from utils import get_monthly_sip_nav_df import numpy as np import pandas as pd def get_investment_sd(investment_df,start_date, end_date, SIP_date): return_df = pd.DataFrame() investment_monthly_df = get_monthly_sip_nav_df(investment_df, start_date, end_date, SIP_date=SIP_date) return_df['monthly_return'] = investment_monthly_df['nav'].pct_change() return_df['monthly_return'] = return_df['monthly_return'].dropna() # calculate annualized standard deviation of monthly returns return (return_df['monthly_return'].std()*np.sqrt(12)) * 100 def get_investment_sharpe_ratio(investment_df, start_date, end_date, SIP_date,risk_free_rate=6.86): return_df = pd.DataFrame() investment_monthly_df = get_monthly_sip_nav_df(investment_df, start_date, end_date, SIP_date=SIP_date) return_df['monthly_return'] = investment_monthly_df['nav'].pct_change()*100 return_df['monthly_return'] = return_df['monthly_return'].dropna() # calculate annualized standard deviation of monthly returns annualized_sd = return_df['monthly_return'].std()*np.sqrt(12) monthly_mean_return = return_df['monthly_return'].mean() print(monthly_mean_return) annualized_return = ((1+monthly_mean_return/100)**12 - 1)*100 print(annualized_return) # calculate Sharpe Ratio return ((annualized_return - risk_free_rate) / annualized_sd) def get_investment_indicator_report(investment_df, start_date,end_date,SIP_date="start",risk_free_rate=6.86): investment_monthly_df = get_monthly_sip_nav_df(investment_df, start_date, end_date, SIP_date) investment_sd = get_investment_sd(investment_monthly_df, start_date, end_date, SIP_date) investment_sharpe_ratio = get_investment_sharpe_ratio(investment_monthly_df, start_date, end_date, SIP_date,risk_free_rate) return (f""" Standard Deviation: {investment_sd} Sharpe Ratio: {investment_sharpe_ratio}""")