开箱雅虎金融历史价格
unpacking yahoo finance historical pice
使用我下载的yahoo finance,Apple的历史数据。我正在使用来自 https://pypi.org/project/yahoofinancials/
的信息
from yahoofinancials import YahooFinancials
ticker = 'AAPL'
yahoo_financials = YahooFinancials(ticker)
据此我可以使用以下方法获取每周数据:
historical_price = yahoo_financials.get_historical_price_data('2020-01-05', '2021-01-05', 'weekly')
这很好用。但是我正在努力将其解压缩为 pandas。有几本词典和词典列表让我难过。
当前输出为
AAPL
currency USD
eventsData {}
firstTradeDate {'formatted_date': '1980-12-12', 'date': 34547...
instrumentType EQUITY
prices [{'date': 1609736400, 'high': 133.610000610351...
timeZone {'gmtOffset': -18000}
我的问题是将上述内容解压到可用数据帧中的最佳方法是什么?
我建议改用 yfinance
,它也是基于雅虎的:
!pip install yfinance
import yfinance
yfinance.download('AAPL', start='2019-01-01', end='2020-12-31')
这输出:
Open High ... Adj Close Volume
Date ...
2019-01-02 38.722500 39.712502 ... 38.562561 148158800
2019-01-03 35.994999 36.430000 ... 34.721451 365248800
2019-01-04 36.132500 37.137501 ... 36.203678 234428400
2019-01-07 37.174999 37.207500 ... 36.123104 219111200
2019-01-08 37.389999 37.955002 ... 36.811718 164101200
... ... ... ... ... ...
2020-12-23 132.160004 132.429993 ... 130.960007 88223700
2020-12-24 131.320007 133.460007 ... 131.970001 54930100
2020-12-28 133.990005 137.339996 ... 136.690002 124486200
2020-12-29 138.050003 138.789993 ... 134.869995 121047300
2020-12-30 135.580002 135.990005 ... 133.720001 96452100
这与使用完全相同:
yahoo_financials = YahooFinancials(ticker)
historical_price = yahoo_financials.get_historical_price_data('2020-01-05', '2021-01-05', 'weekly')
pd.DataFrame(historical_price['AAPL']['prices'])
使用我下载的yahoo finance,Apple的历史数据。我正在使用来自 https://pypi.org/project/yahoofinancials/
的信息from yahoofinancials import YahooFinancials
ticker = 'AAPL'
yahoo_financials = YahooFinancials(ticker)
据此我可以使用以下方法获取每周数据:
historical_price = yahoo_financials.get_historical_price_data('2020-01-05', '2021-01-05', 'weekly')
这很好用。但是我正在努力将其解压缩为 pandas。有几本词典和词典列表让我难过。
当前输出为
AAPL
currency USD
eventsData {}
firstTradeDate {'formatted_date': '1980-12-12', 'date': 34547...
instrumentType EQUITY
prices [{'date': 1609736400, 'high': 133.610000610351...
timeZone {'gmtOffset': -18000}
我的问题是将上述内容解压到可用数据帧中的最佳方法是什么?
我建议改用 yfinance
,它也是基于雅虎的:
!pip install yfinance
import yfinance
yfinance.download('AAPL', start='2019-01-01', end='2020-12-31')
这输出:
Open High ... Adj Close Volume
Date ...
2019-01-02 38.722500 39.712502 ... 38.562561 148158800
2019-01-03 35.994999 36.430000 ... 34.721451 365248800
2019-01-04 36.132500 37.137501 ... 36.203678 234428400
2019-01-07 37.174999 37.207500 ... 36.123104 219111200
2019-01-08 37.389999 37.955002 ... 36.811718 164101200
... ... ... ... ... ...
2020-12-23 132.160004 132.429993 ... 130.960007 88223700
2020-12-24 131.320007 133.460007 ... 131.970001 54930100
2020-12-28 133.990005 137.339996 ... 136.690002 124486200
2020-12-29 138.050003 138.789993 ... 134.869995 121047300
2020-12-30 135.580002 135.990005 ... 133.720001 96452100
这与使用完全相同:
yahoo_financials = YahooFinancials(ticker)
historical_price = yahoo_financials.get_historical_price_data('2020-01-05', '2021-01-05', 'weekly')
pd.DataFrame(historical_price['AAPL']['prices'])