Intermediate Portfolio Analysis in R
Ross Bennett
Instructor
A custom moment function is a user defined function
Arguments:
R
for asset returns
portfolio
for the portfolio specification object
Return a named list where the elements represent the moments
mu
: Expected returns vector
sigma
: Variance-covariance matrix
m3
: Coskewness matrix
m4
: Cokurtosis matrix
library(MASS)
custom_fun <- function(R, portfolio, rob_method = "mcd"){
out <- list()
out$sigma <- cov.rob(R, method = rob_method)
return(out)
# Passing the rob_method argument to custom_fun
optimize.portfolio(R, portfolio, momentFUN = custom_fun,
rob_method = "mcd")
optimize.portfolio(R, portfolio, momentFUN = custom_fun,
rob_method = "mve")
Intermediate Portfolio Analysis in R