数据采集20200628(市场平均PE方法二)

#市场平均PE方法二

TDate=’20200624′

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()

#data.plot(figsize=(14,5)).legend(fontsize=14)#画图

data[‘PEBack’]=1/data.PE

medPEBack={np.median(data.PEBack)}

table={‘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)’:([1/np.median(data.PEBack)])}

APE=pd.DataFrame(table)

APE

APB APB+ APE(TTM) APE(TTM)+ MPE(TTM)
0 4.128349 3.601089 -20.981641 42.925241 51.5158

Leave a Reply

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