File Exchange

image thumbnail

Maximum Drawdown

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


Updated 16 Mar 2006

No License

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 (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

Andy Bibombe

Hae Kyung Im

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

Rick Jacobs

Max Drawdown is so easy to calculate in your head.

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);

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);

juan jose fernandez

great and useful

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

Inspired: Maximum Drawdown

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!