{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "在该 notebook,我们将介绍 xalpha 2020 引入的全新特性,及使用的典型范式,以期用户对 xalpha 的基本工作流有一个大致而全新的认识" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 基本设定" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "holdings.py is found and loaded within xalpha dir\n" ] } ], "source": [ "import xalpha as xa" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "我们总是推荐用 xa.meth 的方式来调用 xalpha 中的函数,\n", "import xalpha from meth 强烈不建议使用,可能导致部分运行时动态调整功能和设定失效" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "xa.set_backend(backend=\"csv\", path=\"../../../lof/data\", precached=\"20170101\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "通过上述命令,我们设定了 xalpha 的全局本地缓存,可以将利用到的金融数据日线全部缓存到本地文件夹 path 中,并以 csv 文件的形式存在。\n", "该缓存也支持数据库后端,backend=\"sql\".\n", "同时 precached 命令告诉缓存引擎,无论抓取的数据需要多少,都至少先将 20170101 至今的数据爬取并缓存到本地。" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import logging\n", "logger = logging.getLogger('xalpha')\n", "logger.setLevel(logging.DEBUG)\n", "ch = logging.StreamHandler()\n", "ch.setLevel(logging.DEBUG)\n", "logger.addHandler(ch)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "我们接下来设定 xalpha 的日志输出,上述设定表示打印 xalpha 所有 DEBUG 级别以上的日志,同时打印到 jupyter notebook 里,\n", "这些内容详细记录了网络连接等 debug 信息。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 使用日线和实时获取器" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateclose
4872019-01-026.8482
4882019-01-036.8631
4892019-01-046.8586
4902019-01-076.8517
4912019-01-086.8402
4922019-01-096.8526
4932019-01-106.8160
4942019-01-116.7909
\n", "
" ], "text/plain": [ " date close\n", "487 2019-01-02 6.8482\n", "488 2019-01-03 6.8631\n", "489 2019-01-04 6.8586\n", "490 2019-01-07 6.8517\n", "491 2019-01-08 6.8402\n", "492 2019-01-09 6.8526\n", "493 2019-01-10 6.8160\n", "494 2019-01-11 6.7909" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 我们可以通过 get_daily 来获取几乎一切内容的日线信息\n", "# 下边并未有 log,显示我们的缓存后端本来就有该文件\n", "xa.get_daily(\"USD/CNY\", start=\"20190101\", end=\"20190113\")" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "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`\n", "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`\n", "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`\n", "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`\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateclose
242020-03-025.0129
232020-03-035.0039
222020-03-045.0087
212020-03-055.0091
202020-03-065.0099
192020-03-095.0254
182020-03-105.0132
172020-03-115.0027
162020-03-124.9876
152020-03-134.9691
142020-03-164.9551
132020-03-174.9320
122020-03-184.9200
112020-03-194.8917
102020-03-204.8975
92020-03-234.8775
82020-03-244.8720
72020-03-254.8881
62020-03-264.8827
52020-03-274.9231
42020-03-304.9329
32020-03-314.9724
22020-04-014.9792
12020-04-024.9465
02020-04-034.9685
\n", "
" ], "text/plain": [ " date close\n", "24 2020-03-02 5.0129\n", "23 2020-03-03 5.0039\n", "22 2020-03-04 5.0087\n", "21 2020-03-05 5.0091\n", "20 2020-03-06 5.0099\n", "19 2020-03-09 5.0254\n", "18 2020-03-10 5.0132\n", "17 2020-03-11 5.0027\n", "16 2020-03-12 4.9876\n", "15 2020-03-13 4.9691\n", "14 2020-03-16 4.9551\n", "13 2020-03-17 4.9320\n", "12 2020-03-18 4.9200\n", "11 2020-03-19 4.8917\n", "10 2020-03-20 4.8975\n", "9 2020-03-23 4.8775\n", "8 2020-03-24 4.8720\n", "7 2020-03-25 4.8881\n", "6 2020-03-26 4.8827\n", "5 2020-03-27 4.9231\n", "4 2020-03-30 4.9329\n", "3 2020-03-31 4.9724\n", "2 2020-04-01 4.9792\n", "1 2020-04-02 4.9465\n", "0 2020-04-03 4.9685" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 对与人民币美元中间价的获取,log 显示了更新,和爬取到 20170101 的过程\n", "xa.get_daily(\"SGD/CNY\", start=\"20200301\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "对于彭博数据的爬取,可能需要设定网络代理, xalpha 支持 http 和 socks 代理,并可以运行时随时设定随时取消。" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using proxy socks5://127.0.0.1:1080\n", "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`\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateclose
12452020-03-16434.75
12462020-03-17449.35
12472020-03-18440.00
12482020-03-19441.45
12492020-03-20444.55
12502020-03-23463.00
12512020-03-24487.90
12522020-03-25483.75
12532020-03-26481.80
12542020-03-27474.50
12552020-03-30474.85
12562020-03-31474.00
12572020-04-01468.10
12582020-04-02476.75
12592020-04-03481.00
\n", "
" ], "text/plain": [ " date close\n", "1245 2020-03-16 434.75\n", "1246 2020-03-17 449.35\n", "1247 2020-03-18 440.00\n", "1248 2020-03-19 441.45\n", "1249 2020-03-20 444.55\n", "1250 2020-03-23 463.00\n", "1251 2020-03-24 487.90\n", "1252 2020-03-25 483.75\n", "1253 2020-03-26 481.80\n", "1254 2020-03-27 474.50\n", "1255 2020-03-30 474.85\n", "1256 2020-03-31 474.00\n", "1257 2020-04-01 468.10\n", "1258 2020-04-02 476.75\n", "1259 2020-04-03 481.00" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xa.set_proxy(\"socks5://127.0.0.1:1080\") # 设置本地 socks 代理\n", "df = xa.get_daily(\"BB-ZGLD:SW\", prev=20) # 抓取数据\n", "xa.set_proxy() # 取消代理\n", "df" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateopenclosehighlowpercent
31582020-03-2524.3724.4925.2422.912.00%
31592020-03-2624.2522.6024.6522.38-7.72%
31602020-03-2723.2921.5123.4420.88-4.82%
31612020-03-3020.9320.0920.9319.27-6.60%
31622020-03-3120.2320.4821.8920.011.94%
31632020-04-0120.1020.3121.5519.90-0.83%
31642020-04-0221.2225.3227.3920.7624.67%
31652020-04-0324.7124.0524.7123.52-5.02%
\n", "
" ], "text/plain": [ " date open close high low percent\n", "3158 2020-03-25 24.37 24.49 25.24 22.91 2.00%\n", "3159 2020-03-26 24.25 22.60 24.65 22.38 -7.72%\n", "3160 2020-03-27 23.29 21.51 23.44 20.88 -4.82%\n", "3161 2020-03-30 20.93 20.09 20.93 19.27 -6.60%\n", "3162 2020-03-31 20.23 20.48 21.89 20.01 1.94%\n", "3163 2020-04-01 20.10 20.31 21.55 19.90 -0.83%\n", "3164 2020-04-02 21.22 25.32 27.39 20.76 24.67%\n", "3165 2020-04-03 24.71 24.05 24.71 23.52 -5.02%" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 获取英为数据\n", "xa.get_daily(\"commodities/crude-oil\", prev=10)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateopenclosehighlow
8122020-03-2524.3724.3125.2422.91
8132020-03-2624.2523.1824.6522.38
8142020-03-2723.2921.8423.4420.88
8152020-03-3020.9320.2820.9319.27
8162020-03-3120.2320.1021.8920.01
8172020-04-0120.1021.2021.5519.90
8182020-04-0221.2224.7527.3920.76
8192020-04-0324.8124.8825.2123.52
\n", "
" ], "text/plain": [ " date open close high low\n", "812 2020-03-25 24.37 24.31 25.24 22.91\n", "813 2020-03-26 24.25 23.18 24.65 22.38\n", "814 2020-03-27 23.29 21.84 23.44 20.88\n", "815 2020-03-30 20.93 20.28 20.93 19.27\n", "816 2020-03-31 20.23 20.10 21.89 20.01\n", "817 2020-04-01 20.10 21.20 21.55 19.90\n", "818 2020-04-02 21.22 24.75 27.39 20.76\n", "819 2020-04-03 24.81 24.88 25.21 23.52" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 获取 FT 数据\n", "xa.get_daily(\"FTC-WTI+Crude+Oil\", prev=10)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Fetching url: https://us.spindices.com/idsexport/file.xls?selectedModule=PerformanceGraphView&selectedSubModule=Graph&yearFlag=oneYearFlag&indexId=5475707 . Inside function `get_historical_fromsp`\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateclose
7802020-03-25896.87
7812020-03-26931.77
7822020-03-27875.53
7832020-03-30887.21
7842020-03-31928.01
7852020-04-01900.94
7862020-04-02962.12
7872020-04-03949.04
\n", "
" ], "text/plain": [ " date close\n", "780 2020-03-25 896.87\n", "781 2020-03-26 931.77\n", "782 2020-03-27 875.53\n", "783 2020-03-30 887.21\n", "784 2020-03-31 928.01\n", "785 2020-04-01 900.94\n", "786 2020-04-02 962.12\n", "787 2020-04-03 949.04" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 获取标普各种指数数据\n", "xa.get_daily(\"SP5475707.2\", prev=10)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "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`\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
datecloseopenhighlow
12502020-03-27156.559998155.820007158.320007155.240005
12512020-03-30157.360001158.059998158.059998156.259995
12522020-03-31156.160004156.619995156.679993153.899994
12532020-04-01154.080002153.720001155.679993152.619995
12542020-04-02156.240005154.300003157.360001153.660004
12552020-04-03156.679993155.800003157.899994155.399994
\n", "
" ], "text/plain": [ " date close open high low\n", "1250 2020-03-27 156.559998 155.820007 158.320007 155.240005\n", "1251 2020-03-30 157.360001 158.059998 158.059998 156.259995\n", "1252 2020-03-31 156.160004 156.619995 156.679993 153.899994\n", "1253 2020-04-01 154.080002 153.720001 155.679993 152.619995\n", "1254 2020-04-02 156.240005 154.300003 157.360001 153.660004\n", "1255 2020-04-03 156.679993 155.800003 157.899994 155.399994" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 获取雅虎数据\n", "xa.get_daily(\"YH-CSGOLD.SW\", prev=8)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateopenclosehighlowpercent
2182020-03-3026.5025.6026.8025.02-0.12
2192020-03-3126.3627.1929.5326.016.21
2202020-04-0126.1426.2026.6025.02-3.64
2212020-04-024.916.4010.584.90-75.57
2222020-04-037.055.387.355.28-15.94
\n", "
" ], "text/plain": [ " date open close high low percent\n", "218 2020-03-30 26.50 25.60 26.80 25.02 -0.12\n", "219 2020-03-31 26.36 27.19 29.53 26.01 6.21\n", "220 2020-04-01 26.14 26.20 26.60 25.02 -3.64\n", "221 2020-04-02 4.91 6.40 10.58 4.90 -75.57\n", "222 2020-04-03 7.05 5.38 7.35 5.28 -15.94" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 获取美股数据\n", "xa.get_daily(\"LK\", prev=5)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "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`\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateopenclosehighlowpercent
11852020-03-3010.1810.2810.2810.110.39
11862020-03-3110.3010.1510.3610.13-1.26
11872020-04-0110.1110.0910.2610.09-0.59
11882020-04-0210.0910.2010.2010.071.09
11892020-04-0310.1310.1510.2110.12-0.49
\n", "
" ], "text/plain": [ " date open close high low percent\n", "1185 2020-03-30 10.18 10.28 10.28 10.11 0.39\n", "1186 2020-03-31 10.30 10.15 10.36 10.13 -1.26\n", "1187 2020-04-01 10.11 10.09 10.26 10.09 -0.59\n", "1188 2020-04-02 10.09 10.20 10.20 10.07 1.09\n", "1189 2020-04-03 10.13 10.15 10.21 10.12 -0.49" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 获取 A 股数据\n", "xa.get_daily(\"SH600000\", prev=5)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "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`\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateopenclosehighlowpercent
11812020-03-30371.8376.6380.0371.6-1.52
11822020-03-31385.2380.2386.0370.80.96
11832020-04-01383.6374.4383.6372.4-1.53
11842020-04-02370.0379.8379.8369.61.44
11852020-04-03372.0376.4376.4372.0-0.90
\n", "
" ], "text/plain": [ " date open close high low percent\n", "1181 2020-03-30 371.8 376.6 380.0 371.6 -1.52\n", "1182 2020-03-31 385.2 380.2 386.0 370.8 0.96\n", "1183 2020-04-01 383.6 374.4 383.6 372.4 -1.53\n", "1184 2020-04-02 370.0 379.8 379.8 369.6 1.44\n", "1185 2020-04-03 372.0 376.4 376.4 372.0 -0.90" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 获取港股数据\n", "xa.get_daily(\"HK00700\", prev=5)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Fetching url: http://fund.eastmoney.com/pingzhongdata/501018.js . Inside function `_basic_init`\n", "Fetching url: http://fund.eastmoney.com/f10/jjfl_501018.html . Inside function `_feepreprocess`\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "no saved copy of 501018\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateclose
9162020-03-300.5183
9172020-03-310.5241
9182020-04-010.5142
9192020-04-020.5723
\n", "
" ], "text/plain": [ " date close\n", "916 2020-03-30 0.5183\n", "917 2020-03-31 0.5241\n", "918 2020-04-01 0.5142\n", "919 2020-04-02 0.5723" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 获取基金数据\n", "xa.get_daily(\"F501018\", prev=5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "我们也可以通过 get_rt 获取实时数据,通过 get_bar 获取分钟线小时线等数据,以下是一些例子" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'currency': 'USD',\n", " 'current': 51.19,\n", " 'current_ext': 51.39,\n", " 'floatshare': None,\n", " 'market': 'US',\n", " 'name': '拼多多',\n", " 'percent': 3.27,\n", " 'time': '2020-04-28 04:00:00',\n", " 'totshare': 1197626247,\n", " 'volume': 4717569}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xa.get_rt(\"PDD\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'currency': 'CNY',\n", " 'current': 0.717,\n", " 'current_ext': None,\n", " 'floatshare': None,\n", " 'market': 'CN',\n", " 'name': '南方原油LOF',\n", " 'percent': -1.38,\n", " 'time': '2020-04-28 09:30:04',\n", " 'totshare': 3180963285,\n", " 'volume': 7808665}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xa.get_rt(\"SH501018\")\n", "# 请注意第二次请求已经不需要去要雪球 token 了,因为已缓存" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Fetching url: https://markets.ft.com/data/indices/tearsheet/summary?s=INX:IOM . Inside function `get_rt_from_ft`\n" ] }, { "data": { "text/plain": [ "{'currency': 'USD',\n", " 'current': 2488.65,\n", " 'current_ext': None,\n", " 'market': None,\n", " 'name': 'S&P 500 INDEX',\n", " 'percent': -1.51}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xa.get_rt(\"FT-INX:IOM\")\n", "# 请注意 FT 的实时数据存在延迟!" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Fetching url: https://cnappapi.investing.com/currencies/usd-cnh . Inside function `get_cninvesting_rt`\n" ] }, { "data": { "text/plain": [ "{'currency': None,\n", " 'current': 7.1119,\n", " 'current_ext': None,\n", " 'market': None,\n", " 'name': 'USD/CNH - 美元 离岸人民币',\n", " 'percent': 0.26}" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xa.get_rt(\"INA-currencies/usd-cnh\")\n", "# 从 app 源获取英为实时数据" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Fetching url: https://xueqiu.com . Inside function `get_token`\n", "Fetching url: https://stock.xueqiu.com/v5/stock/quote.json?symbol=SH600000&extend=detail . Inside function `get_xueqiu_rt`\n", "Fetching url: https://hq.sinajs.cn/list=sh600000 . Inside function `get_rt_from_sina`\n" ] }, { "data": { "text/plain": [ "{'currency': 'CNY',\n", " 'current': 10.15,\n", " 'current_ext': None,\n", " 'market': 'CN',\n", " 'name': '浦发银行',\n", " 'percent': -0.49}" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xa.get_rt(\"SH600000\", double_check=True)\n", "# 获取 A 股数据,并经过新浪源的双重校验" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Fetching url: https://cn.investing.com/indices/germany-30 . Inside function `get_investing_id`\n", "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`\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dateclose
02020-04-01 18:00:009583.50
12020-04-01 19:00:009551.50
22020-04-01 20:00:009533.00
32020-04-01 21:00:009559.75
42020-04-01 22:00:009586.75
52020-04-01 23:00:009539.50
62020-04-02 15:00:009542.25
72020-04-02 16:00:009565.75
82020-04-02 17:00:009548.75
92020-04-02 18:00:009594.25
102020-04-02 19:00:009580.50
112020-04-02 20:00:009433.00
122020-04-02 21:00:009451.50
132020-04-02 22:00:009613.75
142020-04-02 23:00:009569.00
152020-04-03 15:00:009534.75
162020-04-03 16:00:009529.75
172020-04-03 17:00:009527.00
182020-04-03 18:00:009535.25
192020-04-03 19:00:009611.00
202020-04-03 20:00:009569.75
212020-04-03 21:00:009558.75
222020-04-03 22:00:009547.25
232020-04-03 23:00:009525.77
\n", "
" ], "text/plain": [ " date close\n", "0 2020-04-01 18:00:00 9583.50\n", "1 2020-04-01 19:00:00 9551.50\n", "2 2020-04-01 20:00:00 9533.00\n", "3 2020-04-01 21:00:00 9559.75\n", "4 2020-04-01 22:00:00 9586.75\n", "5 2020-04-01 23:00:00 9539.50\n", "6 2020-04-02 15:00:00 9542.25\n", "7 2020-04-02 16:00:00 9565.75\n", "8 2020-04-02 17:00:00 9548.75\n", "9 2020-04-02 18:00:00 9594.25\n", "10 2020-04-02 19:00:00 9580.50\n", "11 2020-04-02 20:00:00 9433.00\n", "12 2020-04-02 21:00:00 9451.50\n", "13 2020-04-02 22:00:00 9613.75\n", "14 2020-04-02 23:00:00 9569.00\n", "15 2020-04-03 15:00:00 9534.75\n", "16 2020-04-03 16:00:00 9529.75\n", "17 2020-04-03 17:00:00 9527.00\n", "18 2020-04-03 18:00:00 9535.25\n", "19 2020-04-03 19:00:00 9611.00\n", "20 2020-04-03 20:00:00 9569.75\n", "21 2020-04-03 21:00:00 9558.75\n", "22 2020-04-03 22:00:00 9547.25\n", "23 2020-04-03 23:00:00 9525.77" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xa.get_bar(\"indices/germany-30\", interval=3600) \n", "# 获取小时线数据" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "下面简单演示对于承载数据的 pd.DataFrame 的简单处理和可视化" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7.0995" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = xa.get_daily(\"USD/CNY\", prev=20)\n", "df[df[\"date\"]==\"2020-04-02\"].iloc[0][\"close\"]" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = xa.Compare((\"commodities/crude-oil\", \"USD\"), \"F501018\", \"F160216\", start=\"20190101\")\n", "c.v()" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
commodities/crude-oilF501018F160216
commodities/crude-oil1.0000000.8705830.934701
F5010180.8705831.0000000.952503
F1602160.9347010.9525031.000000
\n", "
" ], "text/plain": [ " commodities/crude-oil F501018 F160216\n", "commodities/crude-oil 1.000000 0.870583 0.934701\n", "F501018 0.870583 1.000000 0.952503\n", "F160216 0.934701 0.952503 1.000000" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.corr() # 打印关联系数" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 使用聚宽数据" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 使用聚宽数据需要激活数据源,如果之前没有激活的话\n", "user = \"jquser\"\n", "passw = \"jqpassw\"\n", "xa.provider.set_jq_data(user, passw)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idstat_monthretail_sinretail_accretail_sin_yoyretail_acc_yoyscale_retail_sinscale_retail_accscale_retail_sin_yoyscale_retail_acc_yoy...hotel_scale_retail_acc_yoysale_retail_sinsale_retail_accsale_retail_sin_yoysale_retail_acc_yoysale_scale_retail_sinsale_scale_retail_accsale_scale_retail_sin_yoysale_scale_retail_acc_yoydate
14042018-03-0129193.600090275.400010.10009.800011831.800034941.00009.00008.5000...8.000026095.000080563.900010.00009.80011112.500032754.70008.90008.60002018-03-01
24052018-04-0128541.9000118817.30009.40009.700011240.600046136.90007.80008.4000...7.700025517.4000106081.30009.40009.70010540.400043247.90007.80008.40002018-04-01
34062018-05-0130359.1000149176.40008.50009.500011476.700057517.70005.50007.8000...7.100027038.4000133119.70008.40009.40010735.600053888.10005.60007.80002018-05-01
44072018-06-0130841.6000180017.90009.00009.400012448.300069937.60006.50007.5000...7.200027441.0000160560.70008.90009.30011671.300065538.20006.40007.60002018-06-01
54192018-07-0130733.7000210751.60008.80009.300011419.000081125.20005.70007.3000...7.000027390.5000187951.20008.70009.20010655.200075978.80005.70007.30002018-07-01
64202018-08-0131542.3000242293.90009.00009.300011832.200092367.70006.00007.1000...7.100028026.2000215977.40008.90009.20011041.100086460.30005.90007.10002018-08-01
74212018-09-0132005.4000274299.30009.20009.300012761.7000104792.10005.70006.9000...7.000028558.5000244535.90009.20009.20011961.600098099.30005.60006.90002018-09-01
84222018-10-0135534.4000309833.70008.60009.200012478.6000117177.50003.70006.6000...6.800031528.4000276064.30008.50009.10011630.1000109637.10003.60006.60002018-10-01
94232018-11-0135259.7000345093.40008.10009.100013678.7000130829.90002.10006.1000...6.500030734.7000306799.10008.00009.00012862.1000122473.10002.00006.10002018-11-01
104242018-12-0135893.4983380986.85228.16088.981715084.0071145311.28732.43695.7055...6.428331471.9353338270.99988.04088.92114174.7441136074.92832.24575.65752018-12-01
114252019-02-010.000066064.00000.00008.20000.000023096.00000.00003.5000...8.10000.000058813.00000.00008.0000.000021580.00000.00003.20002019-02-01
124262019-03-0131725.700097789.70008.70008.300011952.500035078.20005.10004.1000...7.900028332.800087145.70008.60008.20011226.800032852.40005.00003.80002019-03-01
134272019-04-0130586.1000128375.80007.20008.000011120.100046211.90002.00003.5000...7.100027305.3000114451.00007.00007.90010428.800043291.30001.80003.30002019-04-01
144282019-05-0132955.7000161331.60008.60008.100011693.800057924.00005.10003.9000...7.100029324.4000143775.40008.50008.00010939.000054222.20005.00003.60002019-05-01
154292019-06-0133878.1000195209.70009.80008.400013163.400071124.20009.70004.9000...7.200030154.8000173930.20009.90008.30012374.700066627.10009.80004.70002019-06-01
164312019-07-0133073.3000228282.90007.60008.300011412.100082446.20002.90004.6000...7.200029415.2000203345.40007.40008.20010634.800077208.10002.60004.40002019-07-01
174322019-08-0133896.3000262179.30007.50008.200011772.100093880.90002.00004.3000...7.300030039.2000233384.60007.20008.10010957.400087832.60001.60004.10002019-08-01
184342019-09-0134494.9000296674.20007.80008.200012835.4000106691.90003.10004.1000...7.300030724.7000264109.30007.60008.00012020.900099829.80002.90003.90002019-09-01
194352019-10-0138104.3000334778.50007.20008.100012322.1000118918.80001.20003.8000...7.100033736.9000297846.20007.00007.90011475.9000111223.60000.90003.60002019-10-01
204362019-11-0138093.8000372872.30008.00008.000013964.7000132639.10004.40003.9000...7.200033130.1000330976.30007.80007.90013133.7000124111.00004.20003.70002019-11-01
214372019-12-0138776.7000411649.00008.00008.000015337.6000148009.90004.40003.9000...7.100033952.1000364928.30007.90007.90014423.6000138565.10004.30003.70002019-12-01
224382020-02-010.000052129.80000.0000-20.50000.000016949.80000.0000-23.4000...-39.70000.000047935.50000.0000-17.6000.000016021.60000.0000-22.20002020-02-01
\n", "

22 rows × 35 columns

\n", "
" ], "text/plain": [ " id stat_month retail_sin retail_acc retail_sin_yoy retail_acc_yoy \\\n", "1 404 2018-03-01 29193.6000 90275.4000 10.1000 9.8000 \n", "2 405 2018-04-01 28541.9000 118817.3000 9.4000 9.7000 \n", "3 406 2018-05-01 30359.1000 149176.4000 8.5000 9.5000 \n", "4 407 2018-06-01 30841.6000 180017.9000 9.0000 9.4000 \n", "5 419 2018-07-01 30733.7000 210751.6000 8.8000 9.3000 \n", "6 420 2018-08-01 31542.3000 242293.9000 9.0000 9.3000 \n", "7 421 2018-09-01 32005.4000 274299.3000 9.2000 9.3000 \n", "8 422 2018-10-01 35534.4000 309833.7000 8.6000 9.2000 \n", "9 423 2018-11-01 35259.7000 345093.4000 8.1000 9.1000 \n", "10 424 2018-12-01 35893.4983 380986.8522 8.1608 8.9817 \n", "11 425 2019-02-01 0.0000 66064.0000 0.0000 8.2000 \n", "12 426 2019-03-01 31725.7000 97789.7000 8.7000 8.3000 \n", "13 427 2019-04-01 30586.1000 128375.8000 7.2000 8.0000 \n", "14 428 2019-05-01 32955.7000 161331.6000 8.6000 8.1000 \n", "15 429 2019-06-01 33878.1000 195209.7000 9.8000 8.4000 \n", "16 431 2019-07-01 33073.3000 228282.9000 7.6000 8.3000 \n", "17 432 2019-08-01 33896.3000 262179.3000 7.5000 8.2000 \n", "18 434 2019-09-01 34494.9000 296674.2000 7.8000 8.2000 \n", "19 435 2019-10-01 38104.3000 334778.5000 7.2000 8.1000 \n", "20 436 2019-11-01 38093.8000 372872.3000 8.0000 8.0000 \n", "21 437 2019-12-01 38776.7000 411649.0000 8.0000 8.0000 \n", "22 438 2020-02-01 0.0000 52129.8000 0.0000 -20.5000 \n", "\n", " scale_retail_sin scale_retail_acc scale_retail_sin_yoy \\\n", "1 11831.8000 34941.0000 9.0000 \n", "2 11240.6000 46136.9000 7.8000 \n", "3 11476.7000 57517.7000 5.5000 \n", "4 12448.3000 69937.6000 6.5000 \n", "5 11419.0000 81125.2000 5.7000 \n", "6 11832.2000 92367.7000 6.0000 \n", "7 12761.7000 104792.1000 5.7000 \n", "8 12478.6000 117177.5000 3.7000 \n", "9 13678.7000 130829.9000 2.1000 \n", "10 15084.0071 145311.2873 2.4369 \n", "11 0.0000 23096.0000 0.0000 \n", "12 11952.5000 35078.2000 5.1000 \n", "13 11120.1000 46211.9000 2.0000 \n", "14 11693.8000 57924.0000 5.1000 \n", "15 13163.4000 71124.2000 9.7000 \n", "16 11412.1000 82446.2000 2.9000 \n", "17 11772.1000 93880.9000 2.0000 \n", "18 12835.4000 106691.9000 3.1000 \n", "19 12322.1000 118918.8000 1.2000 \n", "20 13964.7000 132639.1000 4.4000 \n", "21 15337.6000 148009.9000 4.4000 \n", "22 0.0000 16949.8000 0.0000 \n", "\n", " scale_retail_acc_yoy ... hotel_scale_retail_acc_yoy sale_retail_sin \\\n", "1 8.5000 ... 8.0000 26095.0000 \n", "2 8.4000 ... 7.7000 25517.4000 \n", "3 7.8000 ... 7.1000 27038.4000 \n", "4 7.5000 ... 7.2000 27441.0000 \n", "5 7.3000 ... 7.0000 27390.5000 \n", "6 7.1000 ... 7.1000 28026.2000 \n", "7 6.9000 ... 7.0000 28558.5000 \n", "8 6.6000 ... 6.8000 31528.4000 \n", "9 6.1000 ... 6.5000 30734.7000 \n", "10 5.7055 ... 6.4283 31471.9353 \n", "11 3.5000 ... 8.1000 0.0000 \n", "12 4.1000 ... 7.9000 28332.8000 \n", "13 3.5000 ... 7.1000 27305.3000 \n", "14 3.9000 ... 7.1000 29324.4000 \n", "15 4.9000 ... 7.2000 30154.8000 \n", "16 4.6000 ... 7.2000 29415.2000 \n", "17 4.3000 ... 7.3000 30039.2000 \n", "18 4.1000 ... 7.3000 30724.7000 \n", "19 3.8000 ... 7.1000 33736.9000 \n", "20 3.9000 ... 7.2000 33130.1000 \n", "21 3.9000 ... 7.1000 33952.1000 \n", "22 -23.4000 ... -39.7000 0.0000 \n", "\n", " sale_retail_acc sale_retail_sin_yoy sale_retail_acc_yoy \\\n", "1 80563.9000 10.0000 9.800 \n", "2 106081.3000 9.4000 9.700 \n", "3 133119.7000 8.4000 9.400 \n", "4 160560.7000 8.9000 9.300 \n", "5 187951.2000 8.7000 9.200 \n", "6 215977.4000 8.9000 9.200 \n", "7 244535.9000 9.2000 9.200 \n", "8 276064.3000 8.5000 9.100 \n", "9 306799.1000 8.0000 9.000 \n", "10 338270.9998 8.0408 8.921 \n", "11 58813.0000 0.0000 8.000 \n", "12 87145.7000 8.6000 8.200 \n", "13 114451.0000 7.0000 7.900 \n", "14 143775.4000 8.5000 8.000 \n", "15 173930.2000 9.9000 8.300 \n", "16 203345.4000 7.4000 8.200 \n", "17 233384.6000 7.2000 8.100 \n", "18 264109.3000 7.6000 8.000 \n", "19 297846.2000 7.0000 7.900 \n", "20 330976.3000 7.8000 7.900 \n", "21 364928.3000 7.9000 7.900 \n", "22 47935.5000 0.0000 -17.600 \n", "\n", " sale_scale_retail_sin sale_scale_retail_acc sale_scale_retail_sin_yoy \\\n", "1 11112.5000 32754.7000 8.9000 \n", "2 10540.4000 43247.9000 7.8000 \n", "3 10735.6000 53888.1000 5.6000 \n", "4 11671.3000 65538.2000 6.4000 \n", "5 10655.2000 75978.8000 5.7000 \n", "6 11041.1000 86460.3000 5.9000 \n", "7 11961.6000 98099.3000 5.6000 \n", "8 11630.1000 109637.1000 3.6000 \n", "9 12862.1000 122473.1000 2.0000 \n", "10 14174.7441 136074.9283 2.2457 \n", "11 0.0000 21580.0000 0.0000 \n", "12 11226.8000 32852.4000 5.0000 \n", "13 10428.8000 43291.3000 1.8000 \n", "14 10939.0000 54222.2000 5.0000 \n", "15 12374.7000 66627.1000 9.8000 \n", "16 10634.8000 77208.1000 2.6000 \n", "17 10957.4000 87832.6000 1.6000 \n", "18 12020.9000 99829.8000 2.9000 \n", "19 11475.9000 111223.6000 0.9000 \n", "20 13133.7000 124111.0000 4.2000 \n", "21 14423.6000 138565.1000 4.3000 \n", "22 0.0000 16021.6000 0.0000 \n", "\n", " sale_scale_retail_acc_yoy date \n", "1 8.6000 2018-03-01 \n", "2 8.4000 2018-04-01 \n", "3 7.8000 2018-05-01 \n", "4 7.6000 2018-06-01 \n", "5 7.3000 2018-07-01 \n", "6 7.1000 2018-08-01 \n", "7 6.9000 2018-09-01 \n", "8 6.6000 2018-10-01 \n", "9 6.1000 2018-11-01 \n", "10 5.6575 2018-12-01 \n", "11 3.2000 2019-02-01 \n", "12 3.8000 2019-03-01 \n", "13 3.3000 2019-04-01 \n", "14 3.6000 2019-05-01 \n", "15 4.7000 2019-06-01 \n", "16 4.4000 2019-07-01 \n", "17 4.1000 2019-08-01 \n", "18 3.9000 2019-09-01 \n", "19 3.6000 2019-10-01 \n", "20 3.7000 2019-11-01 \n", "21 3.7000 2019-12-01 \n", "22 -22.2000 2020-02-01 \n", "\n", "[22 rows x 35 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = xa.get_daily(\"mcm-MAC_SALE_RETAIL_MONTH\", start=\"20180301\")\n", "# 获取宏观数据,商品零售总额\n", "df" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support. ' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
');\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " // select the cell after this one\n", " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", " IPython.notebook.select(index + 1);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = xa.get_daily(\"mcd-MAC_LEND_RATE\", start=\"2018-01-01\")\n", "df = df[(df[\"currency_name\"]==\"人民币\") & (df[\"market_id\"] == 5) & (df[\"term_id\"]==20)]\n", "%matplotlib notebook\n", "df.plot(x=\"date\", y=\"interest_rate\")" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
codedatedisplay_nameweight
1950600000.XSHG2020-04-01浦发银行1.812
1951600009.XSHG2020-04-01上海机场1.668
1952600016.XSHG2020-04-01民生银行1.953
1953600028.XSHG2020-04-01中国石化1.901
1954600030.XSHG2020-04-01中信证券2.290
1955600031.XSHG2020-04-01三一重工2.363
1956600036.XSHG2020-04-01招商银行1.891
1957600050.XSHG2020-04-01中国联通1.959
1958600104.XSHG2020-04-01上汽集团1.920
1959600196.XSHG2020-04-01复星医药2.779
1960600276.XSHG2020-04-01恒瑞医药2.338
1961600309.XSHG2020-04-01万华化学1.728
1962600340.XSHG2020-04-01华夏幸福1.615
1963600519.XSHG2020-04-01贵州茅台2.037
1964600547.XSHG2020-04-01山东黄金2.345
1965600585.XSHG2020-04-01海螺水泥2.429
1966600690.XSHG2020-04-01海尔智家1.812
1967600703.XSHG2020-04-01三安光电2.338
1968600837.XSHG2020-04-01海通证券1.923
1969600887.XSHG2020-04-01伊利股份2.056
1970601988.XSHG2020-04-01中国银行2.042
1971600048.XSHG2020-04-01保利地产2.033
1972601111.XSHG2020-04-01中国国航1.614
1973601398.XSHG2020-04-01工商银行1.906
1974601628.XSHG2020-04-01中国人寿1.684
1975601166.XSHG2020-04-01兴业银行1.787
1976601318.XSHG2020-04-01中国平安1.757
1977601328.XSHG2020-04-01交通银行1.993
1978601939.XSHG2020-04-01建设银行1.899
1979601088.XSHG2020-04-01中国神华1.972
1980601857.XSHG2020-04-01中国石油1.737
1981601390.XSHG2020-04-01中国中铁2.005
1982601601.XSHG2020-04-01中国太保1.722
1983601186.XSHG2020-04-01中国铁建2.135
1984601668.XSHG2020-04-01中国建筑2.140
1985601766.XSHG2020-04-01中国中车2.005
1986601888.XSHG2020-04-01中国国旅1.673
1987601989.XSHG2020-04-01中国重工1.703
1988601688.XSHG2020-04-01华泰证券2.040
1989601012.XSHG2020-04-01隆基股份2.092
1990601288.XSHG2020-04-01农业银行1.983
1991601818.XSHG2020-04-01光大银行1.839
1992601336.XSHG2020-04-01新华保险1.846
1993603993.XSHG2020-04-01洛阳钼业1.971
1994601211.XSHG2020-04-01国泰君安1.969
1995601066.XSHG2020-04-01中信建投2.904
1996601236.XSHG2020-04-01红塔证券2.694
1997603259.XSHG2020-04-01药明康德2.124
1998601319.XSHG2020-04-01中国人保1.974
1999601138.XSHG2020-04-01工业富联1.601
\n", "
" ], "text/plain": [ " code date display_name weight\n", "1950 600000.XSHG 2020-04-01 浦发银行 1.812\n", "1951 600009.XSHG 2020-04-01 上海机场 1.668\n", "1952 600016.XSHG 2020-04-01 民生银行 1.953\n", "1953 600028.XSHG 2020-04-01 中国石化 1.901\n", "1954 600030.XSHG 2020-04-01 中信证券 2.290\n", "1955 600031.XSHG 2020-04-01 三一重工 2.363\n", "1956 600036.XSHG 2020-04-01 招商银行 1.891\n", "1957 600050.XSHG 2020-04-01 中国联通 1.959\n", "1958 600104.XSHG 2020-04-01 上汽集团 1.920\n", "1959 600196.XSHG 2020-04-01 复星医药 2.779\n", "1960 600276.XSHG 2020-04-01 恒瑞医药 2.338\n", "1961 600309.XSHG 2020-04-01 万华化学 1.728\n", "1962 600340.XSHG 2020-04-01 华夏幸福 1.615\n", "1963 600519.XSHG 2020-04-01 贵州茅台 2.037\n", "1964 600547.XSHG 2020-04-01 山东黄金 2.345\n", "1965 600585.XSHG 2020-04-01 海螺水泥 2.429\n", "1966 600690.XSHG 2020-04-01 海尔智家 1.812\n", "1967 600703.XSHG 2020-04-01 三安光电 2.338\n", "1968 600837.XSHG 2020-04-01 海通证券 1.923\n", "1969 600887.XSHG 2020-04-01 伊利股份 2.056\n", "1970 601988.XSHG 2020-04-01 中国银行 2.042\n", "1971 600048.XSHG 2020-04-01 保利地产 2.033\n", "1972 601111.XSHG 2020-04-01 中国国航 1.614\n", "1973 601398.XSHG 2020-04-01 工商银行 1.906\n", "1974 601628.XSHG 2020-04-01 中国人寿 1.684\n", "1975 601166.XSHG 2020-04-01 兴业银行 1.787\n", "1976 601318.XSHG 2020-04-01 中国平安 1.757\n", "1977 601328.XSHG 2020-04-01 交通银行 1.993\n", "1978 601939.XSHG 2020-04-01 建设银行 1.899\n", "1979 601088.XSHG 2020-04-01 中国神华 1.972\n", "1980 601857.XSHG 2020-04-01 中国石油 1.737\n", "1981 601390.XSHG 2020-04-01 中国中铁 2.005\n", "1982 601601.XSHG 2020-04-01 中国太保 1.722\n", "1983 601186.XSHG 2020-04-01 中国铁建 2.135\n", "1984 601668.XSHG 2020-04-01 中国建筑 2.140\n", "1985 601766.XSHG 2020-04-01 中国中车 2.005\n", "1986 601888.XSHG 2020-04-01 中国国旅 1.673\n", "1987 601989.XSHG 2020-04-01 中国重工 1.703\n", "1988 601688.XSHG 2020-04-01 华泰证券 2.040\n", "1989 601012.XSHG 2020-04-01 隆基股份 2.092\n", "1990 601288.XSHG 2020-04-01 农业银行 1.983\n", "1991 601818.XSHG 2020-04-01 光大银行 1.839\n", "1992 601336.XSHG 2020-04-01 新华保险 1.846\n", "1993 603993.XSHG 2020-04-01 洛阳钼业 1.971\n", "1994 601211.XSHG 2020-04-01 国泰君安 1.969\n", "1995 601066.XSHG 2020-04-01 中信建投 2.904\n", "1996 601236.XSHG 2020-04-01 红塔证券 2.694\n", "1997 603259.XSHG 2020-04-01 药明康德 2.124\n", "1998 601319.XSHG 2020-04-01 中国人保 1.974\n", "1999 601138.XSHG 2020-04-01 工业富联 1.601" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 指数成分股和权重\n", "xa.get_daily(\"iw-SH000050\", start=\"20200331\", end=\"20200405\")" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support. ' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
');\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " // select the cell after this one\n", " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", " IPython.notebook.select(index + 1);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h.v(\"pb\")" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "# 指数成份股总盈利和总净资产\n", "df = xa.get_daily(\"teb-SH000050\", start=\"20180101\")" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support. ' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
');\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " // select the cell after this one\n", " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", " IPython.notebook.select(index + 1);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.plot(x=\"date\", y=\"b\")" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support. ' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
');\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('