AssertionError: not allocated in all_benchmark_returns. Calendar seems to mismatch with benchmark.

99 views
Skip to first unread message

Laur Läänemets

unread,
Feb 24, 2015, 11:56:26 AM2/24/15
to zip...@googlegroups.com
I was successfully running zipline manually until it just stopped working for some reason. I have run out of ideas on why. Only thing I changed was updating Matplotlib, but can't see how that could affect it. I am getting an AssertionError: Date 2000-01-03 00:00:00+00:00 not allocated in  all_benchmark_returns. Calendar seems to mismatch with benchmark. Please help

Anyway, the code I'm running is the following:

import pytz
from datetime import datetime

from zipline.algorithm import TradingAlgorithm
from zipline.utils.factory import load_bars_from_yahoo
from zipline.api import order, record

# Load data manually from Yahoo! finance
start = datetime(2000, 1, 1, 0, 0, 0, 0, pytz.utc)
end = datetime(2012, 1, 1, 0, 0, 0, 0, pytz.utc)
data = load_bars_from_yahoo(stocks=['AAPL'], start=start,
                            end=end)

# Define algorithm
def initialize(context):
    pass

def handle_data(context, data):
    order(symbol('AAPL'), 10)
    record(AAPL=data[symbol('AAPL')].price)

# Create algorithm object passing in initialize and
# handle_data functions
algo_obj = TradingAlgorithm(initialize=initialize, 
                            handle_data=handle_data)

# Run algorithm
perf_manual = algo_obj.run(data)

And the console outputs an error as follows:

AAPL
Traceback (most recent call last):
  File "C:\Users\...\Zipline_Environment\Z_ManualTest.py", line 28, in <module>
    perf_manual = algo_obj.run(data)
  File "C:\Python27\lib\site-packages\zipline-0.8.0rc1-py2.7.egg\zipline\algorithm.py", line 483, in run
    for perf in self.gen:
  File "C:\Python27\lib\site-packages\zipline-0.8.0rc1-py2.7.egg\zipline\gens\tradesimulation.py", line 123, in transform
    self.algo.perf_tracker.process_event(event)
  File "C:\Python27\lib\site-packages\zipline-0.8.0rc1-py2.7.egg\zipline\finance\performance\tracker.py", line 325, in process_event
    % midnight))
AssertionError: Date 2000-01-03 00:00:00+00:00 not allocated in  all_benchmark_returns. Calendar seems to mismatch with benchmark.


del...@quantopian.com

unread,
Feb 24, 2015, 1:02:33 PM2/24/15
to zip...@googlegroups.com
Hey Laur,

I think you're seeing a known bug with python-dateutils. I recently ran into this myself so I might be able to help you. What version of pandas are you running? My guess is 0.15.x. If that's true, then an incompatible version of python-dateutils was installed as a dependency during the pandas installation. Try this fix:

uninstall python-dateutil
reinstall python-dateutil with version 2.3

Let me know if this works for you.

Thanks,
Delaney
Engineer at Quantopian

Laur Läänemets

unread,
Feb 25, 2015, 9:32:08 AM2/25/15
to zip...@googlegroups.com
Hey Delaney,

Thanks for the advice. It indeed kind of worked. At first I installed python-dateutil 2.4.0. That gave me errors and then went to 2.3 which you suggested.

Now I'm getting this:
[2015-02-25 14:25] WARNING: Loader: No benchmark data found for date range.
start_date=2015-02-25 00:00:00+00:00, end_date=2015-02-25 14:25:16.943000, url=http://ichart.finance.yahoo.com/table.csv?s=%5EGSPC&a=1&b=25&c=2015&d=1&e=25&f=2015&g=d

But the simulation runs nevertheless and I am getting results that I used to. When I print out a csv file of the results, alpha and benchmark are still given despite the previous warning:

algo_volatility algorithm_period_return alpha benchmark_period_return benchmark_volatility beta capital_used ending_cash ending_value excess_return gross_leverage information long_exposure long_mavg longs_count max_drawdown net_leverage
03/01/2000 21:00 0 0 -0.0658 -0.00954909 0 0 0 10000 0 -0.0658 0 0 0 0 0
04/01/2000 21:00 0 0 -0.0649 -0.04752765 0.323230122 0 0 10000 0 -0.0649 0 0 0 0 0
05/01/2000 21:00 0 0 -0.0662 -0.045696784 0.329321497 0 0 10000 0 -0.0662 0 0 0 0 0
06/01/2000 21:00 0 0 -0.0657 -0.044784754 0.29832581 0 0 10000 0 -0.0657 0 0 0 0 0
07/01/2000 21:00 0 0 -0.0652 -0.018907606 0.375301623 0 0 10000 0 -0.0652 0 0 0 0 0
10/01/2000 21:00 0 0 -0.0657 -0.007929216 0.34906984 0 0 10000 0 -0.0657 0 0 0 0 0
11/01/2000 21:00 0 0 -0.0667 -0.020888208 0.326609451 0 0 10000 0 -0.0667 0 0 0 0 0
12/01/2000 21:00 0 0 -0.0672 -0.025182916 0.302508006 0 0 10000 0 -0.0672 0 0 0 0 0
13/01/2000 21:00 0 0 -0.0663 -0.013319721 0.294168539 0 0 10000 0 -0.0663 0 0 0 0 0
14/01/2000 21:00 0 0 -0.0669 -0.002790539 0.283818116 0 0 10000 0 -0.0669 0 0 0 0 0
18/01/2000 21:00 0 0 -0.0675 -0.009603539 0.271155195 0 0 10000 0 -0.0675 0 0 0 0 0
19/01/2000 21:00 0 0 -0.0673 -0.009086269 0.25860137 0 0 10000 0 -0.0673 0 0 0 0 0
20/01/2000 21:00 0 0 -0.0679 -0.016117067 0.249218988 0 0 10000 0 -0.0679 0 0 0 0 0
21/01/2000 21:00 0 0 -0.0679 -0.018982474 0.239560633 0 0 10000 0 -0.0679 0 0 0 0 0
24/01/2000 21:00 0 0 -0.0669 -0.046091543 0.254900541 0 0 10000 0 -0.0669 0 0 0 0 0
25/01/2000 21:00 0 0 -0.067 -0.040306279 0.248882432 0 0 10000 0 -0.067 0 0 0 0 0
26/01/2000 21:00 0 0 -0.0669 -0.044349158 0.241074722 0 0 10000 0 -0.0669 0 0 0 0 0
27/01/2000 21:00 0 0 -0.0668 -0.048112983 0.233934079 0 0 10000 0 -0.0668 0 0 0 0 0

Thanks again. Literally spent the day yesterday trying to figure it out.

Regards,
Laur

Thomas Wiecki

unread,
Feb 25, 2015, 9:42:55 AM2/25/15
to Laur Läänemets, zipline
This might now be due to your cached data being out of date. Can you try:
rm ~/.zipline/cache/* ~/.zipline/data/*

--
You received this message because you are subscribed to the Google Groups "Zipline Python Opensource Backtester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zipline+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages