quantopian / zipline

Zipline, a Pythonic Algorithmic Trading Library
https://www.zipline.io
Apache License 2.0
17.7k stars 4.73k forks source link

v 0.7.0: Accessing out of bounds #547

Closed tomas789 closed 9 years ago

tomas789 commented 9 years ago

I did just

import zipline
%%zipline --start 2013-1-1 --end 2014-1-1 --symbols AAPL -o perf_dma

def initialize(context):
    pass

def handle_data(context, data):
    pass

And I got this error

AAPL
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-8-be37af4d0e86> in <module>()
----> 1 get_ipython().run_cell_magic('zipline', '--start 2013-1-1 --end 2014-1-1 --symbols AAPL -o perf_dma', '\ndef initialize(context):\n    pass\n\ndef handle_data(context, data):\n    pass')

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2160             magic_arg_s = self.var_expand(line, stack_depth)
   2161             with self.builtin_trap:
-> 2162                 result = fn(magic_arg_s, cell)
   2163             return result
   2164 

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zipline/utils/cli.py in parse_cell_magic(line, cell)
    126     output_var_name = args.pop('output', None)
    127 
--> 128     perf = run_pipeline(print_algo=False, algo_text=cell, **args)
    129 
    130     if output_var_name is not None:

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zipline/utils/cli.py in run_pipeline(print_algo, **kwargs)
    188     algo = zipline.TradingAlgorithm(script=algo_text,
    189                                     namespace=kwargs.get('namespace', {}),
--> 190                                     capital_base=float(kwargs['capital_base']))
    191 
    192     perf = algo.run(source)

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zipline/algorithm.py in __init__(self, *args, **kwargs)
    156         if self.sim_params is None:
    157             self.sim_params = create_simulation_parameters(
--> 158                 capital_base=self.capital_base
    159             )
    160         self.perf_tracker = PerformanceTracker(self.sim_params)

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zipline/utils/factory.py in create_simulation_parameters(year, start, end, capital_base, num_days, load, sids, data_frequency, emission_rate)
     63         sids=sids,
     64         data_frequency=data_frequency,
---> 65         emission_rate=emission_rate,
     66     )
     67 

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zipline/finance/trading.py in __init__(self, period_start, period_end, capital_base, emission_rate, data_frequency, sids)
    363         self.sids = sids
    364 
--> 365         self._update_internal()
    366 
    367     def _update_internal(self):

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zipline/finance/trading.py in _update_internal(self)
    367     def _update_internal(self):
    368         # This is the global environment for trading simulation.
--> 369         environment = TradingEnvironment.instance()
    370 
    371         assert self.period_start <= self.period_end, \

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zipline/finance/trading.py in instance(cls)
     81         global environment
     82         if not environment:
---> 83             environment = TradingEnvironment()
     84 
     85         return environment

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zipline/finance/trading.py in __init__(self, load, bm_symbol, exchange_tz, max_date, env_trading_calendar)
     99 
    100         self.benchmark_returns, treasury_curves_map = \
--> 101             load(self.bm_symbol)
    102 
    103         self.treasury_curves = pd.DataFrame(treasury_curves_map).T

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zipline/data/loader.py in load_market_data(bm_symbol)
    216     # Find the offset of the last date for which we have trading data in our
    217     # list of valid trading days
--> 218     last_tr_date = saved_curves.index[-1]
    219     last_tr_date_offset = days_up_to_now.searchsorted(
    220         last_tr_date.strftime('%Y/%m/%d'))

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pandas/core/index.py in __getitem__(self, key)
    913 
    914         if np.isscalar(key):
--> 915             return getitem(key)
    916 
    917         if isinstance(key, slice):

IndexError: index -1 is out of bounds for axis 0 with size 0
ricpruss commented 9 years ago

This may be a dup of: https://github.com/quantopian/zipline/issues/447 but I could not duplicate I got: TypeError: run_pipeline() got multiple values for keyword argument 'print_algo'

with my latest version of Zipline (0.8.0rc1)

llllllllll commented 9 years ago

I am unable to reproduce this on master. I believe that this was fixed and that it was related to #447