rproject at boonstra.org
2006-May-17 20:37 UTC
[Rd] Convention difference in tseries.maxdrawdown (PR#8872)
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))
}
Gabor Grothendieck
2006-May-17 21:20 UTC
[Rd] Convention difference in tseries.maxdrawdown (PR#8872)
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 >
Hi everybody,
I'd like to report this problem I have on Windows with R 2.2.1, R 2.3.0,
R-2.3.0 patched (r38086) and R 2.4.0 devel (r37925):
D:\hpages>R\bin\R CMD config CC
Can't open perl script "D:\hpages\R-2.3.1/bin/config": No such
file
or directory
Best,
H.
--
------------------------
Herv? Pag?s
E-mail: hpages at fhcrc.org
Phone: (206) 667-5791
Fax: (206) 667-1319
Hi,
Something else I'd like to report.
If a segmentation fault occurs during the "creating vignettes" step,
then 'R CMD build' ignores the problem and end up building the source
package anyway:
/loc/biocbuild/1.9d/R/bin/R CMD build RMAGEML
* checking for file 'RMAGEML/DESCRIPTION' ... OK
* preparing 'RMAGEML':
...
* DONE (RMAGEML)
* creating vignettes ...sh: line 1: 8070 Segmentation fault
'/loc/biocbuild/1.9d/R/bin/R' --vanilla --no-save
--quiet /tmp/Rout656233925 2>&1
OK
* cleaning src
* removing junk files
* checking for LF line-endings in source files
* checking for empty or unneeded directories
* building 'RMAGEML_2.7.0.tar.gz'
'R CMD check' behaves the same way during the "checking package
vignettes" step.
I have observed this problem with R 2.3.0 and R 2.4.0 devel (r37925).
Best,
H.
--
------------------------
Herv? Pag?s
E-mail: hpages at fhcrc.org
Phone: (206) 667-5791
Fax: (206) 667-1319
Herve Pages
2006-May-17 21:46 UTC
[Rd] 'R CMD build' ignoring segfaults occuring during the vignettes creation
Sorry for erroneous subject of my previous post. Here it goes again.
----------------------------------------------------------------------------
Hi,
Something else I'd like to report.
If a segmentation fault occurs during the "creating vignettes" step,
then 'R CMD build' ignores the problem and end up building the source
package anyway:
/loc/biocbuild/1.9d/R/bin/R CMD build RMAGEML
* checking for file 'RMAGEML/DESCRIPTION' ... OK
* preparing 'RMAGEML':
...
* DONE (RMAGEML)
* creating vignettes ...sh: line 1: 8070 Segmentation fault
'/loc/biocbuild/1.9d/R/bin/R' --vanilla --no-save
--quiet /tmp/Rout656233925 2>&1
OK
* cleaning src
* removing junk files
* checking for LF line-endings in source files
* checking for empty or unneeded directories
* building 'RMAGEML_2.7.0.tar.gz'
'R CMD check' behaves the same way during the "checking package
vignettes" step.
I have observed this problem with R 2.3.0 and R 2.4.0 devel (r37925).
Best,
H.
--
------------------------
Herv? Pag?s
E-mail: hpages at fhcrc.org
Phone: (206) 667-5791
Fax: (206) 667-1319
Adrian Trapletti
2006-May-18 14:00 UTC
[Rd] Convention difference in tseries.maxdrawdown (PR#8872)
> > 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) > >What type of drawdown to work with depends on the context. If working in percent is more appropriate, then you might use maxdrawdown(log(x))$maxdrawdown or if log returns are not appropriate then the following transformation provides the equivalent what was suggested -(exp(-maxdrawdown(log(x))$maxdrawdown)-1) Best regards Adrian>> 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 >> > >