数据采集之指数估值一:市场平均PE序列

#市场平均PE序列
calendar=DataAPI.TradeCalGet(exchangeCD=u”XSHG,XSHE”,beginDate=u”20150101″,endDate=u”20181130″,field=u””,pandas=”1″)
calendar=calendar[calendar.isMonthEnd==1][calendar.isOpen==1][calendar.isQuarterEnd==1]#只取季末日期
factor_list=[]
for tdate in calendar.calendarDate.values:#拿到因子数据,遍历每一天
data=DataAPI.MktStockFactorsOneDayGet(secID=u””,tradeDate=tdate,field=u”ticker,tradeDate,PE,PB”,pandas=”1″)
data=data.set_index(‘ticker’)#将ticker作为索引
after_winsorizepe=winsorize(data[‘PE’].to_dict())#PE值dict化,并去极值
after_winsorizepb=winsorize(data[‘PB’].to_dict())
data[‘winsorized_PE’]=np.nan
data[‘winsorized_PB’]=np.nan
data.loc[after_winsorizepe.keys(),’winsorized_PE’]=after_winsorizepe.values()#新建winsorized PE列,赋值after_winsorize
data.loc[after_winsorizepb.keys(),’winsorized_PB’]=after_winsorizepb.values()
table={‘tradeDate’:([tdate]),’APB’:([np.mean(data.PB)]),’APB+’:([np.mean(data.winsorized_PB)]),’APE(TTM)’:([np.mean(data.PE)]),’APE(TTM+)’:([np.mean(data.winsorized_PE)]),’MPE(TTM)’:([np.median(data.PE)])}
APE=pd.DataFrame(table)
factor_list.append(APE)
tAPE=pd.concat(factor_list)
tAPE.head(48)

APB APB+ APE(TTM) APE(TTM+) MPE(TTM) tradeDate
0 13.106052 6.409447 66.754817 96.428055 58.46130 2015-03-31
0 20.744910 7.972990 35.846940 121.434260 72.75810 2015-06-30
0 7.796779 5.198993 47.931954 65.565286 46.13280 2015-09-30
0 18.209937 7.275640 -69.644854 79.656014 NaN 2015-12-31
0 9.051723 5.844919 66.007246 83.388905 NaN 2016-03-31
0 8.240866 5.692323 984.205063 83.707933 55.75930 2016-06-30
0 7.861199 5.613655 324.053191 76.396966 54.08900 2016-09-30
0 12.538579 5.514214 113.590437 68.717790 51.01250 2016-12-30
0 12.053589 5.684596 122.918144 77.427108 53.29795 2017-03-31
0 11.161743 4.598219 71.142766 64.234335 45.99535 2017-06-30
0 4.941457 4.682282 74.647000 58.870443 44.61255 2017-09-29
0 9.655877 4.117779 775.453931 50.238026 NaN 2017-12-29
0 7.529885 4.032096 754.876666 55.279115 NaN 2018-03-30
0 4.482460 3.196374 40.982001 43.224041 31.43095 2018-06-29
0 3.407019 2.786354 11.527318 34.905530 26.70940 2018-09-28
0 13.106052 6.409447 66.754817 96.428055 58.46130 2015-03-31
0 20.744910 7.972990 35.846940 121.434260 72.75810 2015-06-30
0 7.796779 5.198993 47.931954 65.565286 46.13280 2015-09-30
0 18.209937 7.275640 -69.644854 79.656014 NaN 2015-12-31
0 9.051723 5.844919 66.007246 83.388905 NaN 2016-03-31
0 8.240866 5.692323 984.205063 83.707933 55.75930 2016-06-30
0 7.861199 5.613655 324.053191 76.396966 54.08900 2016-09-30
0 12.538579 5.514214 113.590437 68.717790 51.01250 2016-12-30
0 12.053589 5.684596 122.918144 77.427108 53.29795 2017-03-31
0 11.161743 4.598219 71.142766 64.234335 45.99535 2017-06-30
0 4.941457 4.682282 74.647000 58.870443 44.61255 2017-09-29
0 9.655877 4.117779 775.453931 50.238026 NaN 2017-12-29
0 7.529885 4.032096 754.876666 55.279115 NaN 2018-03-30
0 4.482460 3.196374 40.982001 43.224041 31.43095 2018-06-29
0 3.407019 2.786354 11.527318 34.905530 26.70940 2018-09-28

数据采集自网络

Leave a Reply

邮箱地址不会被公开。 必填项已用*标注