楼主: 挖矿专家
1372 3

[源码分享] 【每日一策】Matlab量化交易策略之 突破系统 [推广有奖]

  • 0关注
  • 74粉丝

讲师

22%

还不是VIP/贵宾

-

威望
0
论坛币
2016 个
通用积分
5.2622
学术水平
21 点
热心指数
21 点
信用等级
21 点
经验
6055 点
帖子
403
精华
0
在线时间
151 小时
注册时间
2017-2-8
最后登录
2017-6-27

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
策略原理:
         多头入场:当前价格突破100个交易周期的最高价且价格高于20日均线
         空头入场:当前价格跌破100个交易周期的最低价且价格低于20日均线
         出场:动态跟踪止损出场


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

突破系统.png

策略源码:

  1. function Strategy1(default_unit,default_exitway,freq)%

  2. targetList = traderGetTargetList();
  3. %获取目标资产信息
  4. HandleList = traderGetHandleList();
  5. %获取账户句柄
  6. global entry;
  7. for k=1:length(targetList);
  8.    
  9.     %--------------------仓位、K线、当前bar的提取-----------------------------%
  10.     %获取当前仓位
  11.     [marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(k).Market,targetList(k).Code);
  12.     %策略中每次取数据的长度
  13.     dlags=20;
  14.     lags=300;
  15.     barnum=traderGetCurrentBar(targetList(k).Market,targetList(k).Code);
  16.     %数据长度限制
  17.     if(barnum<lags)
  18.         continue;
  19.     end
  20.     %获取K线数据
  21.     [time,open,high,low,close,volume,turnover,openinterest] = traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq, 0-lags, 0,false,'FWard');
  22. %     [time1,open1,high1,low1,close1,volume1,turnover1,openinterest1] = traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq*4, 0-lags1, 0,false,'FWard');
  23.     [Dtime,Dopen,Dhigh,Dlow,Dclose,Dvolume,Dturnover,Dopeninterest] = traderGetKData(targetList(k).Market,targetList(k).Code,'day',1,0-dlags, 0,false,'FWard');
  24.     if length(close)<lags || length(Dclose)<dlags
  25.         continue;
  26.     end
  27.     % 虚拟交易所初始手数
  28.     totalunit=0;
  29.    
  30.     %-------------------------交易逻辑-------------------------------%
  31.     %----------入场信号--------------------%
  32.     buy0=high(end)>max(high(end-100:end-1));
  33.     sellshort0=low(end)<min(low(end-100:end-1));
  34.     dma=ma(Dclose,20);
  35.     con1=Dclose(end)>dma(end);
  36.     s(1).buycon=buy0 && con1;
  37.     s(1).sellshortcon=sellshort0 && ~con1;
  38.     %------------被动出场操作------------------%
  39.     %找到未平仓的订单
  40.     remain=remainorder(entry,k);
  41.     %对未平仓的订单进行平仓判断及操作
  42.     for i=1:length(remain.entrybar);
  43.         % 进仓以来的bar个数
  44.         barsinceentry=barnum-remain.entrybar(i);
  45.         backlen=20;    % 回溯的长度(进仓bar之前)
  46.         longstopcon=0;
  47.         shortstopcon=0;
  48.         % 回溯的信息提取
  49.         [backtime,backopen,backhigh,backlow,backclose,~,~,~] = traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq, 0-barsinceentry-backlen, 0,false,'FWard');
  50.         % 根据出场方式计算出场条件
  51.         if remain.entryexitway(i)==1;
  52.             AFinitial=0;
  53.             AFparam=0.02;
  54.             AFmax=0.2;
  55.             Firstbarmultp=1;  %影响第一根bar的止损价,调高表示可忍受的回撤越多
  56.             [longstopcon,shortstopcon,exitline]=exit1(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,AFinitial,AFparam,AFmax,Firstbarmultp);
  57.         elseif remain.entryexitway(i)==2;
  58.             initialATRparam=2;
  59.             AF=0.02;
  60.             minATRparam=1;
  61.             [longstopcon,shortstopcon,exitline]=exit2(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,initialATRparam,AF,minATRparam);
  62.         elseif remain.entryexitway(i)==3;
  63.             [longstopcon,shortstopcon,exitline]=exit3(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen);
  64.         elseif remain.entryexitway(i)==4
  65.             startpoint=10;
  66.             percent=0.3;
  67.             TRmutlp=1;
  68.             [longstopcon,shortstopcon,exitline]=exit4(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,startpoint,percent,TRmutlp);
  69.         elseif remain.entryexitway(i)==5;
  70.             stdlen=19;
  71.             initialstdparam=2;
  72.             minstdparam=1;
  73.             AF=0.2;
  74.             [longstopcon,shortstopcon,exitline]=exit5(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,stdlen,initialstdparam,minstdparam,AF);
  75.         elseif remain.entryexitway(i)==6;
  76.             longstopcon1=0;
  77.             shortstopcon1=0;
  78.             if remain.entrydirection(i)==1;
  79.                 longstopcon1=low(end)<min(low(end-20:end-1));
  80.             elseif remain.entrydirection(i)==-1
  81.                 shortstopcon1=high(end)>max(high(end-20:end-1));
  82.             end;
  83.             stdlen=19;
  84.             initialstdparam=2;
  85.             minstdparam=1;
  86.             AF=0.1;
  87.             [longstopcon2,shortstopcon2,exitline]=exit5(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,stdlen,initialstdparam,minstdparam,AF);
  88.             longstopcon2=0;
  89.             shortstopcon2=0;
  90.             longstopcon=longstopcon1 || longstopcon2;
  91.             shortstopcon=shortstopcon1 || shortstopcon2;
  92.         end;
  93.         % 出场执行
  94.         if longstopcon
  95.             totalunit=totalunit-remain.entryunit(i);
  96.             orderID1=traderDirectSell(HandleList(1),targetList(k).Market,targetList(k).Code,remain.entryunit(i),0,'market','totalbuy');
  97.             entry.record{k}(remain.num(i))=0;
  98.         end;
  99.         if shortstopcon
  100.             totalunit=totalunit+remain.entryunit(i);
  101.             orderID1=traderDirectBuy(HandleList(1),targetList(k).Market,targetList(k).Code,remain.entryunit(i),0,'market','totalbuy');
  102.             entry.record{k}(remain.num(i))=0;
  103.         end;
  104.     end;
  105.    
  106.     %---------------------------加仓--------------------------------%
  107.     %----------------策略1----------------------%
  108.     %再次找到未平仓的订单
  109.     remain=remainorder(entry,k);
  110.     % 找到策略i的marketposition
  111.     s=mptaking(s,remain);
  112.     % 找到最近的加仓点和加仓价格
  113.     %{
  114.     if s(1).marketposition~=0;
  115.         lastentrybar=max(remain.entrybar(s(1).num));
  116.         lastbarsinceentry=barnum-lastentrybar;
  117.         lastentryprice=open(end-lastbarsinceentry+1);
  118.         vector=remain.entrydirection(s(1).num);
  119.         lastdirection=vector(end);
  120.         TRvalue=TR(close,high,low);
  121.         ATR=2*ma(TRvalue,10);
  122.         s(1).addbuycon=0;
  123.         s(1).addsellshortcon=0;
  124.         if lastdirection>0
  125.             s(1).addbuycon=close(end)-lastentryprice>ATR(end) && high(end)>max(high(end-20:end-1)) && con1;
  126.         elseif lastdirection<0
  127.             s(1).addsellshortcon=lastentryprice-close(end)>ATR(end) && low(end)<min(low(end-20:end-1)) && ~con1;
  128.         end;
  129.         %---------------加仓操作-------------------------%
  130.         if s(1).addbuycon && s(1).marketposition>=2 && s(1).marketposition<4
  131.             addbuyunit=default_unit*0.5;
  132.             orderID1=traderDirectBuy(HandleList(1),targetList(k).Market,targetList(k).Code,addbuyunit,0,'market','totalbuy');
  133.             [~]=entryalter(k,barnum,1,1,addbuyunit,2,1);
  134.             % 合约号,barnum,方向,开关,手数,出场,策略
  135.         end;

  136.         if s(1).addsellshortcon && s(1).marketposition<=-2 && s(1).marketposition>-4
  137.             addsellshortunit=default_unit*0.5;
  138.             orderID1=traderDirectSell(HandleList(1),targetList(k).Market,targetList(k).Code,addsellshortunit,0,'market','totalbuy');
  139.             [~]=entryalter(k,barnum,-1,1,addsellshortunit,2,1);
  140.             % 合约号,barnum,方向,开关,手数,出场,策略
  141.         end;
  142.     end;
  143.     %}
  144.     %---------------------------入场操作--------------------------------%
  145.     %----------------策略1----------------------%
  146.     if s(1).buycon && s(1).marketposition==0
  147.         buyunit=default_unit;
  148.         orderID1=traderDirectBuy(HandleList(1),targetList(k).Market,targetList(k).Code,buyunit,0,'market','totalbuy');
  149.         [~]=entryalter(k,barnum,1,1,buyunit,default_exitway,1);
  150.         % 合约号,barnum,方向,开关,手数,出场,策略
  151.     end;
  152.     if s(1).sellshortcon && s(1).marketposition==0
  153.         sellshortunit=default_unit;
  154.         orderID1=traderDirectSell(HandleList(1),targetList(k).Market,targetList(k).Code,sellshortunit,0,'market','totalbuy');
  155.         [~]=entryalter(k,barnum,-1,1,sellshortunit,default_exitway,1);
  156.         % 合约号,barnum,方向,开关,手数,出场,策略
  157.     end;
  158. end
  159. end
复制代码

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



二维码

扫码加我 拉你入群

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

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


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

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

沙发
ghjktdf 发表于 2017-4-10 11:48:43 |只看作者 |坛友微信交流群
看曲线还行

使用道具

藤椅
65425856 发表于 2017-4-11 18:40:10 |只看作者 |坛友微信交流群
感谢分享

使用道具

板凳
挖矿专家 发表于 2017-4-17 14:11:31 |只看作者 |坛友微信交流群
ghjktdf 发表于 2017-4-10 11:48
看曲线还行
感谢支持

使用道具

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

本版微信群
加好友,备注jr
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 22:29