Team Ai
Apppublic

diegobeyl/backtesting

sourceHugging Faceupdated 9mo agoView on Hugging Face
2likes
check_trades.py31 linesDownload Raw Back to analysis
1import sys
2sys.path.insert(0, 'backtesting_app/backtesting_app')
3
4import yfinance as yf
5import pandas as pd
6from algorithms.fast_ariascampos import FastAriasCampos
7from core.backtester import Backtester
8
9df = yf.download('AAPL', start='2016-01-01', end='2025-12-31', interval='1mo', progress=False)
10df = df[['Open', 'High', 'Low', 'Close', 'Volume']]
11df.columns = ['open', 'high', 'low', 'close', 'volume']
12
13algo = FastAriasCampos()
14params = algo.get_default_params()
15params['timeframe'] = '1mo'
16
17backtester = Backtester(
18    algorithm=algo,
19    initial_capital=10000,
20    commission_pct=0.1,
21    position_sizing='risk',
22    risk_percent=3.0
23)
24
25result = backtester.run(df, params, symbol='AAPL', timeframe='1mo')
26
27print(f'Total trades: {len(result.trades)}\n')
28for t in result.trades:
29    exit_str = t.exit_date.strftime("%Y-%m-%d") if t.exit_date else "OPEN"
30    print(f'{t.direction:5s} | {t.entry_date.strftime("%Y-%m-%d")} -> {exit_str:10s} | {t.exit_reason if t.exit_date else ""}')
31