get_index_stocks(index_symbol,date=None)
获取一个指数给定日期在平台可交易的成分股列表。
1.各项参数意义
1)date:查询日期,类型为字符串,如:“2021-10-20”或为datetime.datetime对象和datatime.date。
默认值为None,研究中默认为当天;回测时默认随着回测日期的变化而变化,等于context.current_dt。
2).index_symbol
指数代码。这里支持600种股票指数数据。
该函数的返回值是股票代码的list列表。
2.实例
get_index_stocks('000134.XSHG')
['600000.XSHG', '600015.XSHG', '600016.XSHG', '600036.XSHG', '600908.XSHG', '600919.XSHG', '600926.XSHG', '600928.XSHG', '601009.XSHG', '601077.XSHG', '601128.XSHG', '601166.XSHG', '601169.XSHG', '601187.XSHG', '601229.XSHG', '601288.XSHG', '601328.XSHG', '601398.XSHG', '601577.XSHG', '601658.XSHG', '601818.XSHG', '601838.XSHG', '601860.XSHG', '601916.XSHG', '601939.XSHG', '601988.XSHG', '601997.XSHG', '601998.XSHG', '603323.XSHG']
stocks=get_index_stocks('000134.XSHG')
df1=history(10,unit='1d',field='open',security_list=stocks,df=True,skip_paused=False,fq='pre')
print("上证银行指数的成分股近10个交易日的开盘价信息:\n",df1)
上证银行指数的成分股近10个交易日的开盘价信息: 600000.XSHG 600015.XSHG ... 601998.XSHG 603323.XSHG 2021-10-13 9.14 5.70 ... 4.62 5.34 2021-10-14 9.07 5.69 ... 4.63 5.23 2021-10-15 9.05 5.64 ... 4.59 5.20 2021-10-18 9.06 5.65 ... 4.60 5.10 2021-10-19 9.03 5.65 ... 4.60 5.16 2021-10-20 9.03 5.65 ... 4.62 5.34 2021-10-21 9.05 5.65 ... 4.62 5.37 2021-10-22 9.07 5.72 ... 4.65 5.44 2021-10-25 9.03 5.71 ... 4.64 5.40 2021-10-26 9.06 5.71 ... 4.62 5.49 [10 rows x 29 columns]
df2=get_fundamentals(query(valuation.pe_ratio,valuation.turnover_ratio).filter(valuation.code.in_(stocks)),'2021-10-20')
df2
pe_ratio | turnover_ratio | |
---|---|---|
0 | 4.4716 | 0.0936 |
1 | 3.7800 | 0.0941 |
2 | 5.2817 | 0.1484 |
3 | 12.1570 | 0.1482 |
4 | 7.9795 | 1.0369 |
5 | 5.2026 | 0.5911 |
6 | 11.0084 | 0.2440 |
7 | 6.9811 | 0.3142 |
8 | 6.9048 | 0.3400 |
9 | 4.8337 | 1.2618 |
10 | 9.4061 | 0.8173 |
11 | 5.3653 | 0.3505 |
12 | 4.1530 | 0.2206 |
13 | 10.5570 | 1.7244 |
14 | 4.8039 | 0.1175 |
15 | 4.5013 | 0.0495 |
16 | 4.0062 | 0.1362 |
17 | 5.0670 | 0.0399 |
18 | 5.8632 | 0.6024 |
19 | 6.8302 | 1.0738 |
20 | 4.4492 | 0.1346 |
21 | 6.6759 | 1.2184 |
22 | 8.4425 | 0.6649 |
23 | 6.0621 | 0.1343 |
24 | 5.2405 | 0.5076 |
25 | 4.3993 | 0.0366 |
26 | 4.0795 | 0.2123 |
27 | 4.2994 | 0.0318 |
28 | 9.1750 | 1.2025 |