% 给定日期下从wind拉取 某类股票(沪深300)的 代码,简称,权重(300下权重),申万行业代码。
dateStr='20160912'; %日期,可随时调整
indexStr='000300.SH'; %沪深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_constituent=[index_constituent,index_SWcode,num2cell(index_rate)];
save('index_constituent.mat','index_constituent');
拉取某种(中证)股票的权重
最新推荐文章于 2021-05-28 11:16:49 发布