%此代码用于从万得读取各股各时段的多因子信息
%时间:2005年Q4到2011年Q4
%1.读取每个季度市场上正常交易的股票
%2.读取因子信息
%注意,因子矩阵第i列存放的是第i季度末的值,而收益率矩阵第i列存放的是i+1季度的收益率
w=windmatlab;
Quarterend=w.tdays('2005-12-01','2011-12-31','Period=Q');
%%
%1.读取上个季度中小板市场上交易的股票,剔除ST,PT,*ST,以及上市时间不满90天
for i=1:length(Quarterend)-1
Date(i)=strcat('date=',Quarterend(i));
w_stock=w.wset('sectorconstituent','sectorid=a001010400000000',Date(i));
index=strncmp('*ST',w_stock(:,3),3)|strncmp('ST',w_stock(:,3),2)|strncmp('PT',w_stock(:,3),2)|strncmp('S*ST',w_stock(:,3),2);
w_stock1=w_stock(~index,2);
%1.2剔除上市时间不满三个月的股票
IPOdate=w.wsd(w_stock1,'ipo_date','2014-12-01','2014-12-31','Period=Q','PriceAdj=F');
%不知道为什么读ipo时间的入参还要填时间,但是不填会corrupt response
index1=find(datenum(Quarterend(i))*ones(length(IPOdate),1)-datenum(IPOdate)>90);
w_stock2=w_stock1(index1);
%1.3剔除下个季度停牌的股票(下个季度换手率为0)
[FT_test,~,~,~,~,~]=w.wsd(w_stock2,'free_turn','ED-1M',Quarterend(i+1),'Period=Q');
index2=find(FT_test>0);
stocklist(1:length(index2),i)=w_stock2(index2);
Qty(i)=length(index2);
end
xlswrite('stocklist',stocklist);
xlswrite('Qty',Qty);
%%
%2读取因子信息,收益率
[~,stocklist]=xlsread('stocklist.xls');
%%
%收益率
for i=1:length(Quarterend)-1
%股票下个季度收益率
[close,~,~,~,~,~]=w.wsd(stocklist(:,i),'close',Quarterend(i),Quarterend(i+1),'Period=Q','PriceAdj=F');
Rate=close(2,:)./close(1,:)-ones(1,length(close));
Return(1:length(Rate),i)=Rate;
%中小板综下个季度收益率
[close,~,~,~,~,~]=w.wsd('399005.SZ','close',Quarterend(i),Quarterend(i+1),'Period=Q','PriceAdj=F');
RM(i)=close(2)/close(1)-1;
end
xlswrite('0Return', Return);
xlswrite('RM', RM);
%%
for i=1:length(Quarterend)-1
%1账面市值比
[pb,~,~,~,~,~]=w.wsd(stocklist(:,i),'pb_lf','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
B2M(1:length(pb),i)=ones(length(pb),1)./pb;
%2盈利收益率
[pe,~,~,~,~,~]=w.wsd(stocklist(:,i),'pe_ttm','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');%PE
PE(1:length(pe),i)=pe;
%3PEG
[peg,~,~,~,~,~]=w.wsd(stocklist(:,i),'estpeg_FTM','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');%股息率
PEG(1:length(peg),i)=peg;
%4股息收益率
[dividendyield,~,~,~,~,~]=w.wsd(stocklist(:,i),'dividendyield2','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');%股息率
DividendYield(1:length(dividendyield),i)=dividendyield;
%5流动市值
[mkt_cap_float,~,~,~,~,~]=w.wsd(stocklist(:,i),'mkt_cap_float','ED-1M',Quarterend(i),'unit=1','currencyType=','Period=Q','PriceAdj=F');
MCF(1:length(mkt_cap_float),i)=mkt_cap_float;
%6换手率
[free_turn,~,~,~,~,~]=w.wsd(stocklist(:,i),'free_turn','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
Freeturn(1:length(free_turn),i)=free_turn;
end
xlswrite('1B2M',PB);
xlswrite('2PE',PE);
xlswrite('3PEG',PEG);
xlswrite('4DividendYield',DividendYield);
xlswrite('5MCF',MCF);
xlswrite('6Freeturn',Freeturn);
%%
%换手率变动
for i=1:length(Quarterend)-1
[free_turn,~,~,~,~,~]=w.wsd(stocklist(:,i),'free_turn','ED-3M',Quarterend(i),'Period=Q','PriceAdj=F');
Dltfreeturn(1:length(free_turn),i)=(free_turn(2,:)-free_turn(1,:))';
end
xlswrite('7Dltfreeturn',Dltfreeturn);
%%
%技术面因子
for i=1:length(Quarterend)-1
%12个月动量
[priceosc12,~,~,~,~,~]=w.wsd(stocklist(:,i),'PRICEOSC',Quarterend(i),Quarterend(i),'PRICEOSC_L=225','PRICEOSC_S=10','TradingCalendar=SZSE','PriceAdj=F');
PRICEOSC12(1:length(priceosc12),i)=priceosc12;
%6个月动量
[priceosc6,~,~,~,~,~]=w.wsd(stocklist(:,i),'PRICEOSC',Quarterend(i),Quarterend(i),'PRICEOSC_L=120','PRICEOSC_S=10','TradingCalendar=SZSE','PriceAdj=F');
PRICEOSC6(1:length(priceosc6),i)=priceosc6;
%1个月反转
[rsi1,~,~,~,~,~]=w.wsd(stocklist(:,i),'RSI',Quarterend(i),Quarterend(i),'RSI_N=22','TradingCalendar=SZSE','PriceAdj=F');
RSI1(1:length(rsi1),i)=rsi1;
end
xlswrite('8PRICEOSC6',PRICEOSC6);
xlswrite('9PRICEOSC12',PRICEOSC12);
xlswrite('10RSI1',RSI1);
%%
%波动
for i=1:length(Quarterend)-1
[std,~,~,~,~,~]=w.wsd(stocklist(:,i),'STD','ED-1D',Quarterend(i),'STD_N=26','Period=M','TradingCalendar=SZSE','PriceAdj=F');
STD(1:length(std),i)=std;
end
xlswrite('11STD',STD);
%%
%震荡指标
for i=1%:length(Quarterend)-1
[high,~,~,~,~,~]=w.wsd(stocklist(:,i),'high','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
[low,~,~,~,~,~]=w.wsd(stocklist(:,i),'low','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
[open,~,~,~,~,~]=w.wsd(stocklist(:,i),'open','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
[close,~,~,~,~,~]=w.wsd(stocklist(:,i),'close','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
Vibrate(1:length(close),i)=(high-low)./(open+close);
end
xlswrite('12Vibrate',Vibrate);
%%
%财务因子
for i=1:length(Quarterend)-1
%净利润同比增长
[yoyprofit,~,~,~,~,~]=w.wsd(stocklist(:,i),'yoyprofit','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
%销售毛利率
[grossprofitmargin,~,~,~,~,~]=w.wsd(stocklist(:,i),'wgsd_grossprofitmargin','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
%销售净利率
[netprofitmargin,~,~,~,~,~]=w.wsd(stocklist(:,i),'netprofitmargin','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
%主营业务占比
[optoebt,~,~,~,~,~]=w.wsd(stocklist(:,i),'optoebt','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
%资本固定化比率
[ncatoequity,~,~,~,~,~]=w.wsd(stocklist(:,i),'ncatoequity','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
%营业收入同比增长
[yoy_or,~,~,~,~,~]=w.wsd(stocklist(:,i),'yoy_or','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
%现金净流量同比增长率
[yoycf,~,~,~,~,~]=w.wsd(stocklist(:,i),'yoycf','ED-1M',Quarterend(i),'Period=Q','PriceAdj=F');
[roe,~,~,~,~,~]=w.wsd(stocklist(:,i),'roe','ED-1M',Quarterend(i),'Period=Q','Fill=Previous','PriceAdj=F');
[roa,~,~,~,~,~]=w.wsd(stocklist(:,i),'roa','ED-1M',Quarterend(i),'Period=Q','Fill=Previous','PriceAdj=F');
[d2a,~,~,~,~,~]=w.wsd(stocklist(:,i),'debttoassets','ED-1M',Quarterend(i),'Period=Q','TradingCalendar=SZSE','Fill=Previous','PriceAdj=F');
if isa(yoyprofit,'double')
YOYPROFIT(1:length(yoyprofit),i)=yoyprofit;
end
if isa(netprofitmargin,'double')%毛利增长率
NPM(1:length(netprofitmargin),i)=netprofitmargin;
end
if isa(grossprofitmargin,'double')
GPM(1:length(grossprofitmargin),i)=grossprofitmargin;
end
if isa(optoebt,'double')
OPTEBT(1:length(optoebt),i)=optoebt;
end
if isa(ncatoequity,'double')
NCA(1:length(ncatoequity),i)=ncatoequity;
end
if isa(yoy_or,'double')
YOYOR(1:length(yoy_or),i)=yoy_or;
end
if isa(yoycf,'double')
YOYCF(1:length(yoycf),i)=yoycf;
end
if isa(roe,'double')
ROE(1:length(roe),i)=roe;
end
if isa(roa,'double')
ROA(1:length(roa),i)=roa;
end
if isa(d2a,'double')
D2A(1:length(d2a),i)=d2a;
end
end
xlswrite('13GPM',GPM);
xlswrite('14NPM',NPM);
xlswrite('15OPTEBT',OPTEBT);
xlswrite('16NCA',NCA);
xlswrite('17ROA',ROA);
xlswrite('18ROE',ROE);
xlswrite('19D2A',D2A);
xlswrite('20YOYCF',YOYCF);
xlswrite('21YOYOR',YOYOR);
xlswrite('22YOYPROFIT',YOYPROFIT);
阿里matlab建模师
- 粉丝: 4254
- 资源: 2843
最新资源
- 毕业设计Jupyter Notebook基于深度网络的垃圾识别与分类算法研究项目源代码,用PyTorch框架中的transforms方法对数据进行预处理操作,后经过多次调参实验,对比不同模型分类效果
- 1221额的2的2的2额
- 基于python第三方库pybloom-live实现的redis布隆过滤器类
- 快速排序算法在Rust语言的实现及其优化
- 微藻检测10-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- 人工智能领域计算断层成像技术研究最新进展综述
- 基于java的公司固定资产管理系统.doc
- 柑橘多种疾病类型图像分类数据集【已标注,约1,000张数据】
- 2025年 UiPath AI和自动化趋势:代理型AI的崛起及企业影响
- 基于Java的环境保护与宣传网站的设计与实现毕业论文.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页