'How do I retrieve price data of stock exchanges in Python?
I can retrieve an individual stock's price data as follows:
import yfinance as yf
stockPrice = yf.Ticker("AAPL").history(period="max")["Close"] #by the way, ["Close"] is not strictly required.
Is there a way to retrieve the historical compounded price data of a stock exchange as a whole (e.g. AEX, IBEX, DAX, etc.)?
Any help is appreciated!
Solution 1:[1]
How about this? Just pass multiple ticker symbols to download.
import yfinance as yf
data = yf.download("AEX IBEX DAX AAPL", periods="max")['Close']
data.tail()
Output:
AAPL AEX DAX IBEX
Date
2022-03-21 165.380005 NaN 28.230000 16.16
2022-03-22 168.820007 NaN 28.629999 15.85
2022-03-23 170.210007 NaN 28.065001 15.91
2022-03-24 174.070007 NaN 28.207001 16.18
2022-03-25 174.720001 NaN 28.340000 15.00
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KarelZe |
