我正在尝试使用回溯测试功能进行金融交易。
问题是当我将自己的数据“price_data”输入到他们的函数时,抱怨操作数类型。
提前感谢您的支持!
!pip install bt
import bt
print(EURUSD_df[['close']])
close
2018-01-01 1.20580
2018-01-02 1.20144
2018-01-03 1.20683
2018-01-04 1.20297
2018-01-07 1.19687
... ...
2018-12-27 1.14448
2018-12-30 1.14649
2019-01-01 1.13447
2019-01-02 1.13942
2019-01-03 1.13951
[262 rows x 1 columns]
price_data=EURUSD_df[['close']]
bt_strategy = bt.Strategy('EMA_crossover',
[bt.algos.WeighTarget(signal),
bt.algos.Rebalance()])
bt_backtest = bt.Backtest(bt_strategy,price_data)
bt_result = bt.run(bt_backtest)
bt_result.plot(title='Backtest result')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-34-11f7c3d37d7c> in <module>()
----> 1 bt_backtest = bt.Backtest(bt_strategy,price_data)
2 bt_result = bt.run(bt_backtest)
3 bt_result.plot(title='Backtest result')
1 frames
/usr/local/lib/python3.7/dist-packages/bt/backtest.py in _process_data(self, data, additional_data)
173 np.nan,
174 columns=data.columns,
--> 175 index=[data.index[0] - pd.DateOffset(days=1)],
176 ),
177 data,
TypeError: unsupported operand type(s) for -: 'str' and 'DateOffset'