2016-11-20 96 views
0

我无法弄清楚为什么我只能在控制台中获取分钟数据而不是日常数据,不管我在代码中声明的内容是否写入frequency = '1d'frequency = '1m',结果总是在几分钟内仅显示分钟价格的Quantopian数据历史记录

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) 

回答

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]