在该 notebook,我们将介绍 xalpha 2020 引入的全新特性,及使用的典型范式,以期用户对 xalpha 的基本工作流有一个大致而全新的认识
import xalpha as xa
holdings.py is found and loaded within xalpha dir
我们总是推荐用 xa.meth 的方式来调用 xalpha 中的函数, import xalpha from meth 强烈不建议使用,可能导致部分运行时动态调整功能和设定失效
xa.set_backend(backend="csv", path="../../../lof/data", precached="20170101")
通过上述命令,我们设定了 xalpha 的全局本地缓存,可以将利用到的金融数据日线全部缓存到本地文件夹 path 中,并以 csv 文件的形式存在。 该缓存也支持数据库后端,backend="sql". 同时 precached 命令告诉缓存引擎,无论抓取的数据需要多少,都至少先将 20170101 至今的数据爬取并缓存到本地。
import logging
logger = logging.getLogger('xalpha')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
我们接下来设定 xalpha 的日志输出,上述设定表示打印 xalpha 所有 DEBUG 级别以上的日志,同时打印到 jupyter notebook 里, 这些内容详细记录了网络连接等 debug 信息。
# 我们可以通过 get_daily 来获取几乎一切内容的日线信息
# 下边并未有 log,显示我们的缓存后端本来就有该文件
xa.get_daily("USD/CNY", start="20190101", end="20190113")
date | close | |
---|---|---|
487 | 2019-01-02 | 6.8482 |
488 | 2019-01-03 | 6.8631 |
489 | 2019-01-04 | 6.8586 |
490 | 2019-01-07 | 6.8517 |
491 | 2019-01-08 | 6.8402 |
492 | 2019-01-09 | 6.8526 |
493 | 2019-01-10 | 6.8160 |
494 | 2019-01-11 | 6.7909 |
# 对与人民币美元中间价的获取,log 显示了更新,和爬取到 20170101 的过程
xa.get_daily("SGD/CNY", start="20200301")
Fetching url: http://www.chinamoney.com.cn/ags/ms/cm-u-bk-ccpr/CcprHisNew?startDate=2019-04-10&endDate=2020-04-04¤cy=SGD/CNY&pageNum=1&pageSize=300 . Inside function `get_rmb` Fetching url: http://www.chinamoney.com.cn/ags/ms/cm-u-bk-ccpr/CcprHisNew?startDate=2018-04-14&endDate=2019-04-09¤cy=SGD/CNY&pageNum=1&pageSize=300 . Inside function `get_rmb` Fetching url: http://www.chinamoney.com.cn/ags/ms/cm-u-bk-ccpr/CcprHisNew?startDate=2017-04-18&endDate=2018-04-13¤cy=SGD/CNY&pageNum=1&pageSize=300 . Inside function `get_rmb` Fetching url: http://www.chinamoney.com.cn/ags/ms/cm-u-bk-ccpr/CcprHisNew?startDate=2017-01-01&endDate=2017-04-17¤cy=SGD/CNY&pageNum=1&pageSize=300 . Inside function `get_rmb`
date | close | |
---|---|---|
24 | 2020-03-02 | 5.0129 |
23 | 2020-03-03 | 5.0039 |
22 | 2020-03-04 | 5.0087 |
21 | 2020-03-05 | 5.0091 |
20 | 2020-03-06 | 5.0099 |
19 | 2020-03-09 | 5.0254 |
18 | 2020-03-10 | 5.0132 |
17 | 2020-03-11 | 5.0027 |
16 | 2020-03-12 | 4.9876 |
15 | 2020-03-13 | 4.9691 |
14 | 2020-03-16 | 4.9551 |
13 | 2020-03-17 | 4.9320 |
12 | 2020-03-18 | 4.9200 |
11 | 2020-03-19 | 4.8917 |
10 | 2020-03-20 | 4.8975 |
9 | 2020-03-23 | 4.8775 |
8 | 2020-03-24 | 4.8720 |
7 | 2020-03-25 | 4.8881 |
6 | 2020-03-26 | 4.8827 |
5 | 2020-03-27 | 4.9231 |
4 | 2020-03-30 | 4.9329 |
3 | 2020-03-31 | 4.9724 |
2 | 2020-04-01 | 4.9792 |
1 | 2020-04-02 | 4.9465 |
0 | 2020-04-03 | 4.9685 |
对于彭博数据的爬取,可能需要设定网络代理, xalpha 支持 http 和 socks 代理,并可以运行时随时设定随时取消。
xa.set_proxy("socks5://127.0.0.1:1080") # 设置本地 socks 代理
df = xa.get_daily("BB-ZGLD:SW", prev=20) # 抓取数据
xa.set_proxy() # 取消代理
df
Using proxy socks5://127.0.0.1:1080 Fetching url: https://www.bloomberg.com/markets2/api/history/ZGLD:SW/PX_LAST?timeframe=1_MONTH&period=daily&volumePeriod=daily . Inside function `get_historical_frombb`
date | close | |
---|---|---|
1245 | 2020-03-16 | 434.75 |
1246 | 2020-03-17 | 449.35 |
1247 | 2020-03-18 | 440.00 |
1248 | 2020-03-19 | 441.45 |
1249 | 2020-03-20 | 444.55 |
1250 | 2020-03-23 | 463.00 |
1251 | 2020-03-24 | 487.90 |
1252 | 2020-03-25 | 483.75 |
1253 | 2020-03-26 | 481.80 |
1254 | 2020-03-27 | 474.50 |
1255 | 2020-03-30 | 474.85 |
1256 | 2020-03-31 | 474.00 |
1257 | 2020-04-01 | 468.10 |
1258 | 2020-04-02 | 476.75 |
1259 | 2020-04-03 | 481.00 |
# 获取英为数据
xa.get_daily("commodities/crude-oil", prev=10)
date | open | close | high | low | percent | |
---|---|---|---|---|---|---|
3158 | 2020-03-25 | 24.37 | 24.49 | 25.24 | 22.91 | 2.00% |
3159 | 2020-03-26 | 24.25 | 22.60 | 24.65 | 22.38 | -7.72% |
3160 | 2020-03-27 | 23.29 | 21.51 | 23.44 | 20.88 | -4.82% |
3161 | 2020-03-30 | 20.93 | 20.09 | 20.93 | 19.27 | -6.60% |
3162 | 2020-03-31 | 20.23 | 20.48 | 21.89 | 20.01 | 1.94% |
3163 | 2020-04-01 | 20.10 | 20.31 | 21.55 | 19.90 | -0.83% |
3164 | 2020-04-02 | 21.22 | 25.32 | 27.39 | 20.76 | 24.67% |
3165 | 2020-04-03 | 24.71 | 24.05 | 24.71 | 23.52 | -5.02% |
# 获取 FT 数据
xa.get_daily("FTC-WTI+Crude+Oil", prev=10)
date | open | close | high | low | |
---|---|---|---|---|---|
812 | 2020-03-25 | 24.37 | 24.31 | 25.24 | 22.91 |
813 | 2020-03-26 | 24.25 | 23.18 | 24.65 | 22.38 |
814 | 2020-03-27 | 23.29 | 21.84 | 23.44 | 20.88 |
815 | 2020-03-30 | 20.93 | 20.28 | 20.93 | 19.27 |
816 | 2020-03-31 | 20.23 | 20.10 | 21.89 | 20.01 |
817 | 2020-04-01 | 20.10 | 21.20 | 21.55 | 19.90 |
818 | 2020-04-02 | 21.22 | 24.75 | 27.39 | 20.76 |
819 | 2020-04-03 | 24.81 | 24.88 | 25.21 | 23.52 |
# 获取标普各种指数数据
xa.get_daily("SP5475707.2", prev=10)
Fetching url: https://us.spindices.com/idsexport/file.xls?selectedModule=PerformanceGraphView&selectedSubModule=Graph&yearFlag=oneYearFlag&indexId=5475707 . Inside function `get_historical_fromsp`
date | close | |
---|---|---|
780 | 2020-03-25 | 896.87 |
781 | 2020-03-26 | 931.77 |
782 | 2020-03-27 | 875.53 |
783 | 2020-03-30 | 887.21 |
784 | 2020-03-31 | 928.01 |
785 | 2020-04-01 | 900.94 |
786 | 2020-04-02 | 962.12 |
787 | 2020-04-03 | 949.04 |
# 获取雅虎数据
xa.get_daily("YH-CSGOLD.SW", prev=8)
Fetching url: https://query1.finance.yahoo.com/v8/finance/chart/CSGOLD.SW?region=US&lang=en-US&includePrePost=false&interval=1d&range=5y&corsDomain=finance.yahoo.com&.tsrc=finance . Inside function `get_historical_fromyh`
date | close | open | high | low | |
---|---|---|---|---|---|
1250 | 2020-03-27 | 156.559998 | 155.820007 | 158.320007 | 155.240005 |
1251 | 2020-03-30 | 157.360001 | 158.059998 | 158.059998 | 156.259995 |
1252 | 2020-03-31 | 156.160004 | 156.619995 | 156.679993 | 153.899994 |
1253 | 2020-04-01 | 154.080002 | 153.720001 | 155.679993 | 152.619995 |
1254 | 2020-04-02 | 156.240005 | 154.300003 | 157.360001 | 153.660004 |
1255 | 2020-04-03 | 156.679993 | 155.800003 | 157.899994 | 155.399994 |
# 获取美股数据
xa.get_daily("LK", prev=5)
date | open | close | high | low | percent | |
---|---|---|---|---|---|---|
218 | 2020-03-30 | 26.50 | 25.60 | 26.80 | 25.02 | -0.12 |
219 | 2020-03-31 | 26.36 | 27.19 | 29.53 | 26.01 | 6.21 |
220 | 2020-04-01 | 26.14 | 26.20 | 26.60 | 25.02 | -3.64 |
221 | 2020-04-02 | 4.91 | 6.40 | 10.58 | 4.90 | -75.57 |
222 | 2020-04-03 | 7.05 | 5.38 | 7.35 | 5.28 | -15.94 |
# 获取 A 股数据
xa.get_daily("SH600000", prev=5)
Fetching url: https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=SH600000&begin=1586069190611&period=day&type=before&count=-1190 . Inside function `get_history`
date | open | close | high | low | percent | |
---|---|---|---|---|---|---|
1185 | 2020-03-30 | 10.18 | 10.28 | 10.28 | 10.11 | 0.39 |
1186 | 2020-03-31 | 10.30 | 10.15 | 10.36 | 10.13 | -1.26 |
1187 | 2020-04-01 | 10.11 | 10.09 | 10.26 | 10.09 | -0.59 |
1188 | 2020-04-02 | 10.09 | 10.20 | 10.20 | 10.07 | 1.09 |
1189 | 2020-04-03 | 10.13 | 10.15 | 10.21 | 10.12 | -0.49 |
# 获取港股数据
xa.get_daily("HK00700", prev=5)
Fetching url: https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=00700&begin=1586069217747&period=day&type=before&count=-9 . Inside function `get_history`
date | open | close | high | low | percent | |
---|---|---|---|---|---|---|
1181 | 2020-03-30 | 371.8 | 376.6 | 380.0 | 371.6 | -1.52 |
1182 | 2020-03-31 | 385.2 | 380.2 | 386.0 | 370.8 | 0.96 |
1183 | 2020-04-01 | 383.6 | 374.4 | 383.6 | 372.4 | -1.53 |
1184 | 2020-04-02 | 370.0 | 379.8 | 379.8 | 369.6 | 1.44 |
1185 | 2020-04-03 | 372.0 | 376.4 | 376.4 | 372.0 | -0.90 |
# 获取基金数据
xa.get_daily("F501018", prev=5)
Fetching url: http://fund.eastmoney.com/pingzhongdata/501018.js . Inside function `_basic_init` Fetching url: http://fund.eastmoney.com/f10/jjfl_501018.html . Inside function `_feepreprocess`
no saved copy of 501018
date | close | |
---|---|---|
916 | 2020-03-30 | 0.5183 |
917 | 2020-03-31 | 0.5241 |
918 | 2020-04-01 | 0.5142 |
919 | 2020-04-02 | 0.5723 |
我们也可以通过 get_rt 获取实时数据,通过 get_bar 获取分钟线小时线等数据,以下是一些例子
xa.get_rt("PDD")
{'currency': 'USD', 'current': 51.19, 'current_ext': 51.39, 'floatshare': None, 'market': 'US', 'name': '拼多多', 'percent': 3.27, 'time': '2020-04-28 04:00:00', 'totshare': 1197626247, 'volume': 4717569}
xa.get_rt("SH501018")
# 请注意第二次请求已经不需要去要雪球 token 了,因为已缓存
{'currency': 'CNY', 'current': 0.717, 'current_ext': None, 'floatshare': None, 'market': 'CN', 'name': '南方原油LOF', 'percent': -1.38, 'time': '2020-04-28 09:30:04', 'totshare': 3180963285, 'volume': 7808665}
xa.get_rt("FT-INX:IOM")
# 请注意 FT 的实时数据存在延迟!
Fetching url: https://markets.ft.com/data/indices/tearsheet/summary?s=INX:IOM . Inside function `get_rt_from_ft`
{'currency': 'USD', 'current': 2488.65, 'current_ext': None, 'market': None, 'name': 'S&P 500 INDEX', 'percent': -1.51}
xa.get_rt("INA-currencies/usd-cnh")
# 从 app 源获取英为实时数据
Fetching url: https://cnappapi.investing.com/currencies/usd-cnh . Inside function `get_cninvesting_rt`
{'currency': None, 'current': 7.1119, 'current_ext': None, 'market': None, 'name': 'USD/CNH - 美元 离岸人民币', 'percent': 0.26}
xa.get_rt("SH600000", double_check=True)
# 获取 A 股数据,并经过新浪源的双重校验
Fetching url: https://xueqiu.com . Inside function `get_token` Fetching url: https://stock.xueqiu.com/v5/stock/quote.json?symbol=SH600000&extend=detail . Inside function `get_xueqiu_rt` Fetching url: https://hq.sinajs.cn/list=sh600000 . Inside function `get_rt_from_sina`
{'currency': 'CNY', 'current': 10.15, 'current_ext': None, 'market': 'CN', 'name': '浦发银行', 'percent': -0.49}
xa.get_bar("indices/germany-30", interval=3600)
# 获取小时线数据
Fetching url: https://cn.investing.com/indices/germany-30 . Inside function `get_investing_id` Fetching url: https://cn.investing.com/common/modules/js_instrument_chart/api/data.php?pair_id=172&pair_id_for_news=172&chart_type=area&pair_interval=3600&candle_count=24&events=yes&volume_series=yes&period= . Inside function `get_bar_frominvesting`
date | close | |
---|---|---|
0 | 2020-04-01 18:00:00 | 9583.50 |
1 | 2020-04-01 19:00:00 | 9551.50 |
2 | 2020-04-01 20:00:00 | 9533.00 |
3 | 2020-04-01 21:00:00 | 9559.75 |
4 | 2020-04-01 22:00:00 | 9586.75 |
5 | 2020-04-01 23:00:00 | 9539.50 |
6 | 2020-04-02 15:00:00 | 9542.25 |
7 | 2020-04-02 16:00:00 | 9565.75 |
8 | 2020-04-02 17:00:00 | 9548.75 |
9 | 2020-04-02 18:00:00 | 9594.25 |
10 | 2020-04-02 19:00:00 | 9580.50 |
11 | 2020-04-02 20:00:00 | 9433.00 |
12 | 2020-04-02 21:00:00 | 9451.50 |
13 | 2020-04-02 22:00:00 | 9613.75 |
14 | 2020-04-02 23:00:00 | 9569.00 |
15 | 2020-04-03 15:00:00 | 9534.75 |
16 | 2020-04-03 16:00:00 | 9529.75 |
17 | 2020-04-03 17:00:00 | 9527.00 |
18 | 2020-04-03 18:00:00 | 9535.25 |
19 | 2020-04-03 19:00:00 | 9611.00 |
20 | 2020-04-03 20:00:00 | 9569.75 |
21 | 2020-04-03 21:00:00 | 9558.75 |
22 | 2020-04-03 22:00:00 | 9547.25 |
23 | 2020-04-03 23:00:00 | 9525.77 |
下面简单演示对于承载数据的 pd.DataFrame 的简单处理和可视化
df = xa.get_daily("USD/CNY", prev=20)
df[df["date"]=="2020-04-02"].iloc[0]["close"]
7.0995
% matplotlib notebook
df.plot(x="date", y="close")
<matplotlib.axes._subplots.AxesSubplot at 0x11a37fe48>
df[df["close"]>7.08]
date | close | |
---|---|---|
781 | 2020-03-20 | 7.1052 |
782 | 2020-03-23 | 7.0940 |
783 | 2020-03-24 | 7.0999 |
788 | 2020-03-31 | 7.0851 |
790 | 2020-04-02 | 7.0995 |
791 | 2020-04-03 | 7.1104 |
df.sort_values("close")
date | close | |
---|---|---|
777 | 2020-03-16 | 7.0018 |
778 | 2020-03-17 | 7.0094 |
779 | 2020-03-18 | 7.0328 |
786 | 2020-03-27 | 7.0427 |
787 | 2020-03-30 | 7.0447 |
780 | 2020-03-19 | 7.0522 |
785 | 2020-03-26 | 7.0692 |
784 | 2020-03-25 | 7.0742 |
789 | 2020-04-01 | 7.0771 |
788 | 2020-03-31 | 7.0851 |
782 | 2020-03-23 | 7.0940 |
790 | 2020-04-02 | 7.0995 |
783 | 2020-03-24 | 7.0999 |
781 | 2020-03-20 | 7.1052 |
791 | 2020-04-03 | 7.1104 |
df["close"].pct_change()
777 NaN 778 0.001085 779 0.003338 780 0.002759 781 0.007515 782 -0.001576 783 0.000832 784 -0.003620 785 -0.000707 786 -0.003749 787 0.000284 788 0.005735 789 -0.001129 790 0.003165 791 0.001535 Name: close, dtype: float64
c = xa.Compare(("commodities/crude-oil", "USD"), "F501018", "F160216", start="20190101")
c.v()
Fetching url: http://fund.eastmoney.com/pingzhongdata/501018.js . Inside function `_basic_init` DEBUG:xalpha.cons:Fetching url: http://fund.eastmoney.com/pingzhongdata/501018.js . Inside function `_basic_init` Fetching url: http://fund.eastmoney.com/f10/jjfl_501018.html . Inside function `_feepreprocess` DEBUG:xalpha.cons:Fetching url: http://fund.eastmoney.com/f10/jjfl_501018.html . Inside function `_feepreprocess` Fetching url: http://fund.eastmoney.com/pingzhongdata/160216.js . Inside function `_basic_init` DEBUG:xalpha.cons:Fetching url: http://fund.eastmoney.com/pingzhongdata/160216.js . Inside function `_basic_init` Fetching url: http://fund.eastmoney.com/f10/jjfl_160216.html . Inside function `_feepreprocess` DEBUG:xalpha.cons:Fetching url: http://fund.eastmoney.com/f10/jjfl_160216.html . Inside function `_feepreprocess`
<matplotlib.axes._subplots.AxesSubplot at 0x11a998978>
c.corr() # 打印关联系数
commodities/crude-oil | F501018 | F160216 | |
---|---|---|---|
commodities/crude-oil | 1.000000 | 0.870583 | 0.934701 |
F501018 | 0.870583 | 1.000000 | 0.952503 |
F160216 | 0.934701 | 0.952503 | 1.000000 |
# 使用聚宽数据需要激活数据源,如果之前没有激活的话
user = "jquser"
passw = "jqpassw"
xa.provider.set_jq_data(user, passw)
df = xa.get_daily("mcm-MAC_SALE_RETAIL_MONTH", start="20180301")
# 获取宏观数据,商品零售总额
df
id | stat_month | retail_sin | retail_acc | retail_sin_yoy | retail_acc_yoy | scale_retail_sin | scale_retail_acc | scale_retail_sin_yoy | scale_retail_acc_yoy | ... | hotel_scale_retail_acc_yoy | sale_retail_sin | sale_retail_acc | sale_retail_sin_yoy | sale_retail_acc_yoy | sale_scale_retail_sin | sale_scale_retail_acc | sale_scale_retail_sin_yoy | sale_scale_retail_acc_yoy | date | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 404 | 2018-03-01 | 29193.6000 | 90275.4000 | 10.1000 | 9.8000 | 11831.8000 | 34941.0000 | 9.0000 | 8.5000 | ... | 8.0000 | 26095.0000 | 80563.9000 | 10.0000 | 9.800 | 11112.5000 | 32754.7000 | 8.9000 | 8.6000 | 2018-03-01 |
2 | 405 | 2018-04-01 | 28541.9000 | 118817.3000 | 9.4000 | 9.7000 | 11240.6000 | 46136.9000 | 7.8000 | 8.4000 | ... | 7.7000 | 25517.4000 | 106081.3000 | 9.4000 | 9.700 | 10540.4000 | 43247.9000 | 7.8000 | 8.4000 | 2018-04-01 |
3 | 406 | 2018-05-01 | 30359.1000 | 149176.4000 | 8.5000 | 9.5000 | 11476.7000 | 57517.7000 | 5.5000 | 7.8000 | ... | 7.1000 | 27038.4000 | 133119.7000 | 8.4000 | 9.400 | 10735.6000 | 53888.1000 | 5.6000 | 7.8000 | 2018-05-01 |
4 | 407 | 2018-06-01 | 30841.6000 | 180017.9000 | 9.0000 | 9.4000 | 12448.3000 | 69937.6000 | 6.5000 | 7.5000 | ... | 7.2000 | 27441.0000 | 160560.7000 | 8.9000 | 9.300 | 11671.3000 | 65538.2000 | 6.4000 | 7.6000 | 2018-06-01 |
5 | 419 | 2018-07-01 | 30733.7000 | 210751.6000 | 8.8000 | 9.3000 | 11419.0000 | 81125.2000 | 5.7000 | 7.3000 | ... | 7.0000 | 27390.5000 | 187951.2000 | 8.7000 | 9.200 | 10655.2000 | 75978.8000 | 5.7000 | 7.3000 | 2018-07-01 |
6 | 420 | 2018-08-01 | 31542.3000 | 242293.9000 | 9.0000 | 9.3000 | 11832.2000 | 92367.7000 | 6.0000 | 7.1000 | ... | 7.1000 | 28026.2000 | 215977.4000 | 8.9000 | 9.200 | 11041.1000 | 86460.3000 | 5.9000 | 7.1000 | 2018-08-01 |
7 | 421 | 2018-09-01 | 32005.4000 | 274299.3000 | 9.2000 | 9.3000 | 12761.7000 | 104792.1000 | 5.7000 | 6.9000 | ... | 7.0000 | 28558.5000 | 244535.9000 | 9.2000 | 9.200 | 11961.6000 | 98099.3000 | 5.6000 | 6.9000 | 2018-09-01 |
8 | 422 | 2018-10-01 | 35534.4000 | 309833.7000 | 8.6000 | 9.2000 | 12478.6000 | 117177.5000 | 3.7000 | 6.6000 | ... | 6.8000 | 31528.4000 | 276064.3000 | 8.5000 | 9.100 | 11630.1000 | 109637.1000 | 3.6000 | 6.6000 | 2018-10-01 |
9 | 423 | 2018-11-01 | 35259.7000 | 345093.4000 | 8.1000 | 9.1000 | 13678.7000 | 130829.9000 | 2.1000 | 6.1000 | ... | 6.5000 | 30734.7000 | 306799.1000 | 8.0000 | 9.000 | 12862.1000 | 122473.1000 | 2.0000 | 6.1000 | 2018-11-01 |
10 | 424 | 2018-12-01 | 35893.4983 | 380986.8522 | 8.1608 | 8.9817 | 15084.0071 | 145311.2873 | 2.4369 | 5.7055 | ... | 6.4283 | 31471.9353 | 338270.9998 | 8.0408 | 8.921 | 14174.7441 | 136074.9283 | 2.2457 | 5.6575 | 2018-12-01 |
11 | 425 | 2019-02-01 | 0.0000 | 66064.0000 | 0.0000 | 8.2000 | 0.0000 | 23096.0000 | 0.0000 | 3.5000 | ... | 8.1000 | 0.0000 | 58813.0000 | 0.0000 | 8.000 | 0.0000 | 21580.0000 | 0.0000 | 3.2000 | 2019-02-01 |
12 | 426 | 2019-03-01 | 31725.7000 | 97789.7000 | 8.7000 | 8.3000 | 11952.5000 | 35078.2000 | 5.1000 | 4.1000 | ... | 7.9000 | 28332.8000 | 87145.7000 | 8.6000 | 8.200 | 11226.8000 | 32852.4000 | 5.0000 | 3.8000 | 2019-03-01 |
13 | 427 | 2019-04-01 | 30586.1000 | 128375.8000 | 7.2000 | 8.0000 | 11120.1000 | 46211.9000 | 2.0000 | 3.5000 | ... | 7.1000 | 27305.3000 | 114451.0000 | 7.0000 | 7.900 | 10428.8000 | 43291.3000 | 1.8000 | 3.3000 | 2019-04-01 |
14 | 428 | 2019-05-01 | 32955.7000 | 161331.6000 | 8.6000 | 8.1000 | 11693.8000 | 57924.0000 | 5.1000 | 3.9000 | ... | 7.1000 | 29324.4000 | 143775.4000 | 8.5000 | 8.000 | 10939.0000 | 54222.2000 | 5.0000 | 3.6000 | 2019-05-01 |
15 | 429 | 2019-06-01 | 33878.1000 | 195209.7000 | 9.8000 | 8.4000 | 13163.4000 | 71124.2000 | 9.7000 | 4.9000 | ... | 7.2000 | 30154.8000 | 173930.2000 | 9.9000 | 8.300 | 12374.7000 | 66627.1000 | 9.8000 | 4.7000 | 2019-06-01 |
16 | 431 | 2019-07-01 | 33073.3000 | 228282.9000 | 7.6000 | 8.3000 | 11412.1000 | 82446.2000 | 2.9000 | 4.6000 | ... | 7.2000 | 29415.2000 | 203345.4000 | 7.4000 | 8.200 | 10634.8000 | 77208.1000 | 2.6000 | 4.4000 | 2019-07-01 |
17 | 432 | 2019-08-01 | 33896.3000 | 262179.3000 | 7.5000 | 8.2000 | 11772.1000 | 93880.9000 | 2.0000 | 4.3000 | ... | 7.3000 | 30039.2000 | 233384.6000 | 7.2000 | 8.100 | 10957.4000 | 87832.6000 | 1.6000 | 4.1000 | 2019-08-01 |
18 | 434 | 2019-09-01 | 34494.9000 | 296674.2000 | 7.8000 | 8.2000 | 12835.4000 | 106691.9000 | 3.1000 | 4.1000 | ... | 7.3000 | 30724.7000 | 264109.3000 | 7.6000 | 8.000 | 12020.9000 | 99829.8000 | 2.9000 | 3.9000 | 2019-09-01 |
19 | 435 | 2019-10-01 | 38104.3000 | 334778.5000 | 7.2000 | 8.1000 | 12322.1000 | 118918.8000 | 1.2000 | 3.8000 | ... | 7.1000 | 33736.9000 | 297846.2000 | 7.0000 | 7.900 | 11475.9000 | 111223.6000 | 0.9000 | 3.6000 | 2019-10-01 |
20 | 436 | 2019-11-01 | 38093.8000 | 372872.3000 | 8.0000 | 8.0000 | 13964.7000 | 132639.1000 | 4.4000 | 3.9000 | ... | 7.2000 | 33130.1000 | 330976.3000 | 7.8000 | 7.900 | 13133.7000 | 124111.0000 | 4.2000 | 3.7000 | 2019-11-01 |
21 | 437 | 2019-12-01 | 38776.7000 | 411649.0000 | 8.0000 | 8.0000 | 15337.6000 | 148009.9000 | 4.4000 | 3.9000 | ... | 7.1000 | 33952.1000 | 364928.3000 | 7.9000 | 7.900 | 14423.6000 | 138565.1000 | 4.3000 | 3.7000 | 2019-12-01 |
22 | 438 | 2020-02-01 | 0.0000 | 52129.8000 | 0.0000 | -20.5000 | 0.0000 | 16949.8000 | 0.0000 | -23.4000 | ... | -39.7000 | 0.0000 | 47935.5000 | 0.0000 | -17.600 | 0.0000 | 16021.6000 | 0.0000 | -22.2000 | 2020-02-01 |
22 rows × 35 columns
%matplotlib notebook
df.plot(x="date", y="retail_sin")
<matplotlib.axes._subplots.AxesSubplot at 0x11a92a470>
df = xa.get_daily("mcd-MAC_LEND_RATE", start="2018-01-01")
df = df[(df["currency_name"]=="人民币") & (df["market_id"] == 5) & (df["term_id"]==20)]
%matplotlib notebook
df.plot(x="date", y="interest_rate")
<matplotlib.axes._subplots.AxesSubplot at 0x1189d8f60>
# 指数成分股和权重
xa.get_daily("iw-SH000050", start="20200331", end="20200405")
code | date | display_name | weight | |
---|---|---|---|---|
1950 | 600000.XSHG | 2020-04-01 | 浦发银行 | 1.812 |
1951 | 600009.XSHG | 2020-04-01 | 上海机场 | 1.668 |
1952 | 600016.XSHG | 2020-04-01 | 民生银行 | 1.953 |
1953 | 600028.XSHG | 2020-04-01 | 中国石化 | 1.901 |
1954 | 600030.XSHG | 2020-04-01 | 中信证券 | 2.290 |
1955 | 600031.XSHG | 2020-04-01 | 三一重工 | 2.363 |
1956 | 600036.XSHG | 2020-04-01 | 招商银行 | 1.891 |
1957 | 600050.XSHG | 2020-04-01 | 中国联通 | 1.959 |
1958 | 600104.XSHG | 2020-04-01 | 上汽集团 | 1.920 |
1959 | 600196.XSHG | 2020-04-01 | 复星医药 | 2.779 |
1960 | 600276.XSHG | 2020-04-01 | 恒瑞医药 | 2.338 |
1961 | 600309.XSHG | 2020-04-01 | 万华化学 | 1.728 |
1962 | 600340.XSHG | 2020-04-01 | 华夏幸福 | 1.615 |
1963 | 600519.XSHG | 2020-04-01 | 贵州茅台 | 2.037 |
1964 | 600547.XSHG | 2020-04-01 | 山东黄金 | 2.345 |
1965 | 600585.XSHG | 2020-04-01 | 海螺水泥 | 2.429 |
1966 | 600690.XSHG | 2020-04-01 | 海尔智家 | 1.812 |
1967 | 600703.XSHG | 2020-04-01 | 三安光电 | 2.338 |
1968 | 600837.XSHG | 2020-04-01 | 海通证券 | 1.923 |
1969 | 600887.XSHG | 2020-04-01 | 伊利股份 | 2.056 |
1970 | 601988.XSHG | 2020-04-01 | 中国银行 | 2.042 |
1971 | 600048.XSHG | 2020-04-01 | 保利地产 | 2.033 |
1972 | 601111.XSHG | 2020-04-01 | 中国国航 | 1.614 |
1973 | 601398.XSHG | 2020-04-01 | 工商银行 | 1.906 |
1974 | 601628.XSHG | 2020-04-01 | 中国人寿 | 1.684 |
1975 | 601166.XSHG | 2020-04-01 | 兴业银行 | 1.787 |
1976 | 601318.XSHG | 2020-04-01 | 中国平安 | 1.757 |
1977 | 601328.XSHG | 2020-04-01 | 交通银行 | 1.993 |
1978 | 601939.XSHG | 2020-04-01 | 建设银行 | 1.899 |
1979 | 601088.XSHG | 2020-04-01 | 中国神华 | 1.972 |
1980 | 601857.XSHG | 2020-04-01 | 中国石油 | 1.737 |
1981 | 601390.XSHG | 2020-04-01 | 中国中铁 | 2.005 |
1982 | 601601.XSHG | 2020-04-01 | 中国太保 | 1.722 |
1983 | 601186.XSHG | 2020-04-01 | 中国铁建 | 2.135 |
1984 | 601668.XSHG | 2020-04-01 | 中国建筑 | 2.140 |
1985 | 601766.XSHG | 2020-04-01 | 中国中车 | 2.005 |
1986 | 601888.XSHG | 2020-04-01 | 中国国旅 | 1.673 |
1987 | 601989.XSHG | 2020-04-01 | 中国重工 | 1.703 |
1988 | 601688.XSHG | 2020-04-01 | 华泰证券 | 2.040 |
1989 | 601012.XSHG | 2020-04-01 | 隆基股份 | 2.092 |
1990 | 601288.XSHG | 2020-04-01 | 农业银行 | 1.983 |
1991 | 601818.XSHG | 2020-04-01 | 光大银行 | 1.839 |
1992 | 601336.XSHG | 2020-04-01 | 新华保险 | 1.846 |
1993 | 603993.XSHG | 2020-04-01 | 洛阳钼业 | 1.971 |
1994 | 601211.XSHG | 2020-04-01 | 国泰君安 | 1.969 |
1995 | 601066.XSHG | 2020-04-01 | 中信建投 | 2.904 |
1996 | 601236.XSHG | 2020-04-01 | 红塔证券 | 2.694 |
1997 | 603259.XSHG | 2020-04-01 | 药明康德 | 2.124 |
1998 | 601319.XSHG | 2020-04-01 | 中国人保 | 1.974 |
1999 | 601138.XSHG | 2020-04-01 | 工业富联 | 1.601 |
# 场内基金份额
df = xa.get_daily("fs-SZ161129", start="20200201")
df.plot(x="date", y="shares")
<matplotlib.axes._subplots.AxesSubplot at 0x11787bf28>
根据实际权重的指数估值分析
h=xa.PEBHistory("SH000050", start="2013-01-01")
Fetching url: https://stock.xueqiu.com/v5/stock/quote.json?symbol=SH000050&extend=detail . Inside function `get_xueqiu_rt`
h.summary()
Fetching url: https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=SH000050&begin=1586072240181&period=day&type=before&count=-1190 . Inside function `get_history`
指数50等权估值情况
Fetching url: https://stock.xueqiu.com/v5/stock/quote.json?symbol=SH000050&extend=detail . Inside function `get_xueqiu_rt`
现在 PE 绝对值 10.801, 相对分位 24.27%,距离最低点 12.9 % 现在 PB 绝对值 1.305, 相对分位 4.22%,距离最低点 8.0 %
h.v("pb")
<matplotlib.axes._subplots.AxesSubplot at 0x11bfffc18>
# 指数成份股总盈利和总净资产
df = xa.get_daily("teb-SH000050", start="20180101")
df.plot(x="date", y="e")
<matplotlib.axes._subplots.AxesSubplot at 0x11c04dbe0>
df.plot(x="date", y="b")
<matplotlib.axes._subplots.AxesSubplot at 0x11c8c27b8>
df["roe"] = df["e"]/df["b"]
df.plot(x="date", y="roe")
<matplotlib.axes._subplots.AxesSubplot at 0x11d1755c0>
p = xa.QDIIPredict("SH501018")
p.get_t1()
Fetching url: http://fund.eastmoney.com/501018.html . Inside function `get_newest_netvalue`
(0.6273979738441035, '2020-04-03')
df = xa.get_daily("LK")
xa.set_display("notebook")
df
df.v_kline()