From ggrothendieck at gmail.com  Wed May 17 23:20:11 2006
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 17 May 2006 17:20:11 -0400
Subject: [Rd] Convention difference in tseries.maxdrawdown (PR#8872)
In-Reply-To: <20060517203730.3158DCD14@slim.kubism.ku.dk>
References: <20060517203730.3158DCD14@slim.kubism.ku.dk>
Message-ID: <971536df0605171420s2eb922c0p5e92ba0f318c000d@mail.gmail.com>

Regarding the upwardly compatible comment, the dollar drawdown that
corresponds to the maximum fractional drawdown is not necessarily the
maximum dollar drawdown.

For example, in this situation the maximum fractional drawdown
is from 100 to 75 but the maximum dollar drawdown is from 200
to 160.

> x <- c(1, 100, 75, 200, 160)

> maximumdrawdown(x) # function defined in post
$maximumdrawdown
[1] 0.25

$maxdrawdown
[1] 25

$from
[1] 2

$to
[1] 3

> maxdrawdown(x) # function from tseries
$maxdrawdown
[1] 40

$from
[1] 4

$to
[1] 5

On 5/17/06, rproject at boonstra.org <rproject at boonstra.org> wrote:
> Full_Name: Brian K. Boonstra
> Version: 2.2.1
> OS: WinXP, OSX
> Submission from: (NULL) (63.172.178.137)
>
>
> The maxdrawdown function in tseries defines the maximum drawdown in terms of
> absolute dollars (or whatever units the input is in).  Industry convention is to
> do this in percentage terms.  I have written the code below as
> maximumdrawdown(), which retains backward compatibility with the current
> version.  It has the flaw that it does not check for zero or negative values.
>
> maximumdrawdown <- function (x)
> {
>    if (NCOL(x) > 1)
>        stop("x is not a vector or univariate time series")
>    if (any(is.na(x)))
>        stop("NAs in x")
>    cminx <- x/cummax(x)
>    mdd <- min(cminx)
>    to <- which(mdd == cminx)
>    from <- double(NROW(to))
>    for (i in 1:NROW(to)) {
>      from[i] <- max( which(cminx[1:to[i]] == 1) )
>      }
>    return(list(maximumdrawdown = 1-mdd, maxdrawdown = (1-mdd)*x[from], from =
> from, to = to))
> }
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Convention difference in tseries.maxdrawdown (PR#8872)
Gabor Grothendieck