before_trading在實(shí)盤(pán)中是開(kāi)盤(pán)前運(yùn)行的,所有在這個(gè)函數(shù)下的數(shù)據(jù)應(yīng)該是取到前一天為止的,但在回測(cè)過(guò)程中發(fā)現(xiàn)能取到當(dāng)天數(shù)據(jù),這樣就用到了未來(lái)數(shù)據(jù),回測(cè)和實(shí)盤(pán)的數(shù)據(jù)不一致。
測(cè)試代碼是
def before_trading(context):
??? pass
??? print(history_bars("000001",100,"1d","close")[-1])
??? print(context.now)
?
def handle_bar(context):
??? # 開(kāi)始編寫(xiě)你的主要的算法邏輯。
??? 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
?
?來(lái)源: CXH99.COM
?
請(qǐng)問(wèn)查證的如何了,是否存在開(kāi)盤(pán)取到當(dāng)天數(shù)據(jù)的情況?
?
我觀察是在日線狀態(tài)有這種情況
?