Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

issue with multi-instrument #37

Closed
ghost opened this issue Dec 6, 2016 · 2 comments
Closed

issue with multi-instrument #37

ghost opened this issue Dec 6, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 6, 2016

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

@ghost ghost mentioned this issue Dec 6, 2016
ranaroussi added a commit that referenced this issue Dec 6, 2016
* develop:
  updated docs and version #
  fixed multi symbol parsing (closing issues #37 + #38)
  Removed `` from log2db (closing issue #36)

# Conflicts:
#	docs/build/html.zip
@ranaroussi
Copy link
Owner

Thanks for catching that... I fixed this issue with version 1.5.41. To upgrade, run:

$ pip install qtpylib --upgrade --no-cache-dir

LMK if that fixed the issue.

@ghost
Copy link
Author

ghost commented Dec 6, 2016

It fixed the issue with the example. Now I'm testing the blobber with 500+ simultaneous instruments. Thanks Ran.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant