features接口对比history_data接口

策略分享
标签: #<Tag:0x00007f73dacfb6b0>

(iQuant) #1
克隆策略

两个数据接口分别获取市盈率数据

In [12]:
df = D.history_data(D.instruments(), '2017-09-01', '2017-09-09', fields=['in_csi300'])
instruments = list(set(df[df['in_csi300']==1]['instrument']))
assert len(instruments) == 300
df_f = D.features(instruments, start_date='2017-09-19', end_date='2017-09-19', fields=['pe_ttm_0'])
df_h = D.history_data(instruments, start_date='2017-09-19', end_date='2017-09-19', fields=['pe_ttm'])
print('features api:',len(df_f))
print('history_data api:',len(df_h))
features api: 283
history_data api: 300

检查相差的这17只股票是哪些?

In [17]:
set(df_h.instrument) - set(df_f.instrument)
Out[17]:
{'000100.SZA',
 '000503.SZA',
 '000540.SZA',
 '000555.SZA',
 '002252.SZA',
 '002426.SZA',
 '002739.SZA',
 '300104.SZA',
 '600021.SHA',
 '600074.SHA',
 '600100.SHA',
 '600485.SHA',
 '600682.SHA',
 '600871.SHA',
 '600959.SHA',
 '601600.SHA',
 '601989.SHA'}

我们以601600股票来查询为什么没有市盈率因子数据

In [21]:
D.features(['601600.SHA'], '2017-09-08', '2017-09-20', ['pe_ttm_0'])
Out[21]:
pe_ttm_0 instrument date
0 102.769913 601600.SHA 2017-09-08
1 109.974678 601600.SHA 2017-09-11

发现,2017-09-11之前是有数据的,于是采用history_data来拉下交易数据看看

In [23]:
D.history_data(['601600.SHA'], '2017-09-08', '2017-09-20', ['open','high','low','close','suspended'])
Out[23]:
date close high instrument low open suspended
0 2017-09-08 7.707231 7.890737 601600.SHA 7.584894 7.768400 False
1 2017-09-11 8.247553 8.369890 601600.SHA 7.503336 7.646062 False
2 2017-09-12 8.247553 8.247553 601600.SHA 8.247553 8.247553 True
3 2017-09-13 8.247553 8.247553 601600.SHA 8.247553 8.247553 True
4 2017-09-14 8.247553 8.247553 601600.SHA 8.247553 8.247553 True
5 2017-09-15 8.247553 8.247553 601600.SHA 8.247553 8.247553 True
6 2017-09-18 8.247553 8.247553 601600.SHA 8.247553 8.247553 True
7 2017-09-19 8.247553 8.247553 601600.SHA 8.247553 8.247553 True

最后一个字段为是否停牌,可以看出9月12号以后停牌了,因此就没有数据了。

总结:features 数据api在获取数据的时候,将停牌数据剔除了。

In [24]:
df_h[df_h['instrument'] =='601600.SHA']
Out[24]:
pe_ttm instrument date
572736 109.974678 601600.SHA 2017-09-19
In [26]:
df_f[df_f['instrument'] =='601600.SHA']
Out[26]:
pe_ttm_0 instrument date