Python: issue with zipline trading calendar/history

杀马特。学长 韩版系。学妹 提交于 2019-12-08 03:45:40

问题


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


回答1:


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...



来源:https://stackoverflow.com/questions/32912392/python-issue-with-zipline-trading-calendar-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!