Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Zipline TypeError: Cannot compare type 'Timestamp' with type 'tuple'

Hi,
I successfully imported my custom CSV data as panel, see the following print.data(head) result:


Dimensions: 2 (items) x 945 (major_axis) x 5 (minor_axis)
Items axis: StockA to StockB
Major_axis axis: 2012-11-30 00:00:00+00:00 to 2016-09-13 00:00:00+00:00
Minor_axis axis: Open to Volume

                                Open    Close      High      Low  Volume  

1 Symbol
2012-11-30 00:00:00+00:00 StockA 557.5 570.0 570.00 557.5 234266
StockB 912.0 923.5 927.00 912.0 12653

But running any simple algo on it (e.g. Dual Moving Average Crossover example) throws the following exception:

C:\Program Files\Miniconda2\lib\site-packages\zipline\finance\trading.pyc in update_internal_from_env(self, env)
447 "Period start falls after period end."
448
--> 449 assert self.period_start <= env.last_trading_day, \
450 "Period start falls after the last known trading day."
451 assert self.period_end >= env.first_trading_day, \
pandas\tslib.pyx in pandas.tslib._Timestamp.__richcmp__ (pandas\tslib.c:17992)()
TypeError: Cannot compare type 'Timestamp' with type 'tuple'

Can you please help me, how to overcome this compare problem?
Thank you
Peter

4 responses

Hi Peter,

Without seeing the code, it's difficult to tell what the problem is. Would you be willing to share a backtest? If you don't feel comfortable sharing your code publicly, you can also email in to [email protected] for help.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi Jamie,
my code is very simple, example.csv file content like this:

SYMBOLA,20121130,93.00,90.00,94.25,86.30,117853  
SYMBOLB,20121130,10685.00,10700.00,10700.00,10610.00,8978  

I am importing it using the follwoing code to get panel:

import pandas as pd  
tabulka=pd.read_csv('example.csv', header=None, parse_dates=True, index_col=1)  
tabulka.index = tabulka.index.normalize()  
if tabulka.index.tzinfo is None:  
    tabulka.index = tabulka.index.tz_localize('UTC')  
pd.to_datetime(tabulka.index)  
tabulka.columns = ["Symbol", "Open", "Close","High", "Low", "Volume"]  
tabulka.index = [tabulka.index, tabulka.Symbol]  
tabulka = tabulka[['Open', 'Close','High', 'Low','Volume']]  
tabulka.to_panel().transpose(2, 1, 0)  

The algorithm itself can be anything, for example this simple buy 100 every day:

def initialize(context):  
    context.asset = symbol('SYMBOLA')  
    context.invested = False

def handle_data(context, data):  
    order(context.asset, 100) 

if __name__ == '__main__':  
    from datetime import datetime  
    import pytz  
    from zipline.algorithm import TradingAlgorithm  
    from zipline.utils.factory import load_from_yahoo

    data = tabulka

    algo = TradingAlgorithm(initialize=initialize, handle_data=handle_data)  
    results = algo.run(data).dropna()  

Hi Peter,

I apologize, I thought you were trying to use Fetcher in an algorithm. For Zipline questions, the best place to ask is in the Zipline repository on Github - I'd recommend creating an issue with your question if someone hasn't already brought it up. Our Zipline engineers monitory the repository and should be able to help you with the issue.

Hi,
I posted question both to GitHib and Google group, but unfortunately no answer after 3 weeks:(
https://github.com/quantopian/zipline/issues/1498
https://groups.google.com/forum/#!topic/zipline/XZEZ0B6Tgnk