多均线趋势策略玩转股票投资

原文链接:http://tecdat.cn/多均线量化策略回测比较/

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.

程序化交易是指通过计算机技术提供量化分析选股,能自由编写策略,实现准确的数据回测,稳定执行自动交易期货和股票。移动平均线是技术分析中最常用的,作为一种简单有效的数学模型而被广泛使用。均线使用的方式的差异在于均线的计算方式与价格使用方式。不同的均线计算方式会产生不同的结果,不同的价格使用也会有不同的效果。此外,使用一条、两条、三条甚至更多条均线的交易策略,也会有很不一样的结果。因此, 我们对传统的均线交叉策略进行了改进,测试了不同的止损策略,尽可能实现了收益的最大化。

多均线趋势策略玩转股票投资_第1张图片

本策略对比了不同的清仓信号、止损信号组合的回测效果。

卖出条件分别测试卖出是close<ma5 ,卖出是close<ma10 ,卖出是close<ma20 ,查看前6条数据head(data)

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 NA

 多均线趋势策略玩转股票投资_第2张图片

 多均线趋势策略玩转股票投资_第3张图片

移动平均均线图

多均线趋势策略玩转股票投资_第4张图片

选择滑动平均指标

多均线趋势策略玩转股票投资_第5张图片

均线图+散点

plan 1 卖出是close<ma5

多均线趋势策略玩转股票投资_第6张图片

查看每笔交易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

股价+现金流量 现金流量画图

多均线趋势策略玩转股票投资_第7张图片

plan1的盈利区间

多均线趋势策略玩转股票投资_第8张图片

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

股价+现金流量

现金流量画图

多均线趋势策略玩转股票投资_第9张图片

选择滑动平均指标画图

多均线趋势策略玩转股票投资_第10张图片

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

现金流量画图

多均线趋势策略玩转股票投资_第11张图片

选择滑动平均指标画图

多均线趋势策略玩转股票投资_第12张图片

对比组合的策略收益,可以看到使用跌幅止损的策略具有最高的策略收益,且最大回撤控制得也比较好;使用概率止损的策略虽然收益较少,但波动率较低,且最大回撤减少了近一半。

你可能感兴趣的:(股票)