Austin home

Example 3.5: Calculating Maximum Drawdown and Maximum Drawdown Duration

The continues the preceding long-short market-neutral example (Example 3.4.) in order to illustrate the calculation of maximum drawdown and maximum drawdown duration.

The first step in this calculation is to calculate the “high watermark” at the close of each day, which is the maximum cumulative return of the strategy up to that time.

(Using the cumulative return curve to calculate high watermark and drawdown is equivalent to using the equity curve, since equity is nothing more than initial investment times 1 plus the cumulative return.) From the high watermark, we can calculate the drawdown, the maximum drawdown, and maximum drawdown duration.

calculateMaxDD <- function(cumret) {
  
  # initialise highwatermark to zero
  highwatermark <- rep(0, length(cumret))
  
  # initialize drawdowns to zero
  drawdown <- rep(0, length(cumret))
  
  # initialize drawdown duration to zero
  drawdownduration <- rep(0, length(cumret))

  for(t in 2:length(cumret)) {
    
    highwatermark[t] <- max(highwatermark[t-1], cumret[t])
  
    # drawdown on each day
    drawdown[t] <-  (1+highwatermark[t]) / (1+cumret[t])-1
    
    if (drawdown[t]==0) {
        drawdownduration[t] <- 0
    } else {
        drawdownduration[t] <- drawdownduration[t-1]+1
    }
  }

  # maximum drawdown
  maxDD <- max(drawdown)

  # maximum drawdown duration
  maxDDD <- max(drawdownduration)

  return(c(maxDD, maxDDD))
}

# This is a continuation of exercise 3.4 and requires the netRet data
netRet <- readRDS(file.path(getwd(), "data", "netRet.rds"))
# cumulative compounded returns
cumret <- cumprod(1+netRet)-1
plot(cumret)

# # maximum drawdown. Output should be 0.1053
# maxDrawdown
maxDrawdown <- calculateMaxDD(cumret)[1]
maxDrawdown
# # maximum drawdown duration. Output should be 497.
# maxDrawdownDuration
maxDrawdownDuration <- calculateMaxDD(cumret)[2]
maxDrawdownDuration
# Notice the code fragment above calls a function “calculateMaxDrawdown,”
# which I display below