Skip to content

Instantly share code, notes, and snippets.

View paduel's full-sized avatar
🎯
Focusing

paduel

🎯
Focusing
View GitHub Profile
@paduel
paduel / sp_components_data.py
Last active April 14, 2023 21:08
Code to download the SP500 components from Yahoo Finance.
# 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()
@paduel
paduel / ibex_components_data.py
Last active February 23, 2020 19:55
Simple code to download historical data of current IBEX components.
# 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)