bt
bt copied to clipboard
Error in example "Strategy_Combination.ipynb"
I've tried running the example notebook both with latest release (0.2.9) and with the master branch. The exception is raised while running cell number 4. Traceback is given below. I'm not able to directly debug the code as it is inside the compiled part.
This might be a separate issue or not: when I try to make my own strategy with children strategies, similar errors happen, raised from bt.core.StrategyBase.update()
when called from self.strategy.update(self.dates[0])
. In this case, the message is similar to #63 but raised because prices for self.dates[0] are all NaN (intentionally if I understood correctly).
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-88e19d9bfbfb> in <module>
17 )
18
---> 19 res = bt.run(combined_test)
D:\WPy64-3771\python-3.7.7.amd64\lib\site-packages\bt\backtest.py in run(*backtests)
26 # run each backtest
27 for bkt in backtests:
---> 28 bkt.run()
29
30 return Result(*backtests)
D:\WPy64-3771\python-3.7.7.amd64\lib\site-packages\bt\backtest.py in run(self)
226 # since there is a dummy row at time 0, start backtest at date 1.
227 # we must still update for t0
--> 228 self.strategy.update(self.dates[0])
229
230 # and for the backtest loop, start at date 1
D:\WPy64-3771\python-3.7.7.amd64\lib\site-packages\bt\core.cp37-win_amd64.pyd in bt.core.StrategyBase.update()
D:\WPy64-3771\python-3.7.7.amd64\lib\site-packages\pandas\core\indexing.py in __setitem__(self, key, value)
669 key = com.apply_if_callable(key, self.obj)
670 indexer = self._get_setitem_indexer(key)
--> 671 self._setitem_with_indexer(indexer, value)
672
673 def _validate_key(self, key, axis: int):
D:\WPy64-3771\python-3.7.7.amd64\lib\site-packages\pandas\core\indexing.py in _setitem_with_indexer(self, indexer, value)
843
844 # add a new item with the dtype setup
--> 845 self.obj[key] = _infer_fill_value(value)
846
847 new_indexer = convert_from_missing_indexer_tuple(
D:\WPy64-3771\python-3.7.7.amd64\lib\site-packages\pandas\core\frame.py in __setitem__(self, key, value)
2924
2925 # see if we can slice the rows
-> 2926 indexer = convert_to_index_sliceable(self, key)
2927 if indexer is not None:
2928 # either we have a slice or we have a string that can be converted
D:\WPy64-3771\python-3.7.7.amd64\lib\site-packages\pandas\core\indexing.py in convert_to_index_sliceable(obj, key)
2277 if idx._supports_partial_string_indexing:
2278 try:
-> 2279 return idx._get_string_slice(key)
2280 except (KeyError, ValueError, NotImplementedError):
2281 return None
D:\WPy64-3771\python-3.7.7.amd64\lib\site-packages\pandas\core\indexes\datetimes.py in _get_string_slice(self, key, use_lhs, use_rhs)
776 def _get_string_slice(self, key: str, use_lhs: bool = True, use_rhs: bool = True):
777 freq = getattr(self, "freqstr", getattr(self, "inferred_freq", None))
--> 778 _, parsed, reso = parsing.parse_time_string(key, freq)
779 loc = self._partial_date_slice(reso, parsed, use_lhs=use_lhs, use_rhs=use_rhs)
780 return loc
TypeError: Argument 'arg' has incorrect type (expected str, got numpy.str_)
same error. I think it may be stuck by the version of pandas.