楼主: 挖矿专家
2124 3

[源码分享] 【每日一策】Matlab量化交易策略之 分市场状态的布林通道系统 [推广有奖]

  • 0关注
  • 74粉丝

讲师

22%

还不是VIP/贵宾

-

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

楼主
挖矿专家 发表于 2017-3-21 10:06:36 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
分市场状态的布林通道系统
策略原理:根据均线斜率的变化将市场分为三种情况:上涨,下跌,震荡
          上涨:突破布林带上轨做多
          下跌:跌破布林带下轨做空
          震荡:突破布林带上轨做空,跌破布林带下轨做多
          出场:动态止损出场

回测曲线(由Auto-Trader提供回测曲线)

分市场状态的布林通道系统.png

策略源码:

function Strategy1(default_unit,default_exitway,freq)%targetList = traderGetTargetList(); %获取目标资产信息HandleList = traderGetHandleList();%获取账户句柄global entry;for k=1:length(targetList);        %--------------------仓位、K线、当前bar的提取-----------------------------%    %获取当前仓位    [marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(k).Market,targetList(k).Code);    %策略中每次取数据的长度    dlags=10;    lags=150;    barnum=traderGetCurrentBar(targetList(k).Market,targetList(k).Code);    %数据长度限制    if(barnum<lags)        continue;    end    %获取K线数据    [time,open,high,low,close,volume,turnover,openinterest] = traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq, 0-lags, 0,false,'FWard');%     [Dtime,Dopen,Dhigh,Dlow,Dclose,Dvolume,Dturnover,Dopeninterest] = traderGetKData(targetList(k).Market,targetList(k).Code,'day',1,0-dlags, 0,false,'FWard');    if length(close)<lags        continue;    end    % 虚拟交易所初始手数    totalunit=0;        %-------------------------交易逻辑-------------------------------%    %----------入场信号--------------------%    % pattern recognition    BOLLmid=ma(close,20);    BOLLup1=BOLLmid+stdev(close,20);    BOLLdn1=BOLLmid-stdev(close,20);    BOLLup2=BOLLmid+2*stdev(close,20);    BOLLdn2=BOLLmid-2*stdev(close,20);    ma0=ma(close,10);    ma1=ma(close,20);    ma2=ma(close,30);    slope0=slope(ma0,10);    slope1=slope(ma1,10);    slope2=slope(ma2,10);    if slope0(end)>5 && slope1(end)>5 && slope2(end)>5;        pattern=1;    elseif slope0(end)<-5 && slope1(end)<-5 && slope2(end)<-5;        pattern=2;    else        pattern=3;    end;    s(1).buycon=0;    s(1).sellshortcon=0;    if pattern==1;        if close(end)>BOLLup1(end) && close(end-1)<BOLLup1(end-1)            s(1).buycon=1;        end;    elseif pattern==2;        if close(end)<BOLLdn1(end) && close(end-1)>BOLLdn1(end-1)            s(1).sellshortcon=2;        end;    elseif pattern==3;        if close(end)<BOLLup2(end) && close(end-1)>BOLLup2(end-1)            s(1).sellshortcon=3;        end;        if close(end)>BOLLdn2(end) && close(end-1)<BOLLdn2(end-1)            s(1).buycon=3;        end;    end;    %----------主动出场信号----------------%          %------------被动出场操作------------------%    %找到未平仓的订单    remain=remainorder(entry,k);    %对未平仓的订单进行平仓判断及操作    for i=1:length(remain.entrybar);        % 进仓以来的bar个数        longstopcon=0;        shortstopcon=0;        barsinceentry=barnum-remain.entrybar(i);        backlen=30;    % 回溯的长度(进仓bar之前)        % 回溯的信息提取        [backtime,backopen,backhigh,backlow,backclose,~,~,~] = traderGetKData(targetList(k).Market,targetList(k).Code,'min',freq, 0-barsinceentry-backlen, 0,false,'FWard');        % 根据出场方式计算出场条件        if remain.entryexitway(i)==1;            AFinitial=0;            AFparam=0.02;            AFmax=0.2;            Firstbarmultp=1;  %影响第一根bar的止损价,调高表示可忍受的回撤越多            [longstopcon,shortstopcon,exitline]=exit1(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,AFinitial,AFparam,AFmax,Firstbarmultp);        elseif remain.entryexitway(i)==2;            initialATRparam=3;            AF=0.1;            minATRparam=1;            [longstopcon,shortstopcon,exitline]=exit2(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,initialATRparam,AF,minATRparam);        elseif remain.entryexitway(i)==3;            [longstopcon,shortstopcon,exitline]=exit3(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen);        elseif remain.entryexitway(i)==4            startpoint=10;            percent=0.3;            TRmutlp=1;            [longstopcon,shortstopcon,exitline]=exit4(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,startpoint,percent,TRmutlp);        elseif remain.entryexitway(i)==5;            stdlen=20;            initialstdparam=3;            minstdparam=1;            AF=0.25;            [longstopcon,shortstopcon,exitline]=exit5(backopen,backhigh,backlow,backclose,remain.entrydirection(i),backlen,stdlen,initialstdparam,minstdparam,AF);         elseif remain.entryexitway(i)==6;            longstopcon=close(end)<BOLLmid(end) && close(end-1)>=BOLLmid(end-1);        elseif remain.entryexitway(i)==7;            shortstopcon=close(end)>BOLLmid(end) && close(end-1)<=BOLLmid(end-1);        elseif remain.entryexitway(i)==8;            if remain.entrydirection(i)==1;                longstopcon=close(end)>BOLLup2(end) && close(end-1)<=BOLLup2(end-1);            elseif remain.entrydirection(i)==-1;                shortstopcon=close(end)<BOLLdn2(end) && close(end-1)>=BOLLdn2(end-1);            end;        end;        % 出场执行        if longstopcon            totalunit=totalunit-remain.entryunit(i);            entry.record{k}(remain.num(i))=0;        end;        if shortstopcon            totalunit=totalunit+remain.entryunit(i);            entry.record{k}(remain.num(i))=0;        end;    end;        %------------------- 主动出场操作 --------------------%    %{    s(1).sellcon=close(end)>upline(end);    s(1).buytocovercon=close(end)<dnline(end);    %再次找到未平仓的订单    remain=remainorder(entry,k);    % 找到策略i的marketposition    s=mptaking(s,remain);    %----------------策略1----------------------%    if s(1).sellcon && s(1).marketposition>0        totalunit=totalunit-abs(s(1).marketposition);        % 把已经平掉的订单的开关关掉        for j=1:length(s(1).num)            entry.record{k}(remain.num(s(1).num(j)))=0;        end;    end;    if s(1).buytocovercon && s(1).marketposition<0        totalunit=totalunit+abs(s(1).marketposition);        % 把已经平掉的订单的开关关掉        for j=1:length(s(1).num)            entry.record{k}(remain.num(s(1).num(j)))=0;        end;    end;    %}    %---------------------------加仓--------------------------------%    %----------------策略1----------------------%    %再次找到未平仓的订单    remain=remainorder(entry,k);    % 找到策略i的marketposition    s=mptaking(s,remain);    %---------------------------入场操作--------------------------------%    %----------------策略1----------------------%    if s(1).buycon==1 && s(1).marketposition==0        buyunit=default_unit;        totalunit=totalunit+buyunit;        [~]=entryalter(k,barnum,1,1,buyunit,6,1);        % 合约号,barnum,方向,开关,手数,出场,策略    end;        if s(1).sellshortcon==2 && s(1).marketposition==0        sellshortunit=default_unit;        totalunit=totalunit-sellshortunit;        [~]=entryalter(k,barnum,-1,1,sellshortunit,7,1);        % 合约号,barnum,方向,开关,手数,出场,策略    end;         if s(1).buycon==3 && s(1).marketposition==0        buyunit=default_unit;        totalunit=totalunit+buyunit;        [~]=entryalter(k,barnum,1,1,buyunit,8,1);        % 合约号,barnum,方向,开关,手数,出场,策略    end;        if s(1).sellshortcon==3 && s(1).marketposition==0        sellshortunit=default_unit;        totalunit=totalunit-sellshortunit;        [~]=entryalter(k,barnum,-1,1,sellshortunit,8,1);        % 合约号,barnum,方向,开关,手数,出场,策略    end;     %---------------------- 虚拟交易所最终执行买卖 ------------------------------%    if totalunit>0        orderID1=traderDirectBuy(HandleList(1),targetList(k).Market,targetList(k).Code,abs(totalunit),0,'market','totalbuy');    elseif totalunit<0        orderID2=traderDirectSell(HandleList(1),targetList(k).Market,targetList(k).Code,abs(totalunit),0,'market','totalsell');    end;endend


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


二维码

扫码加我 拉你入群

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

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

关键词:通道

分市场状态的布林通道系统.png (67.39 KB)

分市场状态的布林通道系统.png

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

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

沙发
ydc129 发表于 2017-3-30 00:17:17
thanks

藤椅
挖矿专家 发表于 2017-3-30 10:25:01
感谢关注~

板凳
ghjktdf 发表于 2017-4-1 10:39:35
感谢分享~

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

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