vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 45
声望: 0

根据公众号里面的 Tick数据载入和策略回测 已经实现了tick回测了,

在有UI下,进行bar级别的回测,直接点击参数优化就搞定了,请教tick级别回测无UI下怎么来实现参数优化? 具体点的代码,新手初学,谢谢

from vnpy.app.cta_strategy.backtesting import BacktestingEngine, OptimizationSetting
from vnpy.app.cta_strategy.base import BacktestingMode
from datetime import datetime
from vnpy.app.cta_strategy.strategies.brush_backtest_strategy import BrushBacktestStrategy

engine = BacktestingEngine()
engine.set_parameters(
vt_symbol="rb2001.SHFE",
interval="1m",
start=datetime(2019, 10, 24),
end=datetime(2019, 10, 26),
rate=1/10000,
slippage=0,
size=10,
pricetick=1,
capital=10_000,
mode=BacktestingMode.TICK
)
engine.add_strategy(BrushBacktestStrategy, {})

engine.load_data()
engine.run_backtesting()
df = engine.calculate_result()
engine.calculate_statistics()
engine.show_chart()

trades = engine.trades
for value in trades.values():
print("时间:",value.datetime,value.direction.value,value.offset.value, "价格:",value.price, "数量:",value.volume)
if value.offset.value == "平":
print("---------------------------------------------------------")

Administrator
avatar
加入于:
帖子: 4122
声望: 229

https://github.com/vnpy/vnpy/blob/master/examples/cta_backtesting/backtesting.ipynb

照着这里的代码操作就行,优化方法和K线模式完全一致的,只是改为使用Tick数据

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3