File Exchange

## Maximum Drawdown

version 1.0.0.0 (597 Bytes) by
Calculates max drawdown, start/end of msx drawdown period, end of recovery period

Updated 16 Mar 2006

Maximum drawdown can be defined as the largest drop from a peak to a bottom in a certain time period. This MATLAB function calculate max drawdown value, start and end of max drawdown period as well as the end of the recovery period (if any).

### Cite As

Andreas Steiner (2021). Maximum Drawdown (https://www.mathworks.com/matlabcentral/fileexchange/10367-maximum-drawdown), MATLAB Central File Exchange. Retrieved .

Andy Bibombe

Hae Kyung Im

Good, since it gets the job done. Just add Andreas Bonelli's efficiency improvement.

Rick Jacobs

Andreas Bonelli

Calculating the maximum of all previous elements in each iteration is not necessary. You can store the previous maximum and simply calculate the maximum of two elements in every loop.

mx = 0;
for i = 1:n
mx = max([lastmax, cr(i)]);
dd(i) = mx - cr(i);
end;

This has a huge impact on the function's performance. (Complexity reduction from O(n^2) to O(n).)

Depending on the shape of the curve avoiding writing mx in each iteration should yield a significant speedup as well:

mx = 0;
for i = 1:n
if cr(i) > mx mx = cr(i); end
dd(i) = mx - cr(i);
end;

juan jose fernandez

great and useful

##### MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
##### Platform Compatibility
Windows macOS Linux