File: maxdrawdown.Rd

package info (click to toggle)
tseries 0.10-48-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 664 kB
  • sloc: fortran: 1,347; ansic: 757; makefile: 67; f90: 21
file content (59 lines) | stat: -rw-r--r-- 1,711 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
\name{maxdrawdown}
\alias{maxdrawdown}
\title{Maximum Drawdown or Maximum Loss}
\description{
  This function computes the maximum drawdown or maximum loss of the
  univariate time series (or vector) \code{x}. 
}
\usage{
maxdrawdown(x)
}
\arguments{
  \item{x}{a numeric vector or univariate time series.}
}
\details{
  The max drawdown or max loss statistic is defined as the maximum
  value drop after one of the peaks of \code{x}. For financial
  instruments the max drawdown represents the worst investment loss for
  a buy-and-hold strategy invested in \code{x}.
}
\value{
  A list containing the following three components:
  \item{maxdrawdown}{double representing the max drawdown or max
    loss statistic.}
  \item{from}{the index (or vector of indices) where the max drawdown
    period starts.} 
  \item{to}{the index (or vector of indices) where the max drawdown
    period ends.} 
}
\author{A. Trapletti}
\seealso{
  \code{\link{sterling}}
}
\examples{
# Toy example
x <- c(1:10, 9:7, 8:14, 13:8, 9:20)
mdd <- maxdrawdown(x)
mdd

plot(x)
segments(mdd$from, x[mdd$from], mdd$to, x[mdd$from], col="grey")
segments(mdd$from, x[mdd$to], mdd$to, x[mdd$to], col="grey")
mid <- (mdd$from + mdd$to)/2
arrows(mid, x[mdd$from], mid, x[mdd$to], col="red", length = 0.16)

# Realistic example
data(EuStockMarkets)
dax <- log(EuStockMarkets[,"DAX"])
mdd <- maxdrawdown(dax)
mdd

plot(dax)
segments(time(dax)[mdd$from], dax[mdd$from],
         time(dax)[mdd$to], dax[mdd$from], col="grey")
segments(time(dax)[mdd$from], dax[mdd$to],
         time(dax)[mdd$to], dax[mdd$to], col="grey")
mid <- time(dax)[(mdd$from + mdd$to)/2]
arrows(mid, dax[mdd$from], mid, dax[mdd$to], col="red", length = 0.16)
}
\keyword{ts}