<jupyter_start><jupyter_text>Valorización SMU<jupyter_code>import os
print(f'pip install -r {os.getcwd()}\\requirements.txt')<jupyter_output><empty_output><jupyter_text>Importación de la Librerías<jupyter_code>import importlib
import matplotlib
import pandas as pd

from utils import functions<jupyter_output><empty_output><jupyter_text>Definición de Variables Clave<jupyter_code>company = str(input('Por favor, ingrese el ticker de la compañía a valorar: '))
market = 'IGPA'<jupyter_output>Por favor, ingrese el ticker de la compañía a valorar:  SMU<jupyter_text>Cálculo Beta<jupyter_code>importlib.reload(functions)

# We define our ticker and associated market to compare to
cols_cov = []
dict_dfs = {company: f'{company} Historical Data.csv',
            market: f'S&P CLX {market} Historical Data.csv'}

for key, data in dict_dfs.items():
    # Using a parser funtion, data is cleaned
    df_local = functions.parse_investing(data)
    
    # We add a year and week column to our dataframe
    for i, dtime in enumerate(['Year', 'Week']):
        df_local.insert(loc=0, column=dtime, value=df_local['Date'].apply(
            lambda dtime: dtime.isocalendar()[i]))
    
    # A column of percentual change is added and results are stored
    df_local[f'{key}_change'] = df_local['Price'].pct_change() * 100
    dict_dfs[key] = df_local.dropna(subset=[f'{key}_change'])
    cols_cov.append(f'{key}_change')


# Relevant columns are merged to calculate a covariation matrix
right_cols = ['Date', f'{market}_change']
df_returns = pd.merge(dict_dfs[company],
                      dict_dfs[market][right_cols], on='Date')

# We generate and print our covariation matrix
cov_matrix = df_returns[cols_cov].cov()
display(cov_matrix)

# Finally, our beta with the market is calculated
beta = cov_matrix.iloc[0, 1] / cov_matrix.iloc[1, 1]
print(f'\nEl beta de mercado de {beta:.2f} unidades!\n')
df_returns
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()
# dict_dfs['SMU']['SMU_change']
dict_dfs['SMU'].at[0, 'Date'].isocalendar()
dict_dfs['SMU']['Date'].apply(lambda dtime:
                              dtime.isocalendar()[1]).sort_values().unique()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12802926383173296, 'fraction_numerical': 0.00594421582075903, 'mean_word_length': 4.8975741239892185, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '58813', 'license': 'MIT', 'n_tokens_mistral': 782, 'n_tokens_neox': 756, 'n_words': 181, 'path': 'Tesis/SMU-calculator/Tesis-SMU.ipynb', 'repo_name': 'nganterh/valuation', 'size': '2187'}