Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/sandbox/MSR_analytical.R
1433 views
1
MSR = function (sigma,return_estimate,long_only) {
2
3
#'Maximum Sharpe Ratio
4
#'Calculates the portfolio weights in accordance with a maximum sharpe ratio strategy.
5
#'From Gautam, K. & Lodh, A. 2013 "Scientific Beta Efficient Maximum Sharpe Ratio Indices " EDHEC-Risk Institute Scientific Beta(2013)
6
#'@Title Efficient Maximum Sharpe Ratio
7
#'@author Corporate Knights Inc.: Michael Fong /email{[email protected]}, Kyle Balkissoon /email{[email protected]}
8
#'@param sigma = Covariance matrix of returns
9
#'@param return_estimate = vector of expected returns (or) expected returns - risk free rate
10
#'
11
#'
12
step1 = sigma
13
unit_vector = c(rep(1,ncol(step1)))
14
#Calculate EMS portfolio weight matrix
15
step2 = (step1)^(-1)%*%return_estimate
16
step3 = as.numeric((unit_vector)%*%(step1)^(-1)%*%return_estimate)
17
step4 = step2/step3
18
# Long-Only Adjustment - Set negative weights to zero
19
if(long_only=='TRUE'){step5 = ifelse(step4<0,0,step4)
20
}else{step5 = step4}
21
# Normalize Weights
22
step6 = step5/sum(step5)
23
return(t(step6))
24
}
25