SysQ Pseudo Code

Calculation of max. drawdown of an individual equity curve works as follows:

equity = 100           // arbitrary start value
maxValue = equity
maxDD = 1.0         // no drawdown
foreach (ret in eqCurve)
{
     equity *= ret
     if (equity > maxValue) maxValue = equity
     else
     {
         dd = equity / maxValue
         if (dd < maxDD) maxDD = dd                     
     }
}
return maxDD

 

Now we have access to the estimated drawdown at a given percentile level:

double MaxDDP(percentile)
{
    idx = Round( ddList.Count * percentile/100.0 )
    return 100.0 * (1.0 + ddList[idx]) // as a positive percentage
}

System Quality Algorithm as Pseudo Code

Input is a sequence of daily account values, typically in dollars.

// Create a list of daily returns
for ( all account values )
    ReturnsList.Add( av[i] / av[i-1] )

// Bootstrap
for( all bootstrap iterations )
{  
// build a one year synthetic equity curve from three day segments
   for(segment=0; segment < 252/3; segment++)
   {  
// random selection of segment
       idx = Random(0 .. ReturnsList.Count-2)
       eqCurve.Add( ReturnsList[idx] )
       eqCurve.Add( ReturnsList[idx+1] )
       eqCurve.Add( ReturnsList[idx+2] )
   }
   // calculate max DD of synthetic equity curve
   maxDD = MaxDD(eqCurve)
   ddlist.Add(maxDD)
}
Sort(ddList)