streaks {PMwR} | R Documentation |
Up and Down Streaks
Description
Compute up and down streaks for time-series.
Usage
streaks(x, ...)
## Default S3 method:
streaks(x, up = 0.2, down = -up,
initial.state = NA, y = NULL, relative = TRUE, ...)
## S3 method for class 'zoo'
streaks(x, up = 0.2, down = -up,
initial.state = NA, y = NULL, relative = TRUE, ...)
## S3 method for class 'NAVseries'
streaks(x, up = 0.2, down = -up,
initial.state = NA, bm = NULL, relative = TRUE, ...)
Arguments
x |
a price series |
initial.state |
|
up |
a number, such as 0.1 (i.e. 10%) |
down |
a negative number, such as -0.1 (i.e. -10%) |
y |
another price series |
bm |
another price series. Mapped to ‘ |
relative |
logical |
... |
other arguments passed to methods |
Details
streaks
is a generic function. It computes
series of uninterrupted up and down movements
(‘streaks’) in a price series. Uninterrupted
is meant in the sense that no countermovement of
down
(up
) percent or more occurs in up
(down) movements.
There are methods for numeric vectors, and
NAVseries
and zoo
objects.
The turning points (extreme points) are computed with the benefit of hindsight: the starting point (the low) of an up streak can only be determined once the streak is triggered, i.e. the up streak has already run its minimum amount. Vice versa for down streaks.
When ‘up
’ and ‘down
’ are
not equal, results may be inconsistent: in the
current implementation, streaks
alternates
between up and down streaks. Suppose up
is
large compared with down
, i.e. it takes long
to trigger up streaks, but they are easily
broken. Down streaks, on the other hand, are quickly
triggered but rarely broken. Now suppose that a down
streak is broken by an up streak: it may then well be
that the up streak would never have been counted as
such, because it was actually broken itself by
another down streak. The implementation for differing
values of ‘up
’ and ‘down
’
may change in the future.
Value
A data.frame
:
start |
beginning of streak |
end |
end of streak |
state |
|
return , change |
the return over the streak. If |
Author(s)
Enrico Schumann <es@enricoschumann.net>
References
Schumann, E. (2023) Portfolio Management with R.
https://enricoschumann.net/PMwR/; in particular, see
https://enricoschumann.net/R/packages/PMwR/manual/PMwR.html#drawdowns-streaks
See Also
Examples
streaks(DAX[[1]], t = as.Date(row.names(DAX)))
## results <- streaks(x = <...>, y = <...>)
##
## ===> *arithmetic* excess returns
## x[results$end]/x[results$start] -
## y[results$end]/y[results$start]
## ===> *geometric* excess returns
## x[results$end]/x[results$start] /
## (y[results$end]/y[results$start]) - 1