| 作者:王洪武二八輪動是FOF里非常簡單的一個策略,下面來簡單回測一下策略的有效性。 選擇三個品種: (1)       二取滬深300指數(shù); (2)       八取中證500指數(shù); (3)       無風(fēng)險取現(xiàn)金. 策略邏輯: 初始狀態(tài)為空倉 過去N個交易日,兩個指數(shù)收益哪個高就持有哪個指數(shù)N個交易日,如兩個指數(shù)過去N個交易日收益均為負值,則投資組合持有現(xiàn)金,空倉現(xiàn)金利息為0.0%,暫不考慮手續(xù)費。 第一部分: 回測分析clear; clcload data.mat
 
N=10; % 持倉每N個交易日輪動一次 PortAsset=zeros(DataLength,1);PortAsset(1:N,1)=1;
 
 for i=N:N:DataLength
 Return=[0,IndexData(i,:)./IndexData(i-N+1,:)-1];
 [Val,Idx]=max(Return);
 if i+N<DataLength
 PortAsset(i+1:i+N)=Idx; %i日尾盤調(diào)倉
 else
 PortAsset(i+1:end)=Idx;
 end
 end
 
PortReturn=zeros(DataLength,1);for i=1:DataLength
 
 switch PortAsset(i)
 case 1
 PortReturn(i)=0;
 case 2
 PortReturn(i)=IndexData(i,1)/IndexData(i-1,1)-1;
 otherwise
 PortReturn(i)=IndexData(i,2)/IndexData(i-1,2)-1;
 end
 end
 
PortNav=zeros(DataLength,1);PortNav(1)=1.00;
 for i=2:DataLength
 PortNav(i)=PortNav(i-1)*(1+PortReturn(i));
 end
 
figure;subplot(2,1,1)
 plot(Date,IndexData(:,1)/1000,'k','LineWidth',1.2);
 hold on;
 plot(Date,IndexData(:,2)/1000,'b','LineWidth',1.2);
 plot(Date,PortNav,'r','LineWidth',1.2);
 dateaxis('x',17);
 legend('滬深300','中證500','二八輪動','Location','NorthWest')
 subplot(2,1,2)
 plot(Date,PortAsset,'k','LineWidth',1.2);
 dateaxis('x',17);
 legend('1:現(xiàn)金,2:滬深300,3:中證500','Location','NorthWest')
 
 
prices1=[IndexData PortNav]; %價格數(shù)據(jù)changes1=tick2ret(prices1); %收益率數(shù)據(jù)
 prices_std=ret2tick(changes1); %標準化價格
 names=[IndexName,{'二八輪動'}];
 
time_span=Date(end)-Date(1);time_span_year=time_span/365
 time_span_year =
 12.2740
 
 
 (1)returntotalYield=prices_std(end,:)-1
 totalYield =
 
 2.5175    5.5787  15.4020
 
 
 公式 (1+yieldYear)^time_span_year-1=totalYield yieldYear=(totalYield+1).^(1/time_span_year)-1
 yieldYear =
 
 0.1079    0.1659   0.2560
 
 
 figuresubplot(3,1,1)
 hist(changes1(:,1),20);
 xlim([-0.1 0.1])
 ylim([0 2000])
 title(names{1})
 xlabel('收益率');
 ylabel('天數(shù)');
 subplot(3,1,2)
 hist(changes1(:,2),20);
 xlim([-0.1 0.1])
 ylim([0 2000])
 title(names{2})
 xlabel('收益率');
 ylabel('天數(shù)');
 subplot(3,1,3)
 hist(changes1(:,3),20);
 xlim([-0.1 0.1])
 ylim([0 2000])
 title(names{3})
 xlabel('收益率');
 ylabel('天數(shù)');
 
 (2)riskvolatility=std(changes1); %波動率volatilityYear=volatility*sqrt(250) %按照250個交易日計算
 volatilityYear =
 
 0.2881    0.3289   0.2404
 
 
 C=cummax(prices_std);maxDrawVector = (C-prices_std)./C; %最大回撤向量
 maxDrawRate=max(maxDrawVector)
 maxDrawRate =
 
 0.7230    0.7242   0.4627
 
 
 figure% bar(Date,maxDrawVector)
 area(Date,[maxDrawVector(:,1), maxDrawVector(:,2)-maxDrawVector(:,1),maxDrawVector(:,3)-maxDrawVector(:,2)]);
 legend(fliplr(names),'Location','northwest')
 ylabel('最大回撤率')
 datetick('x','yyyymmdd')
 
 
