This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import the necessary modules | |
import pandas as pd | |
import yfinance as yf | |
def get_sp_data(start='2008-01-01', end=None): | |
# Get the current SP components, and get a tickers list | |
sp_assets = pd.read_html( | |
'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')[0] | |
assets = sp_assets['Symbol'].str.replace('.', '-').tolist() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import the necessary modules | |
import pandas as pd | |
import yfinance as yf | |
# Get the current IBEX components tickers list | |
ibex_assets = pd.read_html('https://es.wikipedia.org/wiki/IBEX_35')[2] | |
assets = (ibex_assets.Ticker + '.MC').tolist() | |
# Dowload historical data to a multi-index dataframe | |
data = yf.download(assets, start='2008-01-01', as_panel=False) |
NewerOlder