%function [weight,rate]= getWeightRate(dateStr,indexStr)
%{
Ps(rs-A)+(Ps-Po)*a
Ps(Wf*rf -Wf*Ri)+( Wf*Ri- Wi*Ri)
其中 要确定的就是Wf 也是28个行业的,如果没有就确定为0 ,说明他们对行业的判断是没有增长,如果增长了,说明判断不够准确
Ps*Wf*(Rf -Ri)代表择时能力 Ri 是28个行业的,Rf是
%}
%用日期 取得tday = '20160519'
%行业代码
swCode={ '801010.SI','801020.SI','801030.SI','801040.SI','801050.SI','801080.SI','801110.SI','801120.SI','801130.SI',...
'801140.SI','801150.SI','801160.SI','801170.SI','801180.SI','801200.SI','801210.SI','801230.SI','801710.SI',...
'801720.SI','801730.SI','801740.SI','801750.SI','801760.SI','801770.SI','801780.SI','801790.SI','801880.SI','801890.SI'};
%用来求得行业的收益率
% 给定日期下从wind拉取指数的成分股及权重
dateStr='20151222'; %日期,可随时调整
dateEnd='20160901';
%indexStr=swCode; %沪深300
indexStr='881001.WI';
%'000016.SH';'000300.SH';'000905.SH';'000852.SH';'881001.WI' %上证50,沪深300,中证500,中证1000,wind全A。
dateStr1=strcat('date=',dateStr,';windcode=',indexStr); %wind全A
w=windmatlab;
index_constituent=w.wset('indexconstituent',dateStr1,'showblank=0');%4列分别为日期/代码/名称/权重
%4列分别为日期/代码/名称/权重
index_instrumentCode=index_constituent(:,2); %存储所有股票代码
instStr='';
for i=1:1:length(index_instrumentCode)
if i~=length(index_instrumentCode)
str=sprintf('%s,',index_instrumentCode{i});
else
str=index_instrumentCode{i};
end
instStr=strcat(instStr,str);
end
% 给定日期下从wind拉取indexStr的申万一级行业指数代码
index_SWcode=w.wsd(instStr,'indexcode_sw',dateStr,dateEnd,'industryType=1');
index_rate=w.wsd(instStr,'pct_chg',dateStr,dateEnd,'industryType=1')/100;
index_constituent=[index_constituent,index_SWcode,num2cell(index_rate)];
save('index_constituent.mat','index_constituent');
%以上是28行业收益率和
%%
% 给定日期下从wind拉取指数的成分股及权重 2908只股票,在某日下 20160825 股票
dateStr='20160825'; % 20160825日期,可随时调整
indexStr='881001.WI'; %沪深300
stockName=[];
%'000016.SH';'000300.SH';'000905.SH';'000852.SH';'881001.WI' %上证50,沪深300,中证500,中证1000,wind全A。
dateStr1=strcat('date=',dateStr,';windcode=',indexStr); %wind全A
w=windmatlab;
index_constituent=w.wset('indexconstituent',dateStr1,'showblank=0');%4列分别为日期/代码/名称/权重
index_instrumentCode=index_constituent(:,2); %存储所有股票代码
instStr='';
for i=1:1:length(index_instrumentCode)
if i~=length(index_instrumentCode)
str=sprintf('%s,',index_instrumentCode{i});
stockName{i}=index_instrumentCode{i};
else
str=index_instrumentCode{i};
stockName{i}=index_instrumentCode{i};
end
instStr=strcat(instStr,str);
end
load('C:\Users\lenovo\Desktop\test\picktime\data0829\Rate.mat', 'dayUni')
[w_wsd_data,w_wsd_codes,w_wsd_fields,w_wsd_times]...
=w.wsd(instStr,'pct_chg',num2str(dayUni(1)),num2str(dayUni(end)));%不用收盘价close,用涨跌幅'pct_chg'
stockRate=w_wsd_data/100; %获得申万一级行业的收益率序列
save('stockInfo.mat','stockRate','stockName','dayUni');
%%
% 给定日期下从wind拉取指数的成分股及权重 权重每次拉一个而已
dateStr='20160825'; %日期,可随时调整 用靠近的日期进行求解
indexStr='881001.WI'; %沪深300
%'000016.SH';'000300.SH';'000905.SH';'000852.SH';'881001.WI' %上证50,沪深300,中证500,中证1000,wind全A。
dateStr1=strcat('date=',dateStr,';windcode=',indexStr); %wind全A
w=windmatlab;
index_constituent=w.wset('indexconstituent',dateStr1,'showblank=0');%4列分别为日期/代码/名称/权重
index_instrumentCode=index_constituent(:,2); %存储所有股票代码
instStr='';
for i=1:1:length(index_instrumentCode)
if i~=length(index_instrumentCode)
str=sprintf('%s,',index_instrumentCode{i});
else
str=index_instrumentCode{i};
end
instStr=strcat(instStr,str);
end
% 给定日期下从wind拉取indexStr的申万一级行业指数代码
index_SWcode=w.wsd(instStr,'indexcode_sw',dateStr,dateStr,'industryType=1');
index_rate=w.wsd(instStr,'pct_chg',dateStr,dateStr,'industryType=1')/100;
index_weight=[index_constituent,index_SWcode,num2cell(index_rate)];
save('index_weight.mat','index_weight');
%以上记录了每只股票的权重,行业权重WI 可以由股票权重求得
得到各种收益率
最新推荐文章于 2024-08-14 21:01:00 发布