楼主: ghjktdf
1246 0

[源码分享] 【每日一策】Matlab量化交易策略之 高抛低吸 [推广有奖]

  • 1关注
  • 1粉丝

硕士生

19%

还不是VIP/贵宾

-

威望
0
论坛币
166 个
通用积分
0
学术水平
1 点
热心指数
2 点
信用等级
1 点
经验
1340 点
帖子
225
精华
0
在线时间
39 小时
注册时间
2017-2-16
最后登录
2017-6-26

楼主
ghjktdf 发表于 2017-4-6 14:32:15 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
策略原理:
         对沪深300全市场股票扫描
         入场条件:1. macd绿柱变短的时候
                   2. 5日均线上扬
                   3. 指数上扬

         出场条件:止损线设为入场时的最低点


回测曲线(由Auto-trader提供回测报告)

高抛低吸.png


策略源码:

  1. function GPDX(n) % 日内高抛低吸.
  2. % 其中,len为在多少日内全部完成突破
  3. targetList = traderGetTargetList(); % 在RunBackTest中选择好的标的.
  4. %获取目标资产信息
  5. HandleList = traderGetHandleList(); %
  6. %获取账户信息
  7. %=================================================================
  8. % RunBackTest的参数设置
  9. % n=200;
  10. %=================================================================

  11. global s; % 定义cc为全局变量
  12. if isempty(s) % 判断cc是否为空值
  13.     for i=1:length(targetList)
  14.         s(i).BarNLong=0;
  15.         s(i).time=0;
  16.         s(i).stopprice=0;
  17.         s(i).openmacd=0;
  18.     end
  19. end

  20. for i = 1:length(targetList)
  21.     [marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(i).Market,targetList(i).Code);
  22.     %获取当前仓位

  23.     lags=n; % lags为策略需要往前获取多少天
  24.     %策略中每次取数据的长度
  25.    
  26.     barnum=traderGetCurrentBar(targetList(i).Market,targetList(i).Code); % K线的序号,后面会增加,前面的值对应的日期固定.
  27.     if(barnum<lags)
  28.         continue;
  29.     end
  30.     % 数据长度限制,排除了前lags根k线
  31.       
  32. %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  33.     % 策略开始部分
  34.     [time,open,high,low,close,volume,turnover,openinterest] = traderGetKData(targetList(i).Market,targetList(i).Code,'min',1, 0-lags, 0,false,'FWard');
  35.    
  36.     if length(close)<n
  37.         continue;
  38.     end
  39. %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------        
  40.     % MACD
  41.     [ema12]=traderEMA(12,targetList(i).Market,targetList(i).Code,'min',1, 0-lags, 0,false,'FWard');
  42.     [ema26]=traderEMA(26,targetList(i).Market,targetList(i).Code,'min',1, 0-lags, 0,false,'FWard');
  43.     dif=ema12-ema26;
  44.     dea=zeros(length(dif),1);
  45.     for j=2:length(dif)
  46.         dea(j,1)=8/10*dea(j-1,1)+2/10*dif(j,1);
  47.     end
  48.     macd=(dif-dea)*2;
  49.     a=macd(end)<0 && macd(end-2)>macd(end-1) && macd(end)>macd(end-1); % 买入条件:macd绿柱变短.
  50. %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  51.     % 5日均线上扬
  52.     ma5=mean(close(end-4:end));
  53.     ma5_1=mean(close(end-5:end-1));
  54.     ma5_2=mean(close(end-6:end-2));   
  55.     b=ma5_1>ma5_2 && ma5>ma5_1;
  56. %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  57.     [time0,open0,high0,low0,close0,volume0,turnover0,openinterest0] = traderGetKData('sse','000001','min',1,0-lags,0,false,'FWard'); % 上证指数
  58.    
  59.     if length(close0)<n
  60.         continue;
  61.     end
  62.     sz_ma60=mean(close0(end-59:end));
  63.     c=close0(end)>sz_ma60; % 上证指数要大于60日均线.
  64. %--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  65.     EntryLong1=a && b && c;
  66. % ===============================================================================================================
  67.     ExitLong1=low(end)<s(i).stopprice; % 止损线设为进场bar的最低点.
  68.    
  69.     if marketposition > 0 && macd(end)>s(i).openmacd
  70.         s(i).openmacd=macd(end);
  71.     end
  72.     ExitLong2=macd(end)<s(i).openmacd; % macd下降时出场.   
  73. % ===============================================================================================================   
  74.     shareNum=floor(100000000/close(end)/100)*100;
  75. %      && time(end)>=datenum('1-Jan-2016')
  76.     if marketposition ==0 && EntryLong1;% 做多情况1
  77.         orderID1=traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,shareNum,0,'market','buy1'); % 开多单
  78.         s(i).openmacd=macd(end);
  79.         s(i).stopprice=low(end);
  80.         s(i).time=time(end);
  81.     end
  82.    
  83.     if marketposition > 0 && ExitLong1 && time(end)~=s(i).time; % 平仓情况1
  84.         traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0,0,'market','sell1');
  85.     end
  86.    
  87.     if marketposition > 0 && ExitLong2 && time(end)~=s(i).time; % 平仓情况2
  88.         traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0,0,'market','sell1');
  89.     end

  90. end
复制代码

更多免费策略源码下载请登录DigQuant社区-策略资源下载~




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝


已有 1 人评分经验 论坛币 收起 理由
fantuanxiaot + 12 + 12 精彩帖子

总评分: 经验 + 12  论坛币 + 12   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jr
拉您进交流群
GMT+8, 2026-1-28 07:19