全部版块 我的主页
论坛 金融投资论坛 六区 金融学(理论版) 量化投资
2100 4
2017-03-14
策略思路:

利用收盘价,构造变形的5阶矩
多头入场条件为:当前高阶矩值大于由高阶矩构造的布林带上轨;
空头入场条件为:当前高阶矩的值低于高阶矩布林带下轨。反手出场。

回测曲线(由Auto-Trader软件提供回测报告):

QQ图片20170314173224.png

策略代码:
function gflossadd(Freq,k,n)global record;targetList = traderGetTargetList();HandleList = traderGetHandleList();for i=1:length(targetList)    marketposition=traderGetAccountPosition(HandleList(1),targetList(i).Market,targetList(i).Code);    lags=200;%270    barnum=traderGetCurrentBar(targetList(i).Market,targetList(i).Code);    if(barnum<=lags)        continue;    end    dlags=40;    [time,open,high,low,close,volume,turnover,openinterest] = traderGetKData(targetList(i).Market,targetList(i).Code,'min',Freq, 0-lags, 0,false,'FWard');    [Dtime,Dopen,Dhigh,Dlow,Dclose,Dvolume,~,~] = traderGetKData(targetList(i).Market,targetList(i).Code,'day',1, 0-dlags, 0,false,'FWard');    if length(close)<lags|| length(Dclose)<dlags        continue;    end;    hmv=hma(close,k,n);    len=100;    gmean=mean(hmv(end-len:end));    gstd=std(hmv(end-len:end));    con1=hmv(end)<=gmean-3*gstd;    con2=hmv(end)>=gmean+3*gstd;    %%    %止损线    ATR=ATR(Dhigh,Dlow,Dclose,20);    %%    %满仓上移    %-------------------------------满仓上移--------------%    if record{i}.m>=3        if close(end)>record{i}.entryp+2*ATR(end)&&(marketposition>0)            record{i}.entryp= record{i}.entryp+2*ATR(end);        elseif close(end)<record{i}.entryp-2*ATR(end)&&(marketposition<0)            record{i}.entryp= record{i}.entryp-2*ATR(end);        end    end        %%    %-------------------------平仓止损--------------------%    %做多平仓    if marketposition>0&&record{i}.m~=0        if close(end)<record{i}.entryp-0.5*ATR(end)            order= traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0,0,'market','sell');            if order~=0                record{i}.m=0;                record{i}.entryp=close(end);            end        end    end        if marketposition<0&&record{i}.m~=0        if close(end)>record{i}.entryp+0.5*ATR(end)            order= traderPositionTo(HandleList(1),targetList(i).Market,targetList(i).Code,0,0,'market','sell');            if order~=0                record{i}.m=0;                   record{i}.entryp=close(end);            end        end    end    %%    %入场    sharenum=5;    %---------------入场-------------%    if con1&&(record{i}.m==0)&&(marketposition==0)        order=traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum,0,'market','buy'); %%%%做多        if order~=0            record{i}.m= record{i}.m+1;            record{i}.entryp=close(end);        end    end        if con2&&(record{i}.m==0)&&(marketposition==0)        order=traderSellShort(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum,0,'market','buy'); %%%%做多        if order~=0            record{i}.m= record{i}.m+1;            record{i}.entryp=close(end);        end    end    %%    %-----------------加仓----------------%    if  close(end)>record{i}.entryp+2*ATR(end)&&(record{i}.m<3)&&(marketposition>0)        order=traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum,0,'market','buy'); %%%%做多        if order~=0            record{i}.m= record{i}.m+1;            record{i}.entryp=close(end);        end    end        if  close(end)<record{i}.entryp-2*ATR(end)&&(record{i}.m<3)&&(marketposition<0)        order=traderSellShort(HandleList(1),targetList(i).Market,targetList(i).Code,sharenum,0,'market','buy'); %%%%做多        if order~=0            record{i}.m= record{i}.m+1;            record{i}.entryp=close(end);        end    end        endendfunction ATRValue=ATR(High,Low,Close,Length)ATRValue=zeros(length(High),1);TRValue=zeros(length(High),1);TRValue(2:end)=max([High(2:end)-Low(2:end) abs(High(2:end)-Close(1:end-1)) abs(Low(2:end)-Close(1:end-1))],[],2);ATRValue=MA(TRValue,Length);endfunction MAValue=MA(Price,Length)MAValue=zeros(length(Price),1);for i=Length:length(Price)    MAValue(i)=sum(Price(i-Length+1:i))/Length;endMAValue(1:Length-1)=Price(1:Length-1);endfunction hmv=hma(price,k,n)hmv=zeros(length(price),1);hmv(1:n)=price(1:n);for i=n+1:length(price)    hmv(i)=0.5*(mean(diff(price(i-n+1:i)).^k));endend


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

二维码

扫码加我 拉你入群

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

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

全部回复
2017-3-15 11:44:03
现在登录社区还有礼品送哦~
二维码

扫码加我 拉你入群

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

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

2017-3-15 14:27:51
楼主的每个贴我都会看~~
二维码

扫码加我 拉你入群

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

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

2017-3-15 17:05:03
楼主好人~
二维码

扫码加我 拉你入群

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

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

2017-3-16 13:24:26
感谢支持,每天都会有策略分享,欢迎关注~
二维码

扫码加我 拉你入群

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

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

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群