forked from 51bitquant/howtrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backtest_demo.py
33 lines (27 loc) · 886 Bytes
/
backtest_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from howtrader.app.cta_strategy.backtesting import BacktestingEngine, OptimizationSetting
from howtrader.trader.object import Interval
from datetime import datetime
from howtrader.app.cta_strategy.strategies.atr_rsi_strategy import AtrRsiStrategy
engine = BacktestingEngine()
engine.set_parameters(
vt_symbol="BTCUSDT.BINANCE",
interval=Interval.MINUTE,
start=datetime(2019, 10, 1),
end=datetime(2020, 5, 1),
rate=6/ 10000,
slippage=0,
size=1,
pricetick=0.01,
capital=1_000_000,
)
engine.add_strategy(AtrRsiStrategy, {})
engine.load_data()
engine.run_backtesting()
df = engine.calculate_result()
engine.calculate_statistics()
engine.show_chart()
setting = OptimizationSetting()
setting.set_target("sharpe_ratio")
setting.add_parameter("atr_length", 3, 39, 1)
setting.add_parameter("atr_ma_length", 10, 30, 1)
engine.run_ga_optimization(setting)