Zipline Date Trouble

20 views Asked by At

I am trying to run the momentum program for Trading Evolved (Chapter 12 – Momentum/Momentum Model.ipynb), contained below.

I am having a terrible time with the dates.

Running the code as it was originally provided gives me the error

AttributeError: 'UTC' object has no attribute 'key'

After a large amount of google searching I was able to get around this error for a different program (First Zipleine Backtest.ipynb) by changing

start_date = datetime(1996, 1, 1, tzinfo=pytz.UTC)

end_date = datetime(2017, 12, 31, tzinfo=pytz.UTC)

to

start_date=pd.to_datetime('1996-01-01')

end_date =pd.to_datetime('2017-12-31')

However, when I make this change to the Momentum Model program changing

start = datetime(1997, 1, 1, 8, 15, 12, 0, pytz.UTC)

end = datetime(2017, 12, 31, 8, 15, 12, 0, pytz.UTC)

which initially produces the error

NameError: name 'datetime' is not defined

So I change the format of the start and end to

start=pd.to_datetime('1996-01-01')

end =pd.to_datetime('2017-12-31')

I get the error

TypeError: Invalid comparison between dtype=datetime64[ns] and Timestamp

After searching the program for references to ‘start’, I came across

date_rule=date_rules.month_start(),

Now, I know that dates in python can take a couple of different forms and after I made the change, the form of start is

type(start)

Out[21]: pandas._libs.tslibs.timestamps.Timestamp

But I don’t know the format of the date in

date_rule=date_rules.month_start(),

So I don’t know how to make the comparison legitimate, if this indeed the source of the error.

I am trying to develop these programs into teaching material at the university at which I am employed but can’t do that if I can’t get passed the sticking point of the date formats. I would really, really, appreciate some help.

Tried to run the momentum program as is provided in the Trading Evolved website (https://www.dropbox.com/s/tj85sufbsi820ya/Trading%20Evolved.zip?dl=0) under Chapter 12 Momentum / Momentum Model.ipynb

Was expecting the program to run but it produced an error when using the dates.

I tried to change the form of the dates but just got a different error.

I tried to paste in the program here, but stack overflow won't accept the indenting and says that the submission has too many characters.

Run the program for momentum from the Tading Evolved book.

Tried changing the format of the dates but no joy.

0

There are 0 answers