1
鑑於A股{價格,改變價格}順序是這樣的:如何用Mathematica建立回測程序?
lstPrice={{4.66,-0.05},{4.69,0.03},{4.78,0.09},{4.78,0.},{4.81,0.03},{4.85,0.04},{4.78,-0.07},{5.1,0.32},{5.29,0.19},{5.19,-0.1},{5.28,0.09},{5.22,-0.06},{5.18,-0.04},{5.07,-0.11},{5.08,0.01},{5.09,0.01},{5.07,-0.02},{5.1,0.03},{5.05,-0.05},{5.05,0.},{5.13,0.08},{5.1,-0.03},{5.09,-0.01},{5.21,0.12},{5.24,0.03},{5.26,0.02},{5.35,0.09},{5.19,-0.16},{5.24,0.05},{5.09,-0.15},{5.18,0.09},{5.19,0.01},{5.18,-0.01},{5.13,-0.05},{5.15,0.02},{5.06,-0.09},{5.09,0.03},{5.08,-0.01},{5.01,-0.07},{4.99,-0.02},{4.99,0.},{4.94,-0.05},{4.98,0.04},{4.92,-0.06},{4.87,-0.05},{4.91,0.04},{4.91,0.},{4.92,0.01},{4.95,0.03},{4.9,-0.05},{4.93,0.03},{4.99,0.06},{5.04,0.05},{4.98,-0.06},{5.17,0.19},{5.07,-0.1},{5.08,0.01},{5.14,0.06},{5.17,0.03},{5.07,-0.1}}
和最大資本水平爲$ 500000,最高位置級別100000, 當改變價格是負數,購買p1百分比的資本水平,當不同的價格posotive,賣p2百分之的職位級別。以便檢查這個簡單的策略是否成功。 如何構建一個Mathematica回溯測試程序來測試這個想法,最好的功能性編程,或者像下面的塊一樣。 Thansk!
initCapital=500000;(*min to 0 *)
initPosition=0;(*max to 100000*)
p1=0.3;
p2=0.2;
BacktestDo[list_?ListQ]:=If[list[[2]]>0,Buy[p1],Sell[p2]](*Buy and Sell not implemented*)
BacktestDo/@listPrice
它不清楚你問什麼,但我建議你看看'FoldList' – agentp
謝謝! 'MapThread'也可以。 – Jerry
我已經認識到@Chris Degnen的答案是更新的backtesting塊。在github上看到更多。 https://github.com/liuhuashan/StocktaSolva。 – Jerry