You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
I'd like to work with multiple instruments however even with the example that is given in the document I run into issues. Can you help me with the issue?
This is the code:
from qtpylib.algo import Algo
class BuyStockSellOil(Algo):
def on_bar(self, instrument):
# get instrument object
ES = self.get_instrument('ESU2016_FUT')
CL = self.get_instrument('CLU2016_FUT')
# rotate holding between ES and CL
# yes - this strategy makes no sense :)
es_pos = ES.get_positions()
cl_pos = CL.get_positions()
if es_pos["position"] == 0 and cl_pos["position"] > 0:
ES.buy(1)
CL.exit(1)
elif es_pos["position"] > 0 and cl_pos["position"] == 0:
ES.exit(1)
CL.buy(1)
if __name__ == "__main__":
strategy = BuyStockSellOil(
instruments = [
("ES", "FUT", "GLOBEX", "USD", 201609),
("CL", "FUT", "NYMEX", "USD", 201609)
],
resolution = "15T"
)
strategy.run()
This is the error I get:
python multi_inst.py
Traceback (most recent call last):
File "multi_inst.py", line 42, in
strategy.run()
File "/Users/reza/anaconda/lib/python3.5/site-packages/qtpylib/algo.py", line 284, in run
self.blotter.register(self.instruments)
File "/Users/reza/anaconda/lib/python3.5/site-packages/qtpylib/blotter.py", line 1016, in register
instruments['expiry'] = instruments['expiry'].astype(str).str.split(".")[0]
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 2357, in setitem
self._set_item(key, value)
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 2423, in _set_item
value = self._sanitize_column(key, value)
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 2578, in _sanitize_column
value = _sanitize_index(value, self.index, copy=False)
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/series.py", line 2770, in _sanitize_index
raise ValueError('Length of values does not match length of ' 'index')
ValueError: Length of values does not match length of index
The text was updated successfully, but these errors were encountered:
I'd like to work with multiple instruments however even with the example that is given in the document I run into issues. Can you help me with the issue?
This is the code:
This is the error I get:
python multi_inst.py
Traceback (most recent call last):
File "multi_inst.py", line 42, in
strategy.run()
File "/Users/reza/anaconda/lib/python3.5/site-packages/qtpylib/algo.py", line 284, in run
self.blotter.register(self.instruments)
File "/Users/reza/anaconda/lib/python3.5/site-packages/qtpylib/blotter.py", line 1016, in register
instruments['expiry'] = instruments['expiry'].astype(str).str.split(".")[0]
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 2357, in setitem
self._set_item(key, value)
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 2423, in _set_item
value = self._sanitize_column(key, value)
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 2578, in _sanitize_column
value = _sanitize_index(value, self.index, copy=False)
File "/Users/reza/anaconda/lib/python3.5/site-packages/pandas/core/series.py", line 2770, in _sanitize_index
raise ValueError('Length of values does not match length of ' 'index')
ValueError: Length of values does not match length of index
The text was updated successfully, but these errors were encountered: