股票行情数据下载渠道汇总

参考文章

1. https://www.yahoo.com/

# 读取标普500
import pandas_datareader.data as pdr
sp500 = pdr.DataReader(name=’^GSPC’,data_source=’yahoo’,start=’1/1/2020′,end=’2/26/2020)
# 查看数据前5行
sp500.head()
# 输出数据
sp500.to_csv(‘sp500.csv’)

2. http://tushare.org/

import tushare as ts

# 读取中国平安(601318)数据
zgpa = ts.get_hist_data(‘601318′, start=’2019-01-01′, end=’2019-02-20’)
# 查看数据前5行
zgpa.head()
# 输出数据
zgpa.to_csv(‘zgpa.csv’)

3. http://baostock.com/baostock/index.php

import pandas as pd
import baostock as bs

lg = bs.login(user_id=”anonymous”, password=”123456″) # 无需注册,直接输入此行代码即可

# 读取浦发银行数据(600000):frequency=”d”/’w’/’m’(日/周/月)
fields =”date,code,open,high,low,close,preclose,volume,amount,adjustflag,turn,tradestatus,pctChg,\
peTTM,pbMRQ,psTTM,pcfNcfTTM,isST”
rs = bs.query_history_k_data(“sh.600000″,fields,start_date=’2019-01-01′, end_date=’2019-02-20′, frequency=”d”, adjustflag=”3″)
data_list = []
while rs.next():
data_list.append(rs.get_row_data())
pfyh = pd.DataFrame(data_list, columns=rs.fields)
# 查看数据前5行
pfyh.head()
# 输出数据
pfyh.to_csv(‘pfyh.csv’)

Leave a Reply

Your email address will not be published.