Python:zipline交易日历/历史的问题 [英] Python: issue with zipline trading calendar/history
问题描述
我有一个不稳定/奇怪的结果与Zipline交易日历。在一台机器上使用Python 3.4.2x64和Zipline 0.7.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()
它源自: zipline回测试使用非美国(欧洲)日历中的数据
这可能是一个多余的,但让我有一个历史与我的所有数据日期(在一台机器上)。
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)可能是我的配置中的区别,导致这个错误?
1) Would anyone have an idea of what could be the difference in my configs that leads to this error?
2)任何人都有一个更可靠的解决方案来调整日历,使所有我的日期在
2) Would anyone have a more robust solution to tweak the calendar so that all my dates are in the history at the end?
非常感谢。
推荐答案
多一点时间在这。 trading.environment.trading_days实际上是一个DatetimeIndex,应该是不可变的,所以试图设置freq不是一个好的方法。 DatetimeIndex有更适合做我想要的方法。这就是说,我不能用方法...
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...
这篇关于Python:zipline交易日历/历史的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!