# How to calculate the Maximum Drawdown for a portfolio in MATLAB?

I would like to verify my approach of calculating the Maximum Drawdown for a portfolio in MATLAB.

I've got a vector of returns for the portfolio, to which I add 1 for every return. Afterwards I calculate the cumulative product of this series in order to get a plot of how the portfolio develops over time with the function cumprod().

Is it correct to use the function maximumdrawdown() of this portfolio development to get the Maximum Drawdown of the portfolio?

Best regards

• As I remember from my course in Numerical Methods, if you have a good process for X(t), you can derive the distribution of MDD(T) and have an exact formula for it (a theoretical MDD). It may be different from empirical MDD, which you calculate from the data. – David Nguyen Apr 28 '19 at 9:48
• You should check mathworks. I recently used a function to calculate maximum drawdown using as input the price series vector. – alexbougias Apr 30 '19 at 22:26

## 2 Answers

Max drawdown of a portfolio is the loss relative to a previous high-water mark. It's typically calculated as you describe, calculating cumulative performance and maxDD relative to the previous equity peak.

I'm not aware of a built-in Matlab function (speaking as someone that built a backtesting suite in Matlab years back, including max DD by hand), so can't comment if you're speaking about a particular function with your concluding question.

Depending on your version:

Matlab 2018 or before https://in.mathworks.com/matlabcentral/fileexchange/10367-maximum-drawdown

The latter is a user-defined function and not a built-in by MathWorks. The developer is Andreas Steiner.