VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 16
声望: 1
from datetime import datetime
from importlib import reload
import vnpy.app.portfolio_strategy
reload(vnpy.app.portfolio_strategy)
from vnpy.app.portfolio_strategy import BacktestingEngine
from vnpy.trader.constant import Interval
import amplitude_volatility_strategy as avs
reload(avs)
from amplitude_volatility_strategy import AmplitudeVolatilityStrategy
import pandas as pd
def set_ratio(num):
    d = {}
    for i in vt_symbols:
        d[i] = num
    return d
path = 'instruments1.csv'
instruments_df = pd.read_csv(path)
vt_symbols = instruments_df['instrument_full'].to_list()

def show_result(strategy):
    engine = BacktestingEngine()
    rates = set_ratio(0)
    engine.set_parameters(
        vt_symbols=vt_symbols,
        interval=Interval.DAILY,
        start=datetime(2019, 1, 1),
        end=datetime(2021, 7, 8),
        rates=set_ratio(1/1000),
        slippages=set_ratio(0),
        sizes=set_ratio(1),
        priceticks=set_ratio(0.01),
        capital=30_000,
    )

    engine.add_strategy(strategy, {})
    engine.load_data()
    engine.run_backtesting()
    df = engine.calculate_result()
    engine.calculate_statistics()
    engine.show_chart()
show_result(AmplitudeVolatilityStrategy)

AttributeError Traceback (most recent call last)

<ipython-input-13-420dd1322ecb> in <module>
5 # "rebalance_days": 1
6 #}
----> 7 show_result(AmplitudeVolatilityStrategy)

<ipython-input-5-ecbf17cc2e5d> in show_result(strategy)
24 )
25
---> 26 engine.add_strategy(strategy, {})
27 engine.load_data()
28 engine.run_backtesting()
c:\vnstudio\lib\site-packages\vnpy\app\portfolio_strategy\backtesting.py in add_strategy(self, strategy_class, setting)
115 """"""
116 self.strategy = strategy_class(
--> 117 self, strategy_class.name, copy(self.vt_symbols), setting
118 )
119
C:\zwrk\vnpy\dev\amplitude_volatility_strategy.py in init(self, strategy_engine, strategy_name, vt_symbols, setting)
64 pass
65 self.bgs[vt_symbol] = BarGenerator(on_bar)
---> 66 self.ams[vt_symbol] = ArrayManager()
67
68 def on_init(self):
c:\vnstudio\lib\enum.py in getattr(cls, name)
346 return cls._membermap[name]
347 except KeyError:
--> 348 raise AttributeError(name) from None
349
350 def getitem(cls, name):
AttributeError: Day

怎么回事呀?

Administrator
avatar
加入于:
帖子: 4513
声望: 322

这里的报错提示有问题,请在cmd中直接运行后,查看完整的报错输出

意思是某个对象找不到Day这个字段

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

沪公网安备 31011502017034号

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