我无法弄清楚为什么我只在控制台中获取分钟数据而不是每日数据,无论我在代码中说明什么,无论是写frequency = '1d'
还是frequency = '1m'
,结果总是在分钟
def initialize(context):
# AAPL, MSFT, and SPY
context.securities = [sid(24), sid(5061), sid(8554)]
def handle_data(context, data):
prices = data.history(context.securities, "price", bar_count = 10, frequency = "1d")
pct_change = (prices.ix[-1] - prices.ix[0]) / prices.ix[0]
log.info(pct_change)
答案 0 :(得分:2)
您对data.history()
的来电会返回一个包含最近10天数据的面板。该小组包括今天。您每分钟都在拨打电话,因此面板中过去9天的价格是固定的,但今天的价格每分钟都在更新。
我认为您会发现入门教程的Lesson 6非常有用。通常会降低今天的价格以避免您现在处于的状况。
prices = data.history(context.securities, "price", bar_count = 11, frequency = "1d")
pct_change = (prices.ix[-2] - prices.ix[0]) / prices.ix[0]