python读取股票数据_如何利用程序(如python) 从新浪财经或者雅虎财经获取到所有A股数据(历史日线数据,实时股票数据)?...

news/2024/11/30 7:44:25/

用Python内置的Yahoo金融接口两行代码即可挖掘出股票交易数据。再用matplotlib 绘制出图表即可。

示例:1、获取苹果20141/1至2015/8/20的股票数据。

In [27]: import pandas.io.data as web

In [28]: web.get_data_yahoo('AAPL','1/1/2014','20/8/2015')

Out[29]:

Open High Low Close Volume \

Date

2014-01-02 555.680008 557.029945 552.020004 553.129990 58671200

2014-01-03 552.860023 553.699989 540.430046 540.980019 98116900

2014-01-06 537.450005 546.800018 533.599983 543.930046 103152700

2014-01-07 544.320015 545.960052 537.919975 540.039970 79302300

2014-01-08 538.810036 545.559990 538.689980 543.459969 64632400

2014-01-09 546.800018 546.860046 535.349983 536.519997 69787200

2014-01-10 539.829979 540.799988 531.110046 532.940048 76244000

2014-01-13 529.910019 542.500000 529.880005 535.730019 94623200

2014-01-14 538.220009 546.730003 537.659996 546.389969 83140400

2014-01-15 553.520012 560.200005 551.659996 557.360046 97909700

2014-01-16 554.900017 556.850021 551.680023 554.250015 57319500

2014-01-17 551.480019 552.069992 539.899994 540.669998 106684900

2014-01-21 540.990005 550.070000 540.420006 549.069977 82131700

2014-01-22 550.910019 557.290031 547.809975 551.509979 94996300

2014-01-23 549.940010 556.500000 544.810013 556.180046 100809800

2014-01-24 554.000023 555.620033 544.749985 546.070015 107338700

2014-01-27 550.070000 554.799988 545.750008 550.500023 138719700

2014-01-28 508.760002 514.999985 502.070023 506.499977 266380800

2014-01-29 503.950012 507.370010 498.620010 500.749992 125702500

2014-01-30 502.539993 506.499977 496.699966 499.779984 169625400

2014-01-31 495.179985 501.529984 493.549988 500.600029 116199300

2014-02-03 502.610008 507.730019 499.299973 501.529984 100366000

2014-02-04 505.850029 509.459991 502.760025 508.790016 94170300

2014-02-05 506.559952 515.279991 506.249985 512.589996 82086200

2014-02-06 510.059952 513.499977 507.810020 512.509995 64441300

2014-02-07 521.379997 522.930046 517.380013 519.679985 92570100

2014-02-10 518.660042 531.990013 518.000000 528.989998 86389800

2014-02-11 530.610008 537.749985 529.500023 535.959984 70564200

2014-02-12 536.949966 539.560013 533.239975 535.919983 77025200

2014-02-13 534.659981 544.849960 534.200050 544.429977 76849500

... ... ... ... ... ...

2015-07-09 123.849998 124.059998 119.220001 120.070000 78595000

2015-07-10 121.940002 123.849998 121.209999 123.279999 61354500

2015-07-13 125.029999 125.760002 124.320000 125.660004 41440500

2015-07-14 126.040001 126.370003 125.040001 125.610001 31768100

2015-07-15 125.720001 127.150002 125.580002 126.820000 33649200

2015-07-16 127.739998 128.570007 127.349998 128.509995 36222400

2015-07-17 129.080002 129.619995 128.309998 129.619995 46164700

2015-07-20 130.970001 132.970001 130.699997 132.070007 58900200

2015-07-21 132.850006 132.919998 130.320007 130.750000 76756400

2015-07-22 121.989998 125.500000 121.989998 125.220001 115450600

2015-07-23 126.199997 127.089996 125.059998 125.160004 50999500

2015-07-24 125.320000 125.739998 123.900002 124.500000 42162300

2015-07-27 123.089996 123.610001 122.120003 122.769997 44455500

2015-07-28 123.379997 123.910004 122.550003 123.379997 33618100

2015-07-29 123.150002 123.500000 122.269997 122.989998 37011700

2015-07-30 122.320000 122.570000 121.709999 122.370003 33628300

2015-07-31 122.599998 122.639999 120.910004 121.300003 42885000

2015-08-03 121.500000 122.570000 117.519997 118.440002 69976000

2015-08-04 117.419998 117.699997 113.250000 114.639999 124138600

2015-08-05 112.949997 117.440002 112.099998 115.400002 99312600

2015-08-06 115.970001 116.500000 114.120003 115.129997 52903000

2015-08-07 114.580002 116.250000 114.500000 115.519997 38421400

2015-08-10 116.529999 119.989998 116.529999 119.720001 54538500

2015-08-11 117.809998 118.180000 113.330002 113.489998 95711900

2015-08-12 112.529999 115.419998 109.629997 115.239998 101217500

2015-08-13 116.040001 116.400002 114.540001 115.150002 48335500

2015-08-14 114.320000 116.309998 114.010002 115.959999 42693200

2015-08-17 116.040001 117.650002 115.500000 117.160004 40702200

2015-08-18 116.430000 117.440002 116.010002 116.500000 34461400

2015-08-19 116.099998 116.519997 114.680000 115.010002 47445700

Adj Close

Date

2014-01-02 76.419139

2014-01-03 74.740527

2014-01-06 75.148096

2014-01-07 74.610653

2014-01-08 75.083151

2014-01-09 74.124341

2014-01-10 73.629744

2014-01-13 74.015200

2014-01-14 75.487953

2014-01-15 77.003553

2014-01-16 76.573879

2014-01-17 74.697696

2014-01-21 75.858217

2014-01-22 76.195322

2014-01-23 76.840527

2014-01-24 75.443749

2014-01-27 76.055789

2014-01-28 69.976846

2014-01-29 69.182442

2014-01-30 69.048427

2014-01-31 69.161723

2014-02-03 69.290203

2014-02-04 70.293232

2014-02-05 70.818229

2014-02-06 71.231011

2014-02-07 72.227530

2014-02-10 73.521479

2014-02-11 74.490200

2014-02-12 74.484640

2014-02-13 75.667398

... ...

2015-07-09 119.528958

2015-07-10 122.724493

2015-07-13 125.093773

2015-07-14 125.043995

2015-07-15 126.248542

2015-07-16 127.930922

2015-07-17 129.035921

2015-07-20 131.474893

2015-07-21 130.160834

2015-07-22 124.655753

2015-07-23 124.596026

2015-07-24 123.938997

2015-07-27 122.216789

2015-07-28 122.824041

2015-07-29 122.435799

2015-07-30 121.818597

2015-07-31 120.753419

2015-08-03 117.906306

2015-08-04 114.123426

2015-08-05 114.880003

2015-08-06 115.129997

2015-08-07 115.519997

2015-08-10 119.720001

2015-08-11 113.489998

2015-08-12 115.239998

2015-08-13 115.150002

2015-08-14 115.959999

2015-08-17 117.160004

2015-08-18 116.500000

2015-08-19 115.010002

示例2、获取国内股票数据:获取国内股市的方式“股票代码”+“对应股市”。上证股票是股票代码后面加上.ss,

获取深市300481 2015年1月1日到2015年8月20的数据

In [30]: web.get_data_yahoo('300481.sz','1/1/2015','20/8/2015')

Out[30]:

Open High Low Close Volume Adj Close

Date

2015-06-30 12.06 13.15 12.06 13.15 9900 13.15

2015-07-01 14.47 14.47 14.47 14.47 2300 14.47

2015-07-02 15.92 15.92 15.92 15.92 8200 15.92

2015-07-03 17.51 17.51 17.51 17.51 54700 17.51

2015-07-06 19.26 19.26 19.26 19.26 67200 19.26

2015-07-07 21.19 21.19 20.68 21.19 5640300 21.19

2015-07-08 19.07 23.31 19.07 22.51 13515900 22.51

2015-07-09 21.39 24.76 21.39 24.76 3869900 24.76

2015-07-10 27.24 27.24 27.24 27.24 159900 27.24

2015-07-13 29.96 29.96 29.96 29.96 92700 29.96

2015-07-14 32.96 32.96 32.96 32.96 924800 32.96

2015-07-15 36.26 36.26 30.28 33.20 13567100 33.20

2015-07-16 29.88 34.50 29.88 30.30 9096400 30.30

2015-07-17 30.81 33.00 28.85 31.65 7908700 31.65

2015-07-20 31.70 32.87 29.90 30.79 5806900 30.79

2015-07-21 31.90 33.87 30.50 33.87 4762700 33.87

2015-07-22 35.87 37.15 33.94 35.20 8486600 35.20

2015-07-23 34.41 38.72 34.41 38.72 5797300 38.72

2015-07-24 42.11 42.59 39.51 41.00 10129500 41.00

2015-07-27 37.51 42.85 36.90 36.90 8947000 36.90

2015-07-28 34.68 39.63 33.21 35.81 6935200 35.81

2015-07-29 37.31 39.39 34.80 39.39 6690700 39.39

2015-07-30 39.48 43.33 38.01 41.14 10193400 41.14

2015-07-31 41.31 45.25 41.30 45.25 10755600 45.25

2015-08-03 44.00 49.78 42.18 49.78 10950900 49.78

2015-08-04 49.78 54.00 44.80 44.80 10672200 44.80

2015-08-05 41.50 48.38 40.72 45.76 8148500 45.76

2015-08-06 43.70 45.00 41.18 41.18 6212400 41.18

2015-08-07 40.69 42.06 39.91 41.18 4499400 41.18

2015-08-10 41.25 44.50 41.20 43.00 4861300 43.00

2015-08-11 43.17 45.53 42.51 44.50 4732300 44.50

2015-08-12 44.22 44.43 41.95 42.60 4077300 42.60

2015-08-13 42.18 44.05 42.01 43.24 2832800 43.24

2015-08-14 43.89 43.89 42.22 42.80 2909000 42.80

2015-08-17 42.20 42.70 38.61 38.81 3773900 38.81

2015-08-18 38.18 41.25 35.30 36.40 3568600 36.40

2015-08-19 36.38 38.00 33.36 37.28 3929200 37.28

获取 沪市 600624 2015/7/1-2015/8/20的数据

In [33]: web.get_data_yahoo('600624.ss','7/1/2015','8/20/2015')

Out[33]:

Open High Low Close Volume Adj Close

Date

2015-07-01 24.180 25.116 22.100 22.217 19662700 17.06022

2015-07-02 22.360 22.750 19.994 19.994 19521500 15.35320

2015-07-03 18.902 20.397 17.992 17.992 22558800 13.81588

2015-07-06 19.786 19.786 16.198 16.536 27319600 12.69783

2015-07-07 16.380 17.290 14.885 14.885 31718400 11.43005

2015-07-08 13.403 14.404 13.403 13.403 30602900 10.29203

2015-07-09 13.403 13.403 13.403 13.403 0 10.29203

2015-07-10 13.403 13.403 13.403 13.403 0 10.29203

2015-07-13 14.742 14.742 14.742 14.742 636400 11.32024

2015-07-14 16.211 16.211 16.211 16.211 575200 12.44827

2015-07-15 17.836 17.836 17.511 17.823 63917100 13.68611

2015-07-16 16.484 19.188 16.484 18.759 48664300 14.40485

2015-07-17 19.097 20.631 19.097 20.631 41605700 15.84235

2015-07-20 20.670 21.736 20.280 21.307 48188400 16.36144

2015-07-21 20.787 22.438 20.371 22.230 38663900 17.07020

2015-07-22 22.087 23.205 21.528 23.127 33610700 17.75900

2015-07-23 13.910 14.870 13.660 14.600 28677100 14.60000

2015-07-24 14.380 14.510 13.780 14.000 55782000 14.00000

2015-07-27 13.510 13.930 12.600 12.600 37053900 12.60000

2015-07-28 11.600 12.830 11.340 11.830 35532800 11.83000

2015-07-29 12.220 13.050 11.300 13.050 33628100 13.05000

2015-07-30 12.800 13.600 12.450 12.680 40441800 12.68000

2015-07-31 12.100 12.750 11.530 12.010 29180100 12.01000

2015-08-03 11.850 11.940 10.820 11.070 31120500 11.07000

2015-08-04 11.060 12.170 11.060 12.170 35299000 12.17000

2015-08-05 12.350 12.750 11.850 12.280 44522100 12.28000

2015-08-06 11.900 12.850 11.730 12.580 40741700 12.58000

2015-08-07 12.700 13.310 12.520 13.300 48034200 13.30000

2015-08-10 13.480 14.300 13.210 14.030 45970400 14.03000

2015-08-11 13.920 14.080 13.560 13.750 46912700 13.75000

2015-08-12 13.740 14.190 13.550 13.870 43926300 13.87000

2015-08-13 13.730 14.590 13.680 14.470 49713400 14.47000

2015-08-14 14.780 14.840 14.130 14.190 45907000 14.19000

2015-08-17 14.020 14.580 13.810 14.530 39966000 14.53000

2015-08-18 14.410 14.570 13.080 13.080 40506700 13.08000

2015-08-19 12.590 13.570 11.810 13.460 39506600 13.46000

上证股票是股票代码后面加上.ss,深证股票是股票代码后面加上.sz

上证综指代码:000001.ss,深证成指代码:399001.SZ,沪深300代码:000300.ss; 香港为 0001.hk;加拿大股指代码:cnu.to;新西兰股指代码为.nz

新加坡股指代码为.si;台湾股指代码为.tw


http://www.ppmy.cn/news/888630.html

相关文章

Android Glide加载小gif和图片比较模糊

其实Glide加载还是可以将小图片加载的非常清晰的, 可以通过Glide转换为Bitmap 利用Drawable将setFilterBitmap为true 但是这玩意解决不了GIF。在没有找到库的情况下:我直接自定义view通过 pl.droidsonroids.gif:android-gif-drawable获取时间间隔并将gif…

Nuxt.js--》解密Nuxt.js:构建优雅、高效的现代化Vue.js应用

博主今天开设Nuxt.js专栏,带您深入探索 Nuxt.js 的精髓,学习如何利用其强大功能构建出色的前端应用程序。我们将探讨其核心特点、灵活的路由系统、优化技巧以及常见问题的解决方案。无论您是想了解 Nuxt.js 的基础知识,还是希望掌握进阶技巧&…

大前端学习-Get请求和Post请求的区别

常见的HTTP请求方式有: 1、GET: 请求指定的页面信息,并返回实体主体 2、POST:向指定资源提交数据进行处理请求(例如提交表单或者上传文件) 3、HEAD:类似于Get请求,返回的响应中没有内容 4、…

C++之final关键字用法(一百六十)

简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长! 优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀 人生格言: 人生…

springboot与rabbitmq的整合【演示5种基本交换机】

前言: 👏作者简介:我是笑霸final,一名热爱技术的在校学生。 📝个人主页:个人主页1 || 笑霸final的主页2 📕系列专栏:后端专栏 📧如果文章知识点有错误的地方,…

DEVC++伪3D小游戏丧尸城市

//类型&#xff1a;开放世界/丧尸/生存 //地图大小&#xff1a;18*18 //实际大小(除去建筑)&#xff1a;318 #include<algorithm> #include<fstream> #include<iostream> #include<stdio.h> #include<cstdio> #include<iostream> #include…

手柄映射软件_生化危机3该用哪款游戏手柄?北通宙斯给你四维游戏体验

4月3日&#xff0c;生化危机3&#xff1a;重制版重磅上线&#xff0c;不少玩家提出&#xff0c;此作十分适合手柄操作&#xff0c;通过一款好手柄&#xff0c;体验可以达到前所未有的高度。然而,目前手柄市场品种繁多,质量也参差不齐&#xff0c;稍一不慎便会花钱买教训。那么怎…

自创文字小游戏《人类末日·丧尸危机》

这个游戏有很多坑哦&#xff0c;其他就没什么要注意的啦。 你不要以为你以为的就是对的&#xff01; 有些关卡不能通关纯属运气&#xff01;&#xff01;&#xff01;最多10次就可以通关啦&#xff01;&#xff01;&#xff01; 代码在哪里&#xff1f; #include <bits/…