Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Problem loading custom csv file in Zipline/Quantopian

I have a custom csv file in the following format:

Date Open High Low Close Volume Adj Close
02/01/2015 09:00:00 103.76 103.76 103.76 103.76 364 103.76
02/01/2015 09:01:00 103.74 103.74 103.74 103.74 400 103.74
02/01/2015 09:05:00 103.74 103.74 103.74 103.74 2000 103.74
... As you can see it has per-minute history price resolution.

When I import it into my Python code from zipline, it outputs the following to me:


Traceback (most recent call last):
File "MarketDynamics_Q_V2.py", line 933, in
panel.minor_axis = ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close']
File "/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py", line 2094, in setattr
return object.__setattr__(self, name, value)
File "pandas/src/properties.pyx", line 65, in pandas.lib.AxisProperty.__set__ (pandas/lib.c:42543)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py", line 413, in set_axis
self._data.set_axis(axis, labels)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/internals.py", line 2219, in set_axis
'new values have %d elements' % (old
len, new_len))
ValueError: Length mismatch: Expected axis has 6 elements, new values have 7 elements


Here is my code snippet to load the csv file:

import numpy as np  
import pytz  
import pandas as pd  
import pylab as pl  
import matplotlib.pyplot as plt  
import os  
import collections  
from StringIO import StringIO  
dictData = collections.OrderedDict()

start = datetime(2013, 7, 1, 0, 0, 0, 0, pytz.utc)  
end = datetime(2015, 7, 1, 0, 0, 0, 0, pytz.utc)

parse = lambda x: pytz.utc.localize(datetime.strptime(x, '%d/%m/%Y %H:%M'))  
data = pd.read_csv('QQQ_20150101_20151120.csv', parse_dates=['Date'], index_col=0, date_parser=parse)  
data.head()

dictData['QQQ']=data  
panel = pd.Panel(dictData)  
panel.minor_axis = ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close']

sim_params = factory.create_simulation_parameters(  
   start=start, end=end, capital_base=1000)  
sim_params.data_frequency = 'daily'  
sim_params.emission_rate = 'daily'  
data = data.dropna()

algo = TradingAlgorithm(initialize=initialize, handle_data=handle_data, sim_params=sim_params, panel=panel)

Loading from Yahoo works fine.

I would appreciate any help!

Thank you very much

1 response

I think zipline questions are best handled by the zipline Google group, https://groups.google.com/forum/#!forum/zipline .