# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import numpy as np
import pandas as pd
import pandas_datareader.data as web


def get_closes(tickers, start_date=None, end_date=None, freq=None):
    import pandas as pd
    pd.core.common.is_list_like = pd.api.types.is_list_like
    import pandas_datareader.data as web  
    closes = pd.DataFrame(columns = tickers, index=web.YahooDailyReader(symbols=tickers[0], start=start_date, end=end_date, interval=freq).read().index)
    for ticker in tickers:
        df = web.YahooDailyReader(symbols=ticker, start=start_date, end=end_date, interval=freq).read()
        closes[ticker]=df['Adj Close']
    closes.index_name = 'Date'
    closes = closes.sort_index()
    return closes


# +
asset1 = '^MXX'
asset2 = 'BIMBOA.mx'
asset3 = 'ELEKTRA.MX'
asset4 = 'GMEXICOB.MX'
asset5 = 'WALMEX.MX'

names = [asset1,asset2,asset3,asset4,asset5]
start = '2019-08-19' 
end = '2020-08-19'
# -

# Precios diarios
daily_closes = get_closes(tickers = names, start_date = start, end_date = end, freq = 'd')
daily_closes

daily_closes.to_csv("Daily Closes.csv")

daily_closes.to_excel("Daily Closes.xlsx")

# +
#daily_ret = daily_closes.pct_change().dropna()
#daily_ret

StarcoderdataJupyterScriptsDedupFiltered