%% Compute Expected Maximum Drawdown
% This example shows how to use log-return moments of a fund to compute the expected maximum drawdown (EMaxDD) and then compare it with the realized maximum drawdown (MaxDD).

load FundMarketCash
logReturns = log(TestData(2:end,:) ./ TestData(1:end - 1,:));
Mu = mean(logReturns(:,1));
Sigma = std(logReturns(:,1),1);
T = size(logReturns,1);

MaxDD = maxdrawdown(TestData(:,1),'geometric')
EMaxDD = emaxdrawdown(Mu, Sigma, T)

% The drawdown observed in this time period is above the expected maximum drawdown. There is no contradiction here. The expected maximum drawdown is not an upper bound on the maximum losses from a peak, but an estimate of their average, based on a geometric Brownian motion assumption.
% Copyright 2020 The MathWorks, Inc.