Python: issue with zipline trading calendar/histor

2019-05-29 10:42发布

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条回答
贼婆χ
2楼-- · 2019-05-29 11:09

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

查看更多
登录 后发表回答