PS C:\veighna_studio\Lib\site-packages> C:\veighna_studio\python.exe C:\veighna_studio\Lib\site-packages\vnpy_ctastrategy\strategies\backtest.py
2024-09-07 09:43:11.019017 开始加载历史数据
2024-09-07 09:43:11.019017 加载进度:# [0%]
2024-09-07 09:43:11.103324 加载进度:# [9%]
2024-09-07 09:43:11.104326 加载进度:## [19%]
2024-09-07 09:43:11.104326 加载进度:### [28%]
2024-09-07 09:43:11.105325 加载进度:#### [38%]
2024-09-07 09:43:11.106328 加载进度:##### [47%]
2024-09-07 09:43:11.107326 加载进度:###### [56%]
2024-09-07 09:43:11.108328 加载进度:####### [66%]
2024-09-07 09:43:11.109325 加载进度:######## [75%]
2024-09-07 09:43:11.110325 加载进度:######### [84%]
2024-09-07 09:43:11.112327 加载进度:########## [94%]
2024-09-07 09:43:11.113327 历史数据加载完成,数据量:0
2024-09-07 09:43:11.114327 策略初始化完成
2024-09-07 09:43:11.114327 开始回放历史数据
2024-09-07 09:43:11.115326 历史数据回放结束
2024-09-07 09:43:11.115326 开始计算逐日盯市盈亏
2024-09-07 09:43:11.115326 回测成交记录为空
Traceback (most recent call last):
File "C:\veighna_studio\Lib\site-packages\vnpy_ctastrategy\strategies\backtest.py", line 33, in <module>
df = engine.calculate_result()
File "C:\veighna_studio\lib\site-packages\vnpy_ctastrategy\backtesting.py", line 283, in calculate_result
self.daily_df = DataFrame.from_dict(results).set_index("date")
File "C:\veighna_studio\lib\site-packages\pandas\core\frame.py", line 6109, in set_index
raise KeyError(f"None of {missing} are in the columns")
KeyError: "None of ['date'] are in the columns"
PS C:\veighna_studio\Lib\site-packages>
------------------------------------- 代码如下----------------------------------------参考页面https://www.bookstack.cn/read/vnpy-2.1/spilt.2.spilt.4.64caaaef7c5fb2e1.md的示例
from vnpy_ctastrategy.backtesting import BacktestingEngine
from vnpy_ctastrategy.strategies.ag2410_kdj_multi_timeframe_v1 import (
Ag2410MultiTimeframeKdjV1,
)
from datetime import datetime
engine = BacktestingEngine()
engine.set_parameters(
vt_symbol="ag2410.SHFE",
interval="1m",
start=datetime(2024, 4, 15),
end=datetime(2024, 8, 21),
rate=5.0 / 10000,
slippage=0.0,
size=15,
pricetick=1.0,
capital=50000,
)
engine.add_strategy(Ag2410MultiTimeframeKdjV1, {})
engine.load_data()
engine.run_backtesting()
df = engine.calculate_result()
engine.calculate_statistics()
engine.show_chart()