Created
May 11, 2021 16:22
-
-
Save fnneves/e46e5fb63963dcd7e05d938951b56481 to your computer and use it in GitHub Desktop.
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
portf_allvalues = MEGA_DF.filter(regex='mktvalue').fillna(0) # getting just the market value of each ticker | |
portf_allvalues['portf_value'] = portf_allvalues.sum(axis=1) # summing all market values | |
# For the S&P500 price return | |
sp500 = pdr.get_data_yahoo('^GSPC', start_stocks, end_sp) | |
clean_header(sp500) | |
#getting the pct change | |
portf_allvalues = portf_allvalues.join(sp500['adj_close'], how='inner') | |
portf_allvalues.rename(columns={'adj_close': 'sp500_mktvalue'}, inplace=True) | |
portf_allvalues['ptf_value_pctch'] = (portf_allvalues['portf_value'].pct_change()*100).round(2) | |
portf_allvalues['sp500_pctch'] = (portf_allvalues['sp500_mktvalue'].pct_change()*100).round(2) | |
portf_allvalues['ptf_value_diff'] = (portf_allvalues['portf_value'].diff()).round(2) | |
portf_allvalues['sp500_diff'] = (portf_allvalues['sp500_mktvalue'].diff()).round(2) | |
# KPI's for portfolio | |
kpi_portfolio7d_abs = portf_allvalues.tail(7).ptf_value_diff.sum().round(2) | |
kpi_portfolio15d_abs = portf_allvalues.tail(15).ptf_value_diff.sum().round(2) | |
kpi_portfolio30d_abs = portf_allvalues.tail(30).ptf_value_diff.sum().round(2) | |
kpi_portfolio200d_abs = portf_allvalues.tail(200).ptf_value_diff.sum().round(2) | |
kpi_portfolio7d_pct = (kpi_portfolio7d_abs/portf_allvalues.tail(7).portf_value[0]).round(3)*100 | |
kpi_portfolio15d_pct = (kpi_portfolio15d_abs/portf_allvalues.tail(15).portf_value[0]).round(3)*100 | |
kpi_portfolio30d_pct = (kpi_portfolio30d_abs/portf_allvalues.tail(30).portf_value[0]).round(3)*100 | |
kpi_portfolio200d_pct = (kpi_portfolio200d_abs/portf_allvalues.tail(200).portf_value[0]).round(3)*100 | |
# KPI's for S&P500 | |
kpi_sp500_7d_abs = portf_allvalues.tail(7).sp500_diff.sum().round(2) | |
kpi_sp500_15d_abs = portf_allvalues.tail(15).sp500_diff.sum().round(2) | |
kpi_sp500_30d_abs = portf_allvalues.tail(30).sp500_diff.sum().round(2) | |
kpi_sp500_200d_abs = portf_allvalues.tail(200).sp500_diff.sum().round(2) | |
kpi_sp500_7d_pct = (kpi_sp500_7d_abs/portf_allvalues.tail(7).sp500_mktvalue[0]).round(3)*100 | |
kpi_sp500_15d_pct = (kpi_sp500_15d_abs/portf_allvalues.tail(15).sp500_mktvalue[0]).round(3)*100 | |
kpi_sp500_30d_pct = (kpi_sp500_30d_abs/portf_allvalues.tail(30).sp500_mktvalue[0]).round(3)*100 | |
kpi_sp500_200d_pct = (kpi_sp500_200d_abs/portf_allvalues.tail(200).sp500_mktvalue[0]).round(3)*100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment