原文連接:http://tecdat.cn/多均線量化策略回測比較/ide
Programmatic trading refers to the provision of quantitative analysis through the computer technology stock selection, free to write strategies to achieve accurate data back to test the stability of the implementation of automatic trading futures and stocks. Moving averages are the most commonly used in technical analysis and are widely used as a simple and effective mathematical model. The difference between the way in which the average is used is the way the average is calculated and the price is used. Different averages will produce different results, different prices will have different effects. In addition, the use of one, two, three or even more moving average trading strategy, there will be very different results. Therefore, we have improved the traditional moving average cross strategy, tested the different stop-loss strategy, as far as possible to maximize the benefits.測試
程序化交易是指經過計算機技術提供量化分析選股,能自由編寫策略,實現準確的數據回測,穩定執行自動交易期貨和股票。移動平均線是技術分析中最經常使用的,做爲一種簡單有效的數學模型而被普遍使用。均線使用的方式的差別在於均線的計算方式與價格使用方式。不一樣的均線計算方式會產生不一樣的結果,不一樣的價格使用也會有不一樣的效果。此外,使用一條、兩條、三條甚至更多條均線的交易策略,也會有很不同的結果。所以, 咱們對傳統的均線交叉策略進行了改進,測試了不一樣的止損策略,儘量實現了收益的最大化。spa
本策略對比了不一樣的清倉信號、止損信號組合的回測效果。3d
賣出條件分別測試賣出是close<ma5 ,賣出是close<ma10 ,賣出是close<ma20 ,查看前6條數據head(data)blog
Time Open High Low Close MA5 MA10 MA20 MA30 X 1 2014/07/30 5.72 5.77 5.68 5.74 5.652 5.645 5.776 5.657 NA 2 2014/07/31 5.75 5.78 5.72 5.77 5.716 5.648 5.768 5.675 NA 3 2014/08/01 5.76 5.76 5.64 5.67 5.726 5.640 5.754 5.687 NA 4 2014/08/04 5.65 5.73 5.63 5.72 5.726 5.655 5.748 5.702 NA 5 2014/08/05 5.73 5.82 5.72 5.82 5.744 5.680 5.739 5.718 NA 6 2014/08/06 5.82 5.85 5.75 5.82 5.760 5.706 5.739 5.735 NAthree
移動平均均線圖rem
選擇滑動平均指標get
均線圖+散點數學
plan 1 賣出是close<ma5it
查看每筆交易Value op cash amount asset diff 2014-07-30 5.74 B 3.46 17421 100000.0 0.00 2014-07-31 5.77 S 100522.63 0 100522.6 522.63 2014-08-01 5.67 B 4.87 17728 100522.6 0.00 2014-08-05 5.82 S 103181.83 0 103181.8 2659.20 2014-08-08 5.73 B 1.72 18007 103181.8 0.00 2014-08-11 5.84 S 105162.60 0 105162.6 1980.77
盈利的交易Value op cash amount asset diff 2014-07-30 5.74 B 3.46 17421 100000.0 0.00 2014-07-31 5.77 S 100522.63 0 100522.6 522.63 2014-08-01 5.67 B 4.87 17728 100522.6 0.00 2014-08-05 5.82 S 103181.83 0 103181.8 2659.20 2014-08-08 5.73 B 1.72 18007 103181.8 0.00 2014-08-11 5.84 S 105162.60 0 105162.6 1980.77
虧損的交易Value op cash amount asset diff 2014-11-10 7.39 B 5.99 16776 123980.6 0.00 2014-11-17 7.06 S 118444.55 0 118444.6 -5536.08 2014-12-05 7.46 B 1.93 15898 118601.0 0.00 2014-12-11 7.25 S 115262.43 0 115262.4 -3338.58 2014-12-16 7.11 B 2.22 16211 115262.4 0.00 2014-12-24 6.92 S 112182.34 0 112182.3 -3080.09
股價+現金流量 現金流量畫圖
plan1的盈利區間
plan 2賣出是close<ma10跑一次,查看每筆交易Value op cash amount asset diff 2014-07-30 5.74 B 3.46 17421 100000.0 0.00 2014-08-05 5.82 S 101393.68 0 101393.7 1393.68 2014-08-08 5.73 B 1.33 17695 101393.7 0.00 2014-08-11 5.84 S 103340.13 0 103340.1 1946.45 2014-08-26 6.12 B 3.93 16885 103340.1 0.00 2014-08-27 6.25 S 105535.18 0 105535.2 2195.05
盈利的交易Value op cash amount asset diff 2014-07-30 5.74 B 3.46 17421 100000.0 0.00 2014-08-05 5.82 S 101393.68 0 101393.7 1393.68 2014-08-08 5.73 B 1.33 17695 101393.7 0.00 2014-08-11 5.84 S 103340.13 0 103340.1 1946.45 2014-08-26 6.12 B 3.93 16885 103340.1 0.00 2014-08-27 6.25 S 105535.18 0 105535.2 2195.05
虧損的交易Value op cash amount asset diff 2014-11-07 7.45 B 5.36 16207 120747.5 0.00 2014-11-20 7.19 S 116533.69 0 116533.7 -4213.82 2014-12-05 7.46 B 3.14 16468 122854.4 0.00 2015-01-06 6.64 S 109350.66 0 109350.7 -13503.76 2015-04-15 13.58 B 7.95 9514 129208.1 0.00 2015-04-21 13.46 S 128066.39 0 128066.4 -1141.68
股價+現金流量
現金流量畫圖
選擇滑動平均指標畫圖
plan 3賣出是close<ma20跑一次,
交易記錄
查看每筆交易
Value op cash amount asset diff 2014-07-30 5.74 B 3.46 17421 100000.0 0.0 2014-08-19 6.34 S 110452.60 0 110452.6 10452.6 2014-09-10 6.82 S 110452.60 0 110452.6 0.0 2014-09-12 6.95 S 110452.60 0 110452.6 0.0 2014-09-15 6.91 S 110452.60 0 110452.6 0.0 2014-09-16 6.60 S 110452.60 0 110452.6 0.0
盈利的交易
Value op cash amount asset diff 2014-07-30 5.74 B 3.46 17421 100000.0 0.00 2014-08-19 6.34 S 110452.60 0 110452.6 10452.60 2014-11-03 7.49 B 5.06 14746 110452.6 0.00 2014-11-06 7.58 S 111779.74 0 111779.7 1327.14 2014-11-07 7.45 B 7.39 15003 111779.7 0.00 2014-11-21 7.58 S 113730.13 0 113730.1 1950.39
虧損的交易
Value op cash amount asset diff 2014-12-08 7.32 B 5.90 15817 115786.34 0.00 2015-01-08 6.85 S 108352.35 0 108352.35 -7433.99 2015-01-09 6.75 B 1.35 16052 108352.35 0.00 2015-01-16 6.68 S 107228.71 0 107228.71 -1123.64 2015-06-15 26.75 B 10.13 4782 127928.63 0.00 2015-07-21 17.23 S 82403.99 0 82403.99 -45524.64
現金流量畫圖
選擇滑動平均指標畫圖
對比組合的策略收益,能夠看到使用跌幅止損的策略具備最高的策略收益,且最大回撤控制得也比較好;使用機率止損的策略雖然收益較少,但波動率較低,且最大回撤減小了近一半。