Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: KeyError 'shift'
    primarykey
    data
    text
    <p>I am new to Python and try to modify a pair trading script that I found here: <a href="https://github.com/quantopian/zipline/blob/master/zipline/examples/pairtrade.py" rel="nofollow">https://github.com/quantopian/zipline/blob/master/zipline/examples/pairtrade.py</a></p> <p>The original script is designed to use only prices. I would like to use returns to fit my models and price for invested quantity but I don't see how do it.</p> <p>I have tried: </p> <ul> <li>to define a data frame of returns in the main and call it in run</li> <li>to define a data frame of returns in the main as a global object and use where needed in the 'handle data'</li> <li>to define a data frame of retuns directly in the handle data</li> </ul> <p>I assume the last option to be the most appropriate but then I have an error with panda 'shift' attribute.</p> <p>More specifically I try to define 'DataRegression' as follow:</p> <pre><code>DataRegression = data.copy() DataRegression[Stock1]=DataRegression[Stock1]/DataRegression[Stock1].shift(1)-1 DataRegression[Stock2]=DataRegression[Stock2]/DataRegression[Stock2].shift(1)-1 DataRegression[Stock3]=DataRegression[Stock3]/DataRegression[Stock3].shift(1)-1 DataRegression = DataRegression.dropna(axis=0) </code></pre> <p>where 'data' is a data frame which contains prices, stock1, stock2 and stock3 column names defined globally. Those lines in the handle data return the error:</p> <pre><code>File "A:\Apps\Python\Python.2.7.3.x86\lib\site-packages\zipline-0.5.6-py2.7.egg\zipline\utils\protocol_utils.py", line 85, in __getattr__ return self.__internal[key] KeyError: 'shift' </code></pre> <p>Would anyone know why and how to do that correctly?</p> <p>Many Thanks, Vincent</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload