def loadReturns(portfolio_returns: pd.Series, index_returns: pd.Series) -> tuple: assert "Return" in portfolio_returns.columns,\ "Dataframe should have a column named: Return" assert "Close" in index_returns.columns,\ "Dataframe should have a column named: Close" # Calculate key metrics return_10y, return_10y_i = "-", "-" return_5y, return_5y_i = "-", "-" return_1y, return_1y_i = "-", "-" if portfolio_returns.shape[0] > 0: # if stocks in portfolio # Get start values start_investment = portfolio_returns.Return[0] index_start = index_returns['Close'][0] ratio = start_investment / index_start # Modify index returns to match initial investment as portfolio value 10 years ago index_returns.Close = index_returns['Close'] * ratio # Get the number of days days = portfolio_returns.shape[0] days_i = index_returns.shape[0] # Calculate key numbers now = portfolio_returns.Return[days - 1] ago_5y = portfolio_returns.Return[days - 5 * 365 - 1] ago_1y = portfolio_returns.Return[days - 366] index_5y = index_returns['Close'][days_i - 5 * 365 - 1] index_1y = index_returns['Close'][days_i - 365] index_now = index_returns['Close'][days_i - 1] return_10y = round((now - start_investment) * 100 / start_investment, 2) return_5y = round((now - ago_5y) * 100 / ago_5y, 2) return_1y = round((now - ago_1y) * 100 / ago_1y, 2) return_10y_i = round( (index_now - start_investment) * 100 / start_investment, 2) return_5y_i = round((index_now - index_5y) * 100 / index_5y, 2) return_1y_i = round((index_now - index_1y) * 100 / index_1y, 2) return return_1y, return_5y, return_10y, return_1y_i, return_5y_i, return_10y_i