File size: 3,345 Bytes
b64a84d f823eaa bf3ca0c f823eaa b64a84d f823eaa b64a84d f823eaa b64a84d e7c63a2 b64a84d f823eaa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
from utils import get_monthly_sip_nav_df,get_mf_scheme_data
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()
# calculate annualized return, as the risk free rate is annualized
annualized_return = ((1+monthly_mean_return/100)**12 - 1)*100
# calculate Sharpe Ratio
return ((annualized_return - risk_free_rate) / annualized_sd)
def get_investment_beta(investment_df, start_date, end_date, SIP_date):
benchmark_df,_ = get_mf_scheme_data('120716')
benchmark_monthly_df = get_monthly_sip_nav_df(benchmark_df, start_date, end_date, SIP_date)
investment_monthly_df = get_monthly_sip_nav_df(investment_df, start_date, end_date, SIP_date)
return_df = pd.DataFrame()
return_df['investment_monthly_return'] = investment_monthly_df['nav'].pct_change()*100
return_df['benchmark_monthly_return'] = benchmark_monthly_df['nav'].pct_change()*100
return_df = return_df.dropna()
# calculate beta
cov_matrix = np.cov(return_df['investment_monthly_return'], return_df['benchmark_monthly_return'])
covariance = cov_matrix[0][1]
benchmark_variance = cov_matrix[1][1]
beta = covariance / benchmark_variance
return beta
def get_investment_indicator_report(investment_df, start_date,end_date,SIP_date="start",risk_free_rate=6.55):
benchmark_df,_ = get_mf_scheme_data('120716')
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)
investment_beta = get_investment_beta(investment_monthly_df, start_date, end_date, SIP_date)
benchmark_sd = get_investment_sd(benchmark_df, start_date, end_date, SIP_date)
benchmark_sharpe_ratio = get_investment_sharpe_ratio(benchmark_df, start_date, end_date, SIP_date,risk_free_rate)
benchmark_beta = get_investment_beta(benchmark_df, start_date, end_date, SIP_date)
return (f"""
Standard Deviation: {investment_sd}
Sharpe Ratio: {investment_sharpe_ratio}
Beta: {investment_beta}
UTI NIFTY50 Standard Deviation: {benchmark_sd}
UTI NIFTY50 Sharpe Ratio: {benchmark_sharpe_ratio}""")
|