|
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() |
|
|
|
|
|
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() |
|
|
|
|
|
annualized_sd = return_df['monthly_return'].std()*np.sqrt(12) |
|
monthly_mean_return = return_df['monthly_return'].mean() |
|
|
|
annualized_return = ((1+monthly_mean_return/100)**12 - 1)*100 |
|
|
|
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() |
|
|
|
|
|
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}""") |
|
|
|
|
|
|