Repository: quantopian/zipline

Issue #13: Problem running with data outside of provide benchmark date range
Created: 2012-11-08T16:42:40Z
This is using a local copy of zipline instead of the site-packages one.
The data is OHCL and other indicator exported out as CSV from Metatrader 4. The timestamps are then munged to be the index similar to fast-data-mining-with-pytables-and-pandas.pdf and also localized
data = read_csv(data_file)
data['time'] = None
for i in data.index:
    data['time'][i] = datetime.strptime(data['Date'][i] + " " + data['Time'][i] + ":00", '%m-%d-%Y %H:%M:%S')

data.index = data['time']
del data['time']

data.index = tseries.index.DatetimeIndex(data=data.index).tz_localize('US/Eastern')
and when trying out the algo
class TestAlgo(TradingAlgorithm):
    def handle_data(self,data):
        print data

my_algo = TestAlgo()
results = my_algo.run(data)

this results in
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-1-b9b16310508f> in <module>()
     24 
     25 my_algo = TestAlgo()
---> 26 results = my_algo.run(data)
     27 print results.portfolio_value

/Users/michael/Downloads/PandasTutorialFiles/zipline/algorithm.pyc in run(self, source, start, end)
    177         # loop through simulated_trading, each iteration returns a
    178         # perf ndict
--> 179         perfs = list(self.gen)
    180 
    181         # convert perf ndict to pandas dataframe

/Users/michael/Downloads/PandasTutorialFiles/zipline/gens/tradesimulation.pyc in simulate(self, stream_in)
    113         # day.  It will also yield a risk report at the end of the
    114         # simulation.
--> 115         for message in performance_messages:
    116             yield message
    117 

/Users/michael/Downloads/PandasTutorialFiles/zipline/gens/tradesimulation.pyc in transform(self, stream_in)
    202             # Group together events with the same dt field. This depends on the
    203             # events already being sorted.
--> 204             for date, snapshot in groupby(stream_in, attrgetter('dt')):
    205                 # Set the simulation date to be the first event we see.
    206                 # This should only occur once, at the start of the test.

/Users/michael/Downloads/PandasTutorialFiles/zipline/finance/performance.pyc in transform(self, stream_in)
    217                 yield event
    218             else:
--> 219                 event.perf_message = self.process_event(event)
    220                 event.portfolio = self.get_portfolio()
    221                 del event['TRANSACTION']

/Users/michael/Downloads/PandasTutorialFiles/zipline/finance/performance.pyc in process_event(self, event)
    249 
    250         if(event.dt >= self.market_close):
--> 251             message = self.handle_market_close()
    252 
    253         if event.TRANSACTION:

/Users/michael/Downloads/PandasTutorialFiles/zipline/finance/performance.pyc in handle_market_close(self)
    278         #update risk metrics for cumulative performance
    279         self.cumulative_risk_metrics.update(
--> 280             self.todays_performance.returns, datetime.timedelta(days=1))
    281 
    282         # increment the day counter before we move markers forward.

/Users/michael/Downloads/PandasTutorialFiles/zipline/finance/risk.pyc in update(self, returns_in_period, dt)
    417         self.algorithm_volatility.append(
    418             self.calculate_volatility(self.algorithm_returns))
--> 419         self.treasury_period_return = self.choose_treasury()
    420         self.excess_returns.append(
    421             self.algorithm_period_returns[-1] - self.treasury_period_return)

/Users/michael/Downloads/PandasTutorialFiles/zipline/finance/risk.pyc in choose_treasury(self)
    344             term=self.treasury_duration
    345         )
--> 346         raise Exception(message)
    347 
    348 

Exception: no rate for end date = 2012-04-17 00:00:00-04:00 and term = 1month. Check         that date doesn't exceed treasury history range.
At this point the basic test does work using the local copy of zipline which was my sanity check.
[edit: iPython notebook's trackback is clearer]

Duplicate issue #125: Cannot backtest before 1-2-1990
Created: 2013-04-04T23:47:48Z
Edit zipline/examples/buyapple.py to start from an earlier date than the default:
data = load_from_yahoo(stocks=['AAPL'], indexes={}, start=datetime.datetime(1985, 1, 1, tzinfo=pytz.utc))

Then you will get:
Traceback (most recent call last):
  File "./buyapple.py", line 34, in <module>
    results = simple_algo.run(data)
  File "/home/bmccann/src/zipline/zipline/algorithm.py", line 249, in run
    perfs = list(self.gen)
  File "/home/bmccann/src/zipline/zipline/gens/tradesimulation.py", line 134, in simulate
    for message in performance_messages:
  File "/home/bmccann/src/zipline/zipline/gens/tradesimulation.py", line 258, in transform
    for date, snapshot in stream:
  File "/home/bmccann/src/zipline/zipline/finance/performance.py", line 212, in transform
    messages = self.process_event(event)
  File "/home/bmccann/src/zipline/zipline/finance/performance.py", line 265, in process_event
    messages.append(self.handle_market_close())
  File "/home/bmccann/src/zipline/zipline/finance/performance.py", line 314, in handle_market_close
    self.todays_performance.returns)
  File "/home/bmccann/src/zipline/zipline/finance/risk.py", line 585, in update
self.end_date
  File "/home/bmccann/src/zipline/zipline/finance/risk.py", line 254, in choose_treasury
    search_dist = search_day_distance(end_date, prev_day)
  File "/home/bmccann/src/zipline/zipline/finance/risk.py", line 199, in search_day_distance
    assert tdd >= 0
    AssertionError

Closing comment (2013-04-15T09:09:16Z): Closing as a duplicate of #13