构造RSI指标与RSI指标的均匀化处理,在当前价格高于10天前的价格的时候作为过滤条件,并根据均匀化处理的RSI数值在某一个区域同时RSI高于均匀化的RSI的时候考虑进场做多,空头的条件与之相反。在沪深300股指期货与螺纹钢期货里面按照1:6的标准进行投资。测试时间段:2011年1月1日到2017年1月1日。
回测曲线(由 Auto-trader 提供回测报告)
策略源码:
- function RsiT(freq,len1,len2)%
- targetList = traderGetTargetList();
- %获取目标资产信息
- HandleList = traderGetHandleList();
- %获取账户信息
- shareNum=50*[1,6];
- for i = 1:length(targetList)
- [marketposition,~,~]=traderGetAccountPosition(HandleList(1),targetList(i).Market,targetList(i).Code);
- %获取当前仓位
- lags=30;
- %策略中每次取数据的长度
- barnum=traderGetCurrentBar(targetList(i).Market,targetList(i).Code);
- if(barnum<lags)
- continue;
- end
- % 数据长度限制
- [time0,~,~,~,~,volume,~,~] = traderGetKData(targetList(i).Market,targetList(i).Code,'day',1, 0-lags, 0,true,'FWard');
- if volume(end)==0
- continue;
- end
- [time,open,high,low,close,volume0,turnover,openinterest] = traderGetKData(targetList(i).Market,targetList(i).Code,'day',freq, 0-lags, 0,false,'FWard');
- if length(close)<len1+1|| length(close)<len2+1
- continue;
- end
-
- RSIValue=RSI(close,len1);
- mvRsi=tsmovavg(RSIValue,'e',len2,1);
- if close(end)>close(end-10)
- if RSIValue(end)>mvRsi(end)&& mvRsi(end)>40&&mvRsi(end)<60
- if marketposition ==0
- traderBuy(HandleList(1),targetList(i).Market,targetList(i).Code,shareNum(i),0,'market','buy0');%开多单
- elseif marketposition<0
- traderBuyToCover(HandleList(1),targetList(i).Market,targetList(i).Code,shareNum(i),0,'market','buy1');%平空单
- end
- end
-
-
- elseif close(end)<close(end-10)
- if RSIValue(end)<mvRsi(end)&& mvRsi(end)>40&&mvRsi(end)<60
- if marketposition ==0
- traderSellShort(HandleList(1),targetList(i).Market,targetList(i).Code,shareNum(i),0,'market','sell0');%开多单
- elseif marketposition>0
- traderSell(HandleList(1),targetList(i).Market,targetList(i).Code,shareNum(i),0,'market','sell1');%平空单
- end
- end
- end
- end
- end
- function RSIValue=RSI(Price,Length)
- %----------------------------------基本用法------------------------------
- %1)RSI在 50以上表示市场为多头市场,否则为空头市场.RSI 还可以分为 4 个区域,当
- %市场处于极弱(RSI 小于20)或强势状态(RSI在50~80 之间)时,可介入。当市场处于
- %极强(RSI大于 80)或弱势(RSI在 20~50之间)状态时卖出
- %2)当短期RSI上穿长期RSI买入,当短期 RSI下穿长期RSI卖出
- %----------------------------------调用函数------------------------------
- RSIValue=zeros(length(Price),1);
- DiffofPrice=zeros(length(Price),1);
- DiffofPrice(2:end)=Price(2:end)-Price(1:end-1);
- RSIValue(1:Length)=50;
- for i=Length+1:length(Price)
- Temp=DiffofPrice(i-Length+1:i);
- RSIValue(i)=sum(Temp(Temp>0))/sum(abs(Temp))*100;%注:查看文献可知,RSI有几种算法,这是其中一种
- end
- end
更多免费策略源码下载请登录DigQuant社区-策略资源下载~