File size: 1,918 Bytes
f823eaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf3ca0c
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
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()
    # 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_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}""")