CentOS7下AkShare初体验

  |   0 评论   |   0 浏览

背景

AkShare是一个Python开发的开源金融数据接口库,能够做金融数据的ETL。

初体验

本地环境为:CentOS Linux release 7.5.1804 (Core)

安装

安装 python3.6+

sudo yum install python3

安装 akshare

推荐使用非root用户来安装,如下:

pip3 install akshare  --upgrade -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com --user

安装成功提示

Successfully installed akshare-0.4.54 appdirs-1.4.3 beautifulsoup4-4.8.2 bs4-0.0.1 certifi-2019.11.28 chardet-3.0.4 cssselect-1.1.0 cycler-0.10.0 decorator-4.4.2 demjson-2.2.4 et-xmlfile-1.0.1 fake-useragent-0.1.11 fonttools-4.6.0 html5lib-1.0.1 idna-2.9 jdcal-1.4.1 joblib-0.14.1 jsonpath-0.82 kiwisolver-1.1.0 lxml-4.5.0 matplotlib-3.2.1 numpy-1.18.2 openpyxl-3.0.3 pandas-1.0.3 parse-1.15.0 pillow-7.0.0 pycryptodomex-3.9.7 pyee-7.0.1 pyexecjs-1.5.1 pyparsing-2.4.6 pypinyin-0.37.0 pyppeteer-0.0.25 pyquery-1.4.1 python-dateutil-2.8.1 pytz-2019.3 requests-2.23.0 requests-html-0.10.0 scikit-learn-0.22.2.post1 scipy-1.4.1 setuptools-46.1.3 six-1.14.0 soupsieve-2.0 tabulate-0.8.7 tqdm-4.43.0 urllib3-1.25.8 w3lib-1.21.0 webencodings-0.5.1 websocket-client-0.57.0 websockets-8.1 xlrd-1.2.0

安装NodeJS

参考NodeJS官方文档

curl -sL https://rpm.nodesource.com/setup_13.x | sudo bash -

然后安装

sudo yum install -y nodejs

使用

获取展期收益率

import akshare as ak
ak.get_roll_yield_bar(type_method="date", var="RB", start_day="20180618", end_day="20180718", plot=True)

结果

            roll_yield near_by deferred
2018-06-19    0.191289  RB1810   RB1901
2018-06-20    0.192123  RB1810   RB1901
2018-06-21    0.183304  RB1810   RB1901
2018-06-22    0.190642  RB1810   RB1901
2018-06-25    0.194838  RB1810   RB1901
...                ...     ...      ...
2018-07-12    0.212805  RB1810   RB1901
2018-07-13    0.170282  RB1810   RB1901
2018-07-16    0.218066  RB1810   RB1901
2018-07-17    0.229768  RB1810   RB1901
2018-07-18    0.225529  RB1810   RB1901

[22 rows x 3 columns]

获取私募指数数据

import akshare as ak 
ak.zdzk_fund_index(index_type=32, plot=True)

结果

2014-12-26    1000.000000
2015-01-02     985.749098
2015-01-09    1032.860242
2015-01-16    1039.978586
2015-01-23    1046.235945
                 ...
2020-02-07    1445.732520
2020-02-14    1447.868982
2020-02-21    1461.479869
2020-02-28    1456.578298
2020-03-06    1468.761406
Name: 智道管理期货指数, Length: 272, dtype: float64

获取美股历史行情数据

每日历史行情

>>> stock_us_daily_df = ak.stock_us_daily(symbol="BABA")
>>> print(stock_us_daily_df)
              open    high     low   close     volume
date
2014-09-19   92.70   99.70   89.95   93.89  250591300
2014-09-22   92.70   92.95   89.50   89.89   58213800
2014-09-23   88.91   90.48   86.62   87.17   35105200
2014-09-24   88.47   90.57   87.22   90.57   27692400
2014-09-25   91.09   91.50   88.50   88.92   24874100
...            ...     ...     ...     ...        ...
2020-03-19  179.26  187.25  177.39  180.88   20905687
2020-03-20  187.74  188.30  180.00  181.30   21006082
2020-03-23  175.27  178.50  169.95  176.34   22554715
2020-03-24  183.09  188.80  181.18  185.75   20801494
2020-03-25  185.82  195.19  184.52  188.56   19605247

[1388 rows x 5 columns]

前复权数据

>>> stock_us_daily_df = ak.stock_us_daily(symbol="BABA",factor="qfq")
>>> print(stock_us_daily_df)
         date qfq_factor
0  1900-01-01          1

进一步阅读

参考