# Maximum Loss and Mean-Absolute Deviation risk measures

**Systematic Investor » R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

During construction of typical efficient frontier, risk is usually measured by the standard deviation of the portfolio’s return. Maximum Loss and Mean-Absolute Deviation are alternative measures of risk that I will use to construct efficient frontier. I will use methods presented in Comparative Analysis of Linear Portfolio Rebalancing Strategies: An Application to Hedge Funds by Krokhmal, P., S. Uryasev, and G. Zrazhevsky (2001) paper to construct optimal portfolios.

Let x.i, i= 1,…,n be weights of instruments in the portfolio. We suppose that j= 1,…,T scenarios of returns with equal probabilities are available. I will use historical assets returns as scenarios. Let us denote by r.ij the return of i-th asset in the scenario j. The portfolio’s Maximum Loss (page 34) can be written as

It can be formulated as a linear programming problem

This linear programming problem can be easily implemented

min.maxloss.portfolio <- function ( ia, # input assumptions constraints # constraints ) { n = ia$n nt = nrow(ia$hist.returns) # objective : maximum loss, w f.obj = c( rep(0, n), 1) # adjust prior constraints, add w f.con = rbind(constraints$A, 0) f.dir = c(rep('=', constraints$meq), rep('>=', len(constraints$b) - constraints$meq)) f.rhs = constraints$b # -SUMr.ij * x.i <= w, for each j from 1 ... T a1 = rbind( matrix(0, n, nt), 0) b1 = rep(0, nt) a1[1:n,] = t(ia$hist.returns) a1[(n + 1),] = +1 # w f.con = cbind( f.con, a1 ) f.dir = c(f.dir, rep('>=', nt)) f.rhs = c(f.rhs, b1) # find optimal solution x = NA sol = try(lp.anyx('min', f.obj, t(f.con), f.dir, f.rhs, -100), TRUE) if(!inherits(sol, 'try-error')) { x = sol$solution[1:n] } return( x ) }

The portfolio’s Mean-Absolute Deviation (MAD) (page 33) can be written as

It can be formulated as a linear programming problem

This linear programming problem can be implemented

min.mad.portfolio ( ia, # input assumptions constraints # constraints ) { n = ia$n nt = nrow(ia$hist.returns) # objective : Mean-Absolute Deviation (MAD) # 1/T * [ SUM (u+.j + u-.j) ] f.obj = c( rep(0, n), (1/nt) * rep(1, 2 * nt) ) # adjust prior constraints, add u+.j, u-.j f.con = rbind( constraints$A, matrix(0, 2 * nt, ncol(constraints$A) ) ) f.dir = c(rep('=', constraints$meq), rep('>=', len(constraints$b) - constraints$meq)) f.rhs = constraints$b # [ SUM r.ij * x.i ] - 1/T * [ SUM [ SUM r.ij * x.i ] ] = u+.j - u-.j , for each j = 1,...,T a1 = rbind( matrix(0, n, nt), -diag(nt), diag(nt)) b1 = rep(0, nt) a1[1:n,] = t(ia$hist.returns) - repmat(colMeans(ia$hist.returns), 1, nt) f.con = cbind( f.con, a1 ) f.dir = c(f.dir, rep('=', nt)) f.rhs = c(f.rhs, b1) # find optimal solution x = NA min.x.bounds = c( rep(-100, n), rep(0, 2 * nt) ) sol = try(lp.anyx('min', f.obj, t(f.con), f.dir, f.rhs, min.x.bounds), TRUE) if(!inherits(sol, 'try-error')) { x = sol$solution[1:n] } return( x ) }

Let’s examine efficient frontiers computed under different risk measures using historical input assumptions presented in the Introduction to Asset Allocation post:

############################################################################### # Create Efficient Frontier ############################################################################### n = ia$n # x.i >= 0 constraints = new.constraints(diag(n), rep(0, n), type = '>=') # x.i constraints = add.constraints(diag(n), rep(0.8, n), type = ' # SUM x.i = 1 constraints = add.constraints(rep(1, n), 1, type = '=', constraints) # create efficient frontier(s) ef.risk = portopt(ia, constraints, 50, 'Risk') ef.maxloss = portopt(ia, constraints, 50, 'Max Loss', min.maxloss.portfolio) ef.mad = portopt(ia, constraints, 50, 'MAD', min.mad.portfolio) # Plot multiple Efficient Frontiers layout( matrix(1:4, nrow = 2) ) plot.ef(ia, list(ef.risk, ef.maxloss, ef.mad), portfolio.risk, F) plot.ef(ia, list(ef.risk, ef.maxloss, ef.mad), portfolio.maxloss, F) plot.ef(ia, list(ef.risk, ef.maxloss, ef.mad), portfolio.mad, F) # Plot multiple Transition Maps layout( matrix(1:4, nrow = 2) ) plot.transitopn.map(ef.risk) plot.transitopn.map(ef.maxloss) plot.transitopn.map(ef.mad)

The Mean-Absolute Deviation and Standard Deviation risk measures are very similar by construction – they both measure average deviation, so it is not a surprise that their efficient frontiers and transition maps are close. On the other hand, the Maximum Loss measures the extreme deviation and has very different efficient frontier and transition map.

**leave a comment**for the author, please follow the link and comment on their blog:

**Systematic Investor » R**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.