beta1=regress(changes1(:,3),changes1(:,1)) %相對于滬深300
 beta2=regress(changes1(:,3),changes1(:,2)) %相對于中證500
 beta1 =
 
 0.5874
 
 
 beta2 =
 
 0.5199
 
 
 (3)return to riskyieldYearDividemaxDraw=yieldYear./maxDrawRate
 yieldYearDividemaxDraw =
 
 0.1492    0.2291   0.5532
 
 
 xx=sum(changes1(:,3)>0);yy=sum(changes1(:,3)~=0);
 winRate=xx/yy
 winRate =
 
 0.5963
 
 
 Riskless=0;Sharpe = (yieldYear-Riskless)./volatilityYear
 Sharpe =
 
 0.3745    0.5043   1.0646
 
 
 (4)return to benchmarkReturns=changes1(:,3);Benchmark=changes1(:,1);
 Cash=0;
 alpha1=portalpha(Returns, Benchmark,Cash,'capm')
 
 Returns=changes1(:,3);
 Benchmark=changes1(:,2);
 Cash=0;
 alpha2=portalpha(Returns, Benchmark,Cash,'capm')
 alpha1 =
 
 7.1139e-04
 
 
 alpha2 =
 
 6.1517e-04
 
 
 Jensen1=yieldYear(3)-beta1*yieldYear(1) %相對滬深300
 Jensen2=yieldYear(3)-beta2*yieldYear(2) %相對中證500
 Jensen1 =
 
 0.1926
 
 
 Jensen2 =
 
 0.1697
 
 
 Returns=changes1(:,3);Benchmark=changes1(:,1);
 InfoRatio1 = inforatio(Returns, Benchmark)
 
 Returns=changes1(:,3);
 Benchmark=changes1(:,2);
 InfoRatio2 = inforatio(Returns, Benchmark)
 InfoRatio1 =
 
 0.0354
 
 InfoRatio2 =
 
 0.0140
第三部分: 參數(shù)優(yōu)化
遍歷持倉周期N=5:1:60;
 
h=@Wheeled28;
 
[return11, maxDraw11, sharp11]=arrayfun(h,N);
 
figurebar(N,return11');
 title('持倉周期與回報率的關(guān)系')
 % 標記最佳標的
 [maxReturn, maxN]=max(return11);
 hold on
 bar(N(maxN),maxReturn, 'FaceColor', [1 .25 .25], 'EdgeColor', 'none');
 text(N(maxN),maxReturn ,[ 'Best:',num2str(N(maxN))],'HorizontalAlignment', 'center', 'VerticalAlignment', 'Bottom');
 

 
figurebar(N,maxDraw11');
 title('繪制持倉周期與最大回撤的關(guān)系')
 % 標記最佳標的
 [minDraw, minN]=min(maxDraw11);
 hold on
 bar(N(minN),minDraw, 'FaceColor', [1 .25 .25], 'EdgeColor', 'none');
 text(N(minN),minDraw ,[ 'Best:',num2str(N(minN))],'HorizontalAlignment', 'center', 'VerticalAlignment', 'Bottom');
 figurebar(N,return11'./maxDraw11');
 title('持倉周期與收益回撤比的關(guān)系')
 % 標記最佳標的
 [maxSharp, maxN]=max(return11'./maxDraw11');
 hold on
 bar(N(maxN),maxSharp, 'FaceColor', [1 .25 .25], 'EdgeColor', 'none');
 text(N(maxN),maxSharp ,[ 'Best:',num2str(N(maxN))],'HorizontalAlignment', 'center', 'VerticalAlignment', 'Bottom');
 
 figurebar(N,sharp11');
 title('持倉周期與夏普比率的關(guān)系')
 % 標記最佳標的
 [maxSharp, maxN]=max(sharp11);
 hold on
 bar(N(maxN),maxSharp, 'FaceColor', [1 .25 .25], 'EdgeColor', 'none');
 text(N(maxN),maxSharp ,[ 'Best:',num2str(N(maxN))],'HorizontalAlignment', 'center', 'VerticalAlignment', 'Bottom');
 
 第四部分: 總結(jié)(1)二八輪動策略邏輯是趨勢追蹤,靠輪動控制品種和倉位,和大多數(shù)趨勢策略一樣,長期能跑贏指數(shù);(2)缺點是回撤比較大,可以考慮加入動態(tài)止盈止損來控制回撤;(3)從參數(shù)尋優(yōu)的結(jié)果來看7-12穩(wěn)定性較強,莫陷入?yún)?shù)過度優(yōu)化的陷阱。第五部分: 改進(1)計算時增加手續(xù)費和滑點(2)調(diào)倉周期改為自然周、自然月或者自然季度(3)策略中增加動態(tài)止盈止損
 
 |