tushare是一个免费,开源的python财经数据接口包.主要实现对股票等金融数据从数据采集、清洗加工到数据存储的过程,能够为金融分析人员提供快速、整洁、和多样的便于分析的数据,为他们在数据获取方面极大地减轻工作量,使他们更加专注于策略和模型的研究与实现上。考虑到Pythonpandas包在金融量化分析中体现出的优势,TuShare返回的绝大部分的数据格式都是pandasDataFrame类型,非常便于用pandas/NumPy/Matplotlib进行数据分析和可视化。当然,如果您习惯了用Excel或者关系型数据库做分析,您也可以通过TuShare的数据存储功能,将数据全部保存到本地后进行分析。
tushare官网: http://tushare.waditu.com/
sudo pip install pandas
sudo pip install tushare --upgrade
sudo pip install matplotlib
>>>import tushare as ts
>>>df = ts.realtime_boxoffice()
>>> print(df)
BoxOffice Irank MovieName boxPer movieDay sumBoxOffice \
0 3084.86 1 速度与激情8 85.43 6 164407.29
1 285.19 2 大话西游之大圣娶亲 7.90 7 14171.68
2 44.09 3 攻壳机动队 1.22 13 19823.22
3 42.59 4 金刚:骷髅岛 1.18 27 115670.19
4 40.61 5 指甲刀人魔 1.12 6 417.69
5 34.21 6 嫌疑人X的献身 0.95 20 39946.08
6 12.34 7 非凡任务 0.34 20 15580.31
7 9.70 8 爱情冻住了 0.27 6 51.44
8 7.33 9 一念无明 0.20 13 852.84
9 5.42 10 怨灵宿舍之人偶老师 0.15 6 60.21
10 44.75 11 其它 1.00 0 0.00
time
0 2017-04-19 13:38:54
1 2017-04-19 13:38:54
2 2017-04-19 13:38:54
3 2017-04-19 13:38:54
4 2017-04-19 13:38:54
5 2017-04-19 13:38:54
6 2017-04-19 13:38:54
7 2017-04-19 13:38:54
8 2017-04-19 13:38:54
9 2017-04-19 13:38:54
10 2017-04-19 13:38:54
>>> dd = ts.day_cinema()
[Getting data:]##########>>> dd.head(10)
Attendance AvgPeople CinemaName RowNum TodayAudienceCount TodayBox \
0 42.835693 73.15 广州万达影城白云店 1 3804 256927.41
1 31.402390 55.37 广州飞扬影城(正佳分店) 2 3267 204949.84
2 38.515005 67.29 北京UME国际影城双井店 3 3768 187610.65
3 33.904140 54.52 深圳卢米埃华北九方IMAX影城 4 3053 181245.99
4 29.611678 46.59 深圳橙天嘉禾影城 5 3401 177377.51
5 28.176253 37.68 首都华融电影院 6 2788 175088.73
6 30.507503 61.93 北京UME华星国际影城 7 2663 173514.41
7 28.851222 50.30 上海百丽宫影城(环贸iapm店) 8 1861 172371.61
8 46.609085 72.85 中影国际影城珠海华发2店 9 4371 165827.00
9 27.686567 46.38 兰州城关万达影城 10 2597 165515.46
TodayShowCount price
0 52 67.54
1 59 62.73
2 56 49.79
3 56 59.37
4 73 52.15
5 74 62.80
6 43 65.16
7 37 92.62
8 60 37.94
9 56 63.73
>>> wd = ts.get_hist_data('603189')
>>> wd
open high close low volume price_change p_change \
date
2017-04-18 25.88 26.49 25.57 25.51 13207.93 -0.31 -1.20
2017-04-17 26.51 26.52 25.88 25.00 22645.00 -1.36 -4.99
2017-04-14 27.71 27.88 27.24 27.10 10853.77 -0.48 -1.73
2017-04-13 27.33 28.12 27.72 27.32 13186.33 0.21 0.76
2017-04-12 28.20 28.20 27.51 27.45 16166.18 -0.63 -2.24
2017-04-11 27.00 28.20 28.14 26.90 26185.44 0.67 2.44
2017-04-10 30.00 30.00 27.47 27.38 43242.78 -2.75 -9.10
2017-04-07 31.05 31.05 30.22 30.20 17423.72 -0.74 -2.39
2017-04-06 30.70 31.47 30.96 30.45 21612.98 0.35 1.14
2017-04-05 29.92 30.75 30.61 29.87 20281.81 0.74 2.48
2017-03-31 30.30 30.69 29.87 29.46 23217.96 -0.12 -0.40
2017-03-30 31.28 31.28 29.99 29.88 38244.38 -1.48 -4.70
2017-03-29 34.25 34.56 31.47 31.32 60544.07 -3.14 -9.07
2017-03-28 34.68 35.07 34.61 34.19 26849.00 -0.01 -0.03
2017-03-27 35.50 35.53 34.62 34.20 33922.15 -0.67 -1.90
2017-03-24 34.93 35.77 35.29 34.92 34093.48 0.10 0.28
2017-03-23 35.73 35.85 35.19 34.87 48042.30 -0.54 -1.51
2017-03-22 35.60 35.85 35.73 34.81 52934.01 -0.22 -0.61
2017-03-21 36.35 36.36 35.95 35.58 57436.07 -0.36 -0.99
2017-03-20 34.02 36.70 36.31 34.02 89782.92 2.30 6.76
2017-03-17 35.30 35.74 34.01 33.96 55994.45 -1.29 -3.65
2017-03-16 34.89 35.95 35.30 34.89 63739.58 0.39 1.12
2017-03-15 35.68 35.82 34.91 34.75 67849.37 -1.15 -3.19
2017-03-14 36.50 37.03 36.06 36.00 86213.58 -0.92 -2.49
2017-03-13 36.12 37.45 36.98 35.15 123223.48 0.37 1.01
2017-03-10 35.02 37.70 36.61 35.00 176359.47 2.25 6.55
2017-03-09 31.30 34.36 34.36 31.30 109867.26 3.12 9.99
2017-03-08 31.45 31.60 31.24 31.00 30298.17 -0.35 -1.11
2017-03-07 31.20 31.66 31.59 30.81 41062.97 0.49 1.58
2017-03-06 30.20 31.23 31.10 30.20 30952.68 0.92 3.05
ma5 ma10 ma20 v_ma5 v_ma10 v_ma20
date
2017-04-18 26.784 28.132 31.018 15211.84 20480.59 33493.61
2017-04-17 27.298 28.562 31.440 17807.34 21481.60 35632.94
2017-04-14 27.616 28.973 31.911 21926.90 23041.54 37687.67
2017-04-13 28.212 29.396 32.294 23240.89 28010.56 40537.45
2017-04-12 28.860 30.085 32.711 24926.22 29376.83 44188.81
2017-04-11 29.480 30.796 33.185 25749.35 31152.43 49541.68
2017-04-10 29.826 31.511 33.608 25155.85 31943.23 57050.38
2017-04-07 30.330 32.283 33.953 24156.17 32423.19 60381.60
2017-04-06 30.580 32.834 34.004 32780.24 35974.21 61025.32
2017-04-05 31.310 33.333 34.035 33827.44 39556.52 61997.82
2017-03-31 32.112 33.903 34.060 36555.51 46506.63 62531.37
2017-03-30 33.196 34.317 34.075 38730.62 49784.28 62344.33
2017-03-29 34.236 34.848 34.102 40690.20 52333.80 61543.64
2017-03-28 35.088 35.192 34.070 39168.19 53064.33 59662.65
2017-03-27 35.356 35.337 33.897 45285.60 59000.79 59400.45
2017-03-24 35.694 35.573 33.700 56457.76 67930.92 58913.86
2017-03-23 35.438 35.705 33.488 60837.95 82157.52 58757.67
2017-03-22 35.460 35.622 33.242 63977.41 88340.02 57718.66
2017-03-21 35.296 35.173 32.979 66960.48 86076.44 56689.90
2017-03-20 35.318 34.737 32.741 72715.98 84439.13 54992.35
2017-03-17 35.452 34.216 32.473 79404.09 78556.10 51973.71
2017-03-16 35.972 33.833 32.301 103477.10 74904.39 50391.57
2017-03-15 35.784 33.356 32.062 112702.63 70753.48 48208.76
2017-03-14 35.050 32.947 31.859 105192.39 66260.98 46612.00
2017-03-13 34.156 32.457 31.597 96162.27 59800.10 43209.39
2017-03-10 32.980 31.827 31.288 77708.11 49896.79 38167.44
2017-03-09 31.694 31.271 30.969 46331.68 35357.81 30466.13
2017-03-08 30.928 30.862 30.797 28804.32 27097.29 26486.42
2017-03-07 30.844 30.784 30.773 27329.56 27303.36 26268.52
2017-03-06 30.758 30.745 30.698 23437.93 25545.57 25403.08
... ... ... ... ... ... ...
>>> wd = ts.get_realtime_quotes('603189')
>>> wd
name open pre_close price high low bid ask volume \
0 网达软件 25.150 25.570 25.830 25.990 25.110 25.830 25.850 1157563
amount ... a2_p a3_v a3_p a4_v a4_p a5_v a5_p \
0 29538933.000 ... 25.860 15 25.870 5 25.880 20 25.890
date time code
0 2017-04-19 13:55:39 603189
[1 rows x 33 columns]
>>> import pandas as pd
>>> import matplotlib
>>> fig = matplotlib.pyplot.gc
matplotlib.pyplot.gca( matplotlib.pyplot.gcf( matplotlib.pyplot.gci(
>>> fig = matplotlib.pyplot.gcf()
>>> df.plot()
>>> fig.savefig('/home/zy***/test.png')