如何使用Python下载股价数据? [英] How can I download stock price data with Python?

查看:286
本文介绍了如何使用Python下载股价数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了pandas-datareader,但是我想知道是否还有其他选择.

I have installed pandas-datareader but I'm wondering if there are alternatives.

到目前为止,我正在使用它:

So far, I'm using this:

import pandas_datareader.data as web
start_date = '2018-01-01'
end_date = '2018-06-08'
panel_data = web.DataReader('SPY', 'yahoo', start_date, end_date)

推荐答案

Yahoo Finance 是获取股票数据的免费资源之一.您可以使用pandas datareader或yfinance库获取数据.从yfinance库获取数据的方法如下所示.

Yahoo Finance is one of the free sources to get stock data. You can get the data either using pandas datareader or can get using yfinance library. The method to get data from yfinance library is shown below.

import yfinance as yf
# Get the data of the stock AAPL
data = yf.download('AAPL','2016-01-01','2019-08-01')

Wiki是 quandl 上免费的免费资源之一,可获取3000多种美国股票的数据.这是社区维护的数据.最近,它已停止维护,但是,它是一个很好的免费资源,可以回溯测试您的策略. 要获取数据,您需要从quandl获取免费的API密钥,然后将以下代码中的替换为您的API密钥.

Wiki is one of the free source available on quandl to get the data for the 3000+ US equities. This is a community maintained data. Recently it is stopped being maintained but however, it is a good free source to backtest your strategies. To get the data, you need to get the free API key from quandl and replace the in the below code with your API key.

# Import the quandl package
import quandl
# Get the data from quandl
data = quandl.get("WIKI/KO", start_date="2016-01-01", end_date="2018-01-01", 
    api_key=<Your_API_Key>)

注意: Quandl需要NumPy(v1.8或更高版本)和熊猫(v0.14或更高版本)才能工作. 要获取您的API密钥,请注册一个免费的Quandl帐户.然后,您可以在Quandl帐户设置页面上找到您的API密钥.

Note: Quandl requires NumPy (v1.8 or above) and pandas (v0.14 or above) to work. To get your API key, sign up for a free Quandl account. Then, you can find your API key on Quandl account settings page.

这篇关于如何使用Python下载股价数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