Objective functions

Intermediate Portfolio Analysis in R

Ross Bennett

Instructor

Objective functions

Objective functions compute the objective value. In PortfolioAnalytics, objective functions can be any valid R function.

  • Common portfolio risk measures

    • standard deviation, expected shortfall, value at risk, component contribution to risk, maximum drawdown, Sharpe Ratio
  • Common benchmark relative performance measures

    • information ratio, tracking error, excess return, maximum relative drawdown
Intermediate Portfolio Analysis in R

Custom objective functions

User defined functions as objective functions

  • Argument naming:

    • R for asset returns

    • weights for the portfolio weights

    • mu, sigma, m3, m4 for the moments

  • Returns a single value

Intermediate Portfolio Analysis in R
# Annualized sharpe ratio
sr_annualized <- function(R, weights, sigma, scale, rfr){

    # Geometric annualized return
    r <- Return.annualized(Return.portfolio(R, weights), scale = scale)
    # Annual excess return
    re <- r - rfr

    # Annualized portfolio standard deviation
    pasd <- sqrt(as.numeric(t(weights) %*% 
                 sigma %*% weights)) * sqrt(scale)

    return(re / pasd)
}
Intermediate Portfolio Analysis in R
data(edhec)
asset_returns <- edhec[,1:4]

# Setup spec and add constraints port_spec <- portfolio.spec(assets = colnames(asset_returns)) port_spec <- add.constraint(portfolio = port_spec, type = "full_investment") port_spec <- add.constraint(portfolio = port_spec, type = "long_only")
# Add custom objective function port_spec <- add.objective(portfolio = port_spec, type = "return", name = "sr_annualized", arguments = list(scale = 12, rfr = 0.02))
Intermediate Portfolio Analysis in R

Let's practice!

Intermediate Portfolio Analysis in R

Preparing Video For Download...