Python Get Historical Stock Prices With Yfinance

November 2, 2020
import yfinance as yf
yticker = yf.Ticker("MSFT")

df = yticker.history(period="3y") # max, 3mo, etc

# print(df.columns)
# ['Open', 'High', 'Low', 'Close', 'Volume', 'Dividends', 'Stock Splits'

print(df)

'''
                  Open        High  ...  Dividends  Stock Splits
Date                                ...                         
2017-10-31   80.666197   80.666197  ...        0.0             0
2017-11-01   80.015972   80.092470  ...        0.0             0
2017-11-02   79.700420   80.761818  ...        0.0             0
2017-11-03   80.398455   80.838313  ...        0.0             0
2017-11-06   80.513203   80.991310  ...        0.0             0
...                ...         ...  ...        ...           ...
2020-10-26  213.850006  216.339996  ...        0.0             0
2020-10-27  211.589996  214.669998  ...        0.0             0
2020-10-28  207.669998  208.839996  ...        0.0             0
2020-10-29  204.070007  207.360001  ...        0.0             0
2020-10-30  203.500000  204.289993  ...        0.0             0
'''

for index, row in df.iterrows():
    # 2017-10-31 00:00:00 80.6661972680961 80.6661972680961 79.47093001044333 79.5378646850586 27086600.0
    print(index, row['Open'], row['High'], row['Low'], row['Close'], row['Volume'])

NOTE: Plot yfinance Historical Candle Chart With mplfinance

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.