%此代码用于从万得读取各股各时段的多因子信息
%时间: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_多因子选股策略 资源类型:matlab项目全套源码 源码说明: 全部项目源码都是经过测试校正后百分百成功运行的,如果您下载后不能运行可联系我进行指导或者更换。 适合人群:新手及有一定经验的开发人员
资源推荐
资源详情
资源评论
收起资源包目录
matlab_多因子选股策略.rar (6个子文件)
多因子选股
Sortout_3.m 1KB
多因子选股策略简介及案例.docx 92KB
Backtest_4.m 5KB
Choosefactor_2.m 4KB
多因子打分选股在中小板市场上的表现.pptx 511KB
Readinfo_1.m 7KB
共 6 条
- 1
阿里matlab建模师
- 粉丝: 3510
- 资源: 2787
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页