Back to Community
Cannot compare tz-naive and tz-aware timestamps error (Zipline)

Hi,

I'm using the zipline package on python, and for some reason when I run the code below, I get the error "Cannot compare tz-naive and tz-aware timestamps". I was wondering whether anybody could help me?

from zipline.api import order, record, symbol  
from zipline import run_algorithm  
from datetime import datetime

def initialize(context):  
    pass


def handle_data(context, data):  
    order(symbol('AAPL'), 10)  
    record(AAPL=data.current(symbol('AAPL'), 'price'))  
res = run_algorithm(start=datetime(2015, 1, 1, 0, 0, 0),  
                     end=datetime(2016,1,1, 0, 0, 0),  
                     initialize=initialize,  
                     capital_base=10000.0,  
                     data_frequency='daily')  

Thanks,

Jack

2 responses

If anybody else has this problem, use tz-aware dates of the form
pd.to_datetime('2015-01-01').tz_localize('US/Eastern') instead of naive dates such as datetime(2015, 1, 1, 0, 0, 0). Then it'll work.

Awesome thanks Jack! Much appreciated.