Python: issue with zipline trading calendar/history
Asked Answered
S

1

1

I have an unstable/weird result with Zipline trading calendar. On one machine with Python 3.4.2x64 and Zipline 0.7.42 I can run the following code:

trading.environment = TradingEnvironment(bm_symbol='^FTSE', exchange_tz='Europe/London')
    Holidays = list(set(tradingcalendar_lse.non_trading_days)-set(data.index))
    trading.environment.trading_days = pd.date_range(start=trading.environment.trading_days[0],
                                             end=trading.environment.trading_days[-1],
                                             freq=pd.tseries.offsets.CDay(holidays=Holidays))
    freq = trading.environment.trading_days.freq
    trading.environment.trading_days =  trading.environment.trading_days + data.index
    trading.environment.trading_days.freq = freq
    trading.environment.open_and_closes = pd.DataFrame(index=trading.environment.trading_days +
                                                             data.index,columns=["market_open","market_close"])
    trading.environment.open_and_closes.market_open = (trading.environment.open_and_closes.index +
                                                       pd.to_timedelta(60*7,unit="T")).to_pydatetime()
    trading.environment.open_and_closes.market_close = (trading.environment.open_and_closes.index +
                                                        pd.to_timedelta(60*15+30,unit="T")).to_pydatetime()

It derives from: zipline backtesting using non-US (European) intraday data

It is probably a little redundant but enables me to have an history with all my data dates (on one machine).

I am trying to run the same code on another computer which should have the same configuration and get the error:

AttributeError: can't set attribute

1) Would anyone have an idea of what could be the difference in my configs that leads to this error?

2) Would anyone have a more robust solution to tweak the calendar so that all my dates are in the history at the end?

Many thanks

Sweetie answered 2/10, 2015 at 17:12 Comment(2)
Does the interpreter indicate the offending line# in the stack trace? That might help to pinpoint the cause.Costin
Yes sorry the line that has the attribute issue is: trading.environment.trading_days.freq = freq. I can't force into zipline trading when I debug.Sweetie
S
0

I have spent a little more time on this. trading.environment.trading_days is actually a DatetimeIndex which should be immutable so trying to set freq is not a nice approach. DatetimeIndex have methods that are more appropriate to do what I want. That being said I can't reproduce my initial output with the methods...

Sweetie answered 5/10, 2015 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.