Drawdowns and Streaks
Drawdowns and Streaks Package version 1.3-1
Enrico Schumann
mailto:es@enricoschumann.net
Drawdowns
The drawdowns function returns magnitudes of drawdowns, as well as their peaks, troughs, and times of recovery.
> library("PMwR")> library("zoo")> dax <- zoo(DAX[[1]], as.Date(row.names(DAX)))> dd <- drawdowns(dax)> dd <- dd[order(dd$max, decreasing = TRUE), ] ## sort by size> dd
peak trough recover max18 2015-04-10 2015-09-24 <NA> 0.2381549 2014-07-03 2014-10-15 2014-12-05 0.14532010 2014-12-05 2014-12-15 2015-01-16 0.0746614 2014-01-17 2014-03-13 2014-05-13 0.07443017 2015-03-16 2015-03-26 2015-04-10 0.02663112 2015-02-04 2015-02-09 2015-02-12 0.0227118 2014-06-10 2014-06-26 2014-07-03 0.02232611 2015-01-26 2015-01-27 2015-02-02 0.0157205 2014-05-13 2014-05-16 2014-05-23 0.01284914 2015-03-02 2015-03-03 2015-03-05 0.0113932 2014-01-07 2014-01-09 2014-01-13 0.00889815 2015-03-09 2015-03-10 2015-03-11 0.00705713 2015-02-13 2015-02-17 2015-02-19 0.0061827 2014-06-02 2014-06-03 2014-06-06 0.0030533 2014-01-15 2014-01-16 2014-01-17 0.0016541 2014-01-03 2014-01-06 2014-01-07 0.00075816 2015-03-11 2015-03-12 2015-03-13 0.0005596 2014-05-27 2014-05-29 2014-05-30 0.000193
> par(bty = "n", las = 1, tck = 0.01, mar = c(3, 3, 1, 1), mgp = c(2, 0.5, 0), ps = 9)> plot(dax, xlab = "", ylab = "DAX")> abline(v = dd$peak[1])> abline(v = dd$trough[1])
Streaks
The streaks function returns a data-frame of uninterrupted up and down movements, with uninterrupted meaning that no countermovement occured of down (up) percent or more during up (down) movements.
> up_down <- streaks(dax, up = 0.1, down = -0.1)> up_down
start end state return1 2014-01-02 2014-03-13 <NA> -0.04072 2014-03-13 2014-07-03 up 0.11223 2014-07-03 2014-10-15 down -0.14534 2014-10-15 2015-04-10 up 0.44365 2015-04-10 2015-09-24 down -0.23826 2015-09-24 2015-11-30 up 0.20737 2015-11-30 2015-12-30 down -0.0562
You may use this information, for instance, to produce charts of up and down phases, such as the following. Note that the vertical scale is a log scale, i.e. a drop of 50% takes the same vertical distance as a rise of 100%.