VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 16
声望: 0

使用vnpy回测的时候,我用的是vnpy_ctabacktester 中的BacktesterEngine,但为什么调用的时候仍然会使用vnpy_ctastrategy中的BacktestingEngine?
代码如下:

Member
avatar
加入于:
帖子: 16
声望: 0

`
from vnpy_ctabacktester import BacktesterEngine
from vnpy.event import EventEngine
from vnpy.trader.setting import SETTINGS
from vnpy.trader.engine import MainEngine

from vnpy_ctp import CtpGateway
from vnpy_ctastrategy.base import EVENT_CTA_LOG

event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(CtpGateway)
cta_engine = BacktesterEngine(main_engine, event_engine)
main_engine.write_log("主引擎创建成功")

class_name = "AtrRsiStrategy"
strategy_name = "atr_rb"
vt_symbol = "RB888.SHFE"
start=datetime(2019, 3, 22)
end=datetime(2022, 3, 21)
interval='1m'
rate=0.3/10000
slippage=0.2
size = 10
pricetick=0.2
capital=1_000_000
strategy_setting = {
"atr_length": 22,
"atr_ma_length": 10,
'rsi_length':5,
'rsi_entry':16,
'trailing_percent':0.8,
'fixed_size':1
}

log_engine = main_engine.get_engine("log")
event_engine.register(EVENT_CTA_LOG, log_engine.process_log_event)
main_engine.write_log("注册日志事件监听")
cta_engine.init_engine()
main_engine.write_log("CTA策略初始化完成")
cta_engine.add_strategy(class_name, strategy_name, vt_symbol, strategy_setting)
cta_engine.run_backtesting(class_name, vt_symbol, interval, start, end, rate, slippage, size, pricetick, capital, True, {})

`

Member
avatar
加入于:
帖子: 16
声望: 0

然后发现回测是调用的还是vnpy_ctastrategy中的BacktestingEngine,挺奇怪的

Member
avatar
加入于:
帖子: 716
声望: 55

description
因为vnpy_ctabacktester中的BacktestingEngine就是从vnpy_ctastrategy导入的

Member
avatar
加入于:
帖子: 16
声望: 0

郭易燔 wrote:

description
因为vnpy_ctabacktester中的BacktestingEngine就是从vnpy_ctastrategy导入的
明白了!谢谢您的回复

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

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】