vibhorag101
commited on
Commit
•
b64a84d
1
Parent(s):
57afab9
Added Beta
Browse files- indicators.py +31 -3
indicators.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from utils import get_monthly_sip_nav_df
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
|
@@ -25,12 +25,40 @@ def get_investment_sharpe_ratio(investment_df, start_date, end_date, SIP_date,ri
|
|
25 |
# calculate Sharpe Ratio
|
26 |
return ((annualized_return - risk_free_rate) / annualized_sd)
|
27 |
|
28 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
investment_monthly_df = get_monthly_sip_nav_df(investment_df, start_date, end_date, SIP_date)
|
30 |
investment_sd = get_investment_sd(investment_monthly_df, start_date, end_date, SIP_date)
|
31 |
investment_sharpe_ratio = get_investment_sharpe_ratio(investment_monthly_df, start_date, end_date, SIP_date,risk_free_rate)
|
|
|
|
|
|
|
|
|
|
|
32 |
return (f"""
|
33 |
Standard Deviation: {investment_sd}
|
34 |
-
Sharpe Ratio: {investment_sharpe_ratio}
|
|
|
|
|
|
|
|
|
35 |
|
36 |
|
|
|
1 |
+
from utils import get_monthly_sip_nav_df,get_mf_scheme_data
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
|
|
|
25 |
# calculate Sharpe Ratio
|
26 |
return ((annualized_return - risk_free_rate) / annualized_sd)
|
27 |
|
28 |
+
def get_investment_beta(investment_df, start_date, end_date, SIP_date):
|
29 |
+
benchmark_df,_ = get_mf_scheme_data('120716')
|
30 |
+
benchmark_monthly_df = get_monthly_sip_nav_df(benchmark_df, start_date, end_date, SIP_date)
|
31 |
+
investment_monthly_df = get_monthly_sip_nav_df(investment_df, start_date, end_date, SIP_date)
|
32 |
+
return_df = pd.DataFrame()
|
33 |
+
return_df['investment_monthly_return'] = investment_monthly_df['nav'].pct_change()*100
|
34 |
+
return_df['benchmark_monthly_return'] = benchmark_monthly_df['nav'].pct_change()*100
|
35 |
+
return_df = return_df.dropna()
|
36 |
+
|
37 |
+
# calculate beta
|
38 |
+
cov_matrix = np.cov(return_df['investment_monthly_return'], return_df['benchmark_monthly_return'])
|
39 |
+
covariance = cov_matrix[0][1]
|
40 |
+
benchmark_variance = cov_matrix[1][1]
|
41 |
+
beta = covariance / benchmark_variance
|
42 |
+
|
43 |
+
return beta
|
44 |
+
|
45 |
+
|
46 |
+
def get_investment_indicator_report(investment_df, start_date,end_date,SIP_date="start",risk_free_rate=6.55):
|
47 |
+
benchmark_df,_ = get_mf_scheme_data('120716')
|
48 |
investment_monthly_df = get_monthly_sip_nav_df(investment_df, start_date, end_date, SIP_date)
|
49 |
investment_sd = get_investment_sd(investment_monthly_df, start_date, end_date, SIP_date)
|
50 |
investment_sharpe_ratio = get_investment_sharpe_ratio(investment_monthly_df, start_date, end_date, SIP_date,risk_free_rate)
|
51 |
+
investment_beta = get_investment_beta(investment_monthly_df, start_date, end_date, SIP_date)
|
52 |
+
benchmark_sd = get_investment_sd(benchmark_df, start_date, end_date, SIP_date)
|
53 |
+
benchmark_sharpe_ratio = get_investment_sharpe_ratio(benchmark_df, start_date, end_date, SIP_date,risk_free_rate)
|
54 |
+
benchmark_beta = get_investment_beta(benchmark_df, start_date, end_date, SIP_date)
|
55 |
+
|
56 |
return (f"""
|
57 |
Standard Deviation: {investment_sd}
|
58 |
+
Sharpe Ratio: {investment_sharpe_ratio}
|
59 |
+
Beta: {investment_beta}
|
60 |
+
------------------------------------
|
61 |
+
UTI NIFTY50 Standard Deviation: {benchmark_sd}
|
62 |
+
UTI NIFTY50 Sharpe Ratio: {benchmark_sharpe_ratio}""")
|
63 |
|
64 |
|