before_trading在實盤中是開盤前運行的,所有在這個函數下的數據應該是取到前一天為止的,但在回測過程中發現能取到當天數據,這樣就用到了未來數據,回測和實盤的數據不一致。
測試代碼是
def before_trading(context):
??? pass
??? print(history_bars("000001",100,"1d","close")[-1])
??? print(context.now)
?
def handle_bar(context):
??? # 開始編寫你的主要的算法邏輯。
??? print(history_bars("000001",100,"1d","close")[-1])
??? print(context.now)
?
部分輸出
09:45:53 > 10.144375801086426
09:45:53 > 2019-01-17 00:00:00
09:45:53 > 10.144375801086426
09:45:53 > 2019-01-18 00:00:00
09:45:54 > 10.056839942932129
09:45:54 > 2019-01-18 00:00:00
09:45:54 > 10.056839942932129
09:45:54 > 2019-01-21 00:00:00
?
?來源: CXH99.COM
?
請問查證的如何了,是否存在開盤取到當天數據的情況?
?
我觀察是在日線狀態有這種情況
?