RNK: rolling ranks using TTR::runPercentRank

Description Usage Arguments Value References Examples

View source: R/Functions.R

Description

This is a wrapper around the R CRAN package TTR function runPercentRank. TTR runPercentRank gives skewed values (but with the value are in the correct order). This function uses that "proper ordering" and makes usable running ranks.

Usage

1
RNK(x, w = 10, r = w, ...)

Arguments

x

xts object

w

window 10(default) lag to determine the ranks. If cumulative=TRUE, the number of observations to use before the first result is returned. Not tested. So beware. Must be between 1 and nrow(x), inclusive

r

ranks window(default) number of ranks.

...

dots passed

Value

xts object. Lower x coredata values means lower rank numbers.

References

last Fortran version of percentRank.f (but the newer C version has a fix) https://github.com/joshuaulrich/TTR/blob/9b30395f7604c37ea12a865961d81666bc167616/src/percentRank.f

Examples

 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
## Not run: 

# RNK(rolling ranks using TTR::runPercentRank) examples

RNK(xts(c(3, 1, 2, 3), zoo::as.Date(0:3)), w = 2)
           V1rnk.2.2
1970-01-01        NA
1970-01-02         1
1970-01-03         2
1970-01-04         2

RNK(xts(c(3, 1, 2, 3), zoo::as.Date(0:3)), w = 3, r = 2)
           V1rnk.3.2
1970-01-01        NA
1970-01-02        NA
1970-01-03         1
1970-01-04         2

# the window is larger than the data
RNK(xts(c(3, 1, 2, 3), zoo::as.Date(0:3)), w = 5)
           V1rnk.5.5
1970-01-01        NA
1970-01-02        NA
1970-01-03        NA
1970-01-04        NA

## End(Not run)

AndreMikulec/econModel documentation built on June 30, 2021, 9:48 a.m.