qtpylib
qtpylib copied to clipboard
[BUG] Multiple instrument doesn't work
Describe the bug Hello! Thank you for your library. It is awesome. I started to use it and now I'm trying to code my strategies with pairs trading. But I've got an issue and I cannot solve it. Here is the example. And the output is the following:
start!
/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py:376: FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype. In the future, this will return an ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with the correct 'tz'.
To accept the future behavior, pass 'dtype=object'.
To keep the old behavior, pass 'dtype="datetime64[ns]"'.
self.obj[key] = _infer_fill_value(value)
index -1 is out of bounds for axis 0 with size 0
So, what is wrong and fix it?
Thank you
To Reproduce
from qtpylib.algo import Algo
class PairsTrader(Algo):
def on_start(self):
print('start!')
def on_tick(self, instrument):
print('\Tick: ', self.get_instrument('AAPL').get_tick())
print('\Tick: ', self.get_instrument('AMD').get_tick())
if __name__ == "__main__":
strategy = PairsTrader(
instruments=['AAPL', 'AMD'],
tick_window=1000,
resolution='32K',
preload='100K',
timezone="US/Eastern",
ibport=4003,
backtest=True,
log='strats_results',
output='strats_results/log.pkl',
start='2019-12-01',
end='2019-12-04',
blotter="MainBlotter"
)
strategy.run()
Desktop (please complete the following information):
- OS: Ubuntu
- Version: 16
Additional context I built it from source.
https://github.com/ranaroussi/qtpylib/issues/47 This also doesn't work, always the same: On bar: 13:52:43 +1 AMD {'AAPL': 0, 'AMD': 28}
fyi - idk if multiple instruments is implemented
fyi - idk if multiple instruments is implemented
Is should be because you can find an example in docs with 2 instruments.
index -1 is out of bounds for axis 0 with size 0
Just by the error message I would assume that the issue is caused by slicing of a numpy array of a zero size somewhere in the code as in the example below
>>> import numpy as np
>>> np.array([])[-1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: index -1 is out of bounds for axis 0 with size 0