Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pandas Datareader for multiindex stock data
import datetime
import numpy as np
import pandas as pd
import pandas_datareader.data as pdr
# fetch multiple asset data
def getMultiAssetData(ticketList, date_from, date_to):
def getData(ticker):
data = pdr.DataReader(ticker, 'yahoo', date_from, date_to)
return data
datas = map(getData, tickerList)
return pd.concat(datas, keys=tickerList, names=['Ticker', 'Date'])
date_from = datetime.date(2020, 1, 1)
date_to = datetime.date(2020, 8, 31)
tickerList = ['AAPL', 'AMZN', 'CCEP', 'FB', 'JNJ', 'JWN', 'NVS', 'PG']
multiData = getMultiAssetData(tickerList, date_from, date_to)
df = multiData.copy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment