Is it possible to get monthly historical stock prices in python?

Jeffrey Derose picture Jeffrey Derose · Jul 30, 2016 · Viewed 9.6k times · Source

I know using pandas this is how you normally get daily stock price quotes. But I'm wondering if its possible to get monthly or weekly quotes, is there maybe a parameter I can pass through to get monthly quotes?

    from pandas.io.data import DataReader
    from datetime import datetime

    ibm = DataReader('IBM',  'yahoo', datetime(2000,1,1), datetime(2012,1,1))
    print(ibm['Adj Close'])

Answer

sk877 picture sk877 · Aug 8, 2016

Monthly closing prices from Yahoo! Finance...

import pandas_datareader.data as web

data = web.get_data_yahoo('IBM','01/01/2015',interval='m')

where you can replace the interval input as required ('d', 'w', 'm', etc).