Custom moment functions

Intermediate Portfolio Analysis in R

Ross Bennett

Instructor

Custom moment functions

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

Intermediate Portfolio Analysis in R

Example: custom moment function

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

Let's practice!

Intermediate Portfolio Analysis in R

Preparing Video For Download...