cummdd

Syntax

cummdd(X, [ratio=true])

Arguments

X is a numeric vector, indicating the input data for calculating maximum drawdown (MDD), commonly cumulative return (or rate).

ratio (optional) is a Boolean scalar indicating whether to express the MDD in ratio or absolute value.

  • true (default): Return the ratio of MDD over the peak.

  • false: Return the absolute value of MDD.

Please see Cumulative Window Functions for the windowing logic.

Details

Cumulatively calculate the maximum drawdown for the input X. NULL values are ignored in calculation.

Return value: A scalar of the same type as X.

Examples

Suppose the daily returns for a portfolio are as follows:

Date Returns
2024-10-01 36
2024-10-02 96
2024-10-03 42
2024-10-04 100
2024-10-05 59
2024-10-06 86
2024-10-07 25
2024-10-08 72

Calculate the maximum drawdown:

x = [36,96,42,100,59,86,25,64,72]
cummdd(x)
// Output: [0,0,0.5625,0.5625,0.5625,0.5625,0.75,0.75,0.75]
cummdd(x, false)
// Output: [0,0,54,54,54,54,75,75,75]