2016-11-20 47 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]