商品期货流动性、收益以及波动性分析
2018-10-22 本文已影响0人
遇东风
(一)商品期货流动性
下图是2018年上半年所有商品期货品种主力合约的成交量与成交额统计情况:
从图可以看出,流动性差异明显。成交量位居前三的是螺纹钢、铁矿石、豆粕;不管是成交量和成交金额,螺纹钢近几年一直是最活跃的商品期货品种。成交金额方面,位居前三的是螺纹钢、铁矿石和焦煤。相反,普麦、晚稻、粳稻、早籼稻、强麦、燃料油、胶板、纤板、菜籽等品种几乎没有成交量。
流动性%(一)18年上半年商品期货流动性
clear;clc;
%get data
targetList_shfe0=traderGetCodeList('shfe000');
targetList_dce0=traderGetCodeList('dce000');
targetList_czce0=traderGetCodeList('czce000');
targetList=[targetList_shfe0,targetList_dce0,targetList_czce0];
%
Len=length(targetList);
for i=1:Len
% if i==13||i==39
% CFData(i).volume=0;
% CFData(i).turnover=0;
% else
% [CFData(i).time,CFData(i).open,CFData(i).high,CFData(i).low,CFData(i).close,CFData(i).volume,CFData(i).turnover,CFData(i).openinterest]=...
% traderGetKData(targetList(i).Market, targetList(i).Code, 'day', 1, 20180101, 20180630,false, 'FWard');
% end
[CFData(i).time,CFData(i).open,CFData(i).high,CFData(i).low,CFData(i).close,CFData(i).volume,CFData(i).turnover,CFData(i).openinterest]=...
traderGetKData(targetList(i).Market, targetList(i).Code, 'day', 1, 20180101, 20180630,false, 'FWard');
CF_volume(i)=sum(CFData(i).volume);
CF_turnover(i)=sum(CFData(i).turnover);
CF_name{i}=targetList(i).Name(1:end-3);
end
[sort_volume,p]=sort(CF_volume,2,'descend');
sort_turnover=CF_turnover(p);
for i=1:length(p)
sort_name{i}=CF_name{p(i)};
end
%---------------------------------------
days=1:47;
[hAxes,hBar,hLine]=plotyy(days,sort_volume,days,sort_turnover,'bar','plot');
set(hLine,'color','r','LineWidth',2,'MarkerSize',15,'MarkerFace','y')
title('2018年上半年商品期货成交量与成交金额')
ylabel(hAxes(1),'成交量(手)')
ylabel(hAxes(2),'成交金额(元)')
%
set(gca,'XTick',1:47) % 48
set(gca,'XTickLabel',sort_name)
xtickangle(-45)
%-------------------------------------------
%set(gca,'Fontname','Monospaced')
%h = gca;
%th=rotateticklabel(h, 45);
(二)商品期货收益以及波动性分析
接着分析2018年上半年所有商品期货品种主力合约年化波动率和对数收益率的之间的关系,如下图所示,横轴为对数收益率,纵轴为年化波动率:
2018年上半年,苹果、沥青、镍的对数收益率最高;鸡蛋、焦煤、焦炭年化波动率最高。天然橡胶年化波动率很高,但收益率却最低。2018年上半年商品期货的年化波动率分布基本上在5%至25%之间,其均值为10.69%。
收益以及波动性分析代码:
%(二)18年上半年商品期货收益率以及波动性分析
clear;clc;
%get data
targetList_shfe0=traderGetCodeList('shfe000');
targetList_dce0=traderGetCodeList('dce000');
targetList_czce0=traderGetCodeList('czce000');
targetList=[targetList_shfe0,targetList_dce0,targetList_czce0];
%
Len=length(targetList);
for i=1:Len
if i==6||i==19||i==34||i==38||i==41
CFData(i).CF_Return=0;
CF_Vol(i)=0;
CF_R(i)=0;
else
[CFData(i).time,CFData(i).open,CFData(i).high,CFData(i).low,CFData(i).close,CFData(i).volume,CFData(i).turnover,CFData(i).openinterest]=...
traderGetKData(targetList(i).Market, targetList(i).Code, 'day', 1, 20180101, 20180630,false, 'FWard'); % time
CFData(i).CF_Return=log(CFData(i).close(2:end)./CFData(i).close(1:end-1));
CF_Rstd(i)=std(CFData(i).CF_Return);
CF_Vol(i)=CF_Rstd(i)*sqrt(length(CFData(i).time));
CF_R(i)=log(CFData(i).close(end)./CFData(i).close(1));
end
CF_name{i}=targetList(i).Name(1:end-2);
end
% -------------------------------------------------
scatter(CF_R,CF_Vol,'fill','MarkerFaceColor',[1 .1 .0]);
title('2018年上半年商品期货收益波动特征')
ylabel('年化波动率')
xlabel('对数收益率')
text(CF_R,CF_Vol,CF_name);
meanVol=mean(CF_Vol);
(三)有色金属板块17年以来价格走势
铜 20170101-20180930镍 20170101-20180930
铝 20170101-20180930
锌 20170101-20180930
铅 20170101-20180930
锡 20170101-20180930
%----------------------------------------------------------------
i=5; %cu
Time=datetime(datestr(CFData(i).time,'yyyy-mm-dd'));
[hAxes,hBar,hLine]=plotyy(Time,CFData(i).volume,Time,CFData(i).close,'bar','plot');
%set(hLine,'linestyle','-.','marker','o','markersize',0.5,'linewidth',2);
set(hLine,'color','r','linewidth',2.9);
xtickformat('yyyy/MM/dd');
title([CF_name{i},'期货成交量时间序列图'])
ylabel(hAxes(1),'成交量(手)')
ylabel(hAxes(2),'收盘价(元)')
%----------------------------------------------------------------
i=8; %ni
Time=datetime(datestr(CFData(i).time,'yyyy-mm-dd'));
[hAxes,hBar,hLine]=plotyy(Time,CFData(i).volume,Time,CFData(i).close,'bar','plot');
%set(hLine,'linestyle','-.','marker','o','markersize',0.5,'linewidth',2);
set(hLine,'color','r','linewidth',2.9);
xtickformat('yyyy/MM/dd');
title([CF_name{i},'期货成交量时间序列图'])
ylabel(hAxes(1),'成交量(手)')
ylabel(hAxes(2),'收盘价(元)')
%----------------------------------------------------------------
i=2; %al
Time=datetime(datestr(CFData(i).time,'yyyy-mm-dd'));
[hAxes,hBar,hLine]=plotyy(Time,CFData(i).volume,Time,CFData(i).close,'bar','plot');
%set(hLine,'linestyle','-.','marker','o','markersize',0.5,'linewidth',2);
set(hLine,'color','r','linewidth',2.9);
xtickformat('yyyy/MM/dd');
title([CF_name{i},'期货成交量时间序列图'])
ylabel(hAxes(1),'成交量(手)')
ylabel(hAxes(2),'收盘价(元)')
%----------------------------------------------------------------
i=13; %zn
Time=datetime(datestr(CFData(i).time,'yyyy-mm-dd'));
[hAxes,hBar,hLine]=plotyy(Time,CFData(i).volume,Time,CFData(i).close,'bar','plot');
%set(hLine,'linestyle','-.','marker','o','markersize',0.5,'linewidth',2);
set(hLine,'color','r','linewidth',2.9);
xtickformat('yyyy/MM/dd');
title([CF_name{i},'期货成交量时间序列图'])
ylabel(hAxes(1),'成交量(手)')
ylabel(hAxes(2),'收盘价(元)')
%----------------------------------------------------------------
i=9; %pb
Time=datetime(datestr(CFData(i).time,'yyyy-mm-dd'));
[hAxes,hBar,hLine]=plotyy(Time,CFData(i).volume,Time,CFData(i).close,'bar','plot');
%set(hLine,'linestyle','-.','marker','o','markersize',0.5,'linewidth',2);
set(hLine,'color','r','linewidth',2.9);
xtickformat('yyyy/MM/dd');
title([CF_name{i},'期货成交量时间序列图'])
ylabel(hAxes(1),'成交量(手)')
ylabel(hAxes(2),'收盘价(元)')
%----------------------------------------------------------------
i=12; %sn
Time=datetime(datestr(CFData(i).time,'yyyy-mm-dd'));
[hAxes,hBar,hLine]=plotyy(Time,CFData(i).volume,Time,CFData(i).close,'bar','plot');
%set(hLine,'linestyle','-.','marker','o','markersize',0.5,'linewidth',2);
set(hLine,'color','r','linewidth',2.9);
xtickformat('yyyy/MM/dd');
title([CF_name{i},'期货成交量时间序列图'])
ylabel(hAxes(1),'成交量(手)')
ylabel(hAxes(2),'收盘价(元)')