runRanks: 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
2
3
4
5
6
7
8
runRanks(
  x,
  window = 10,
  ranks = window,
  cumulative = F,
  exact.multiplier = 0.5,
  ...
)

Arguments

x

xts object

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

ranks

window(default) number of ranks.

cumulative

FALSE(default) use from-inception calculation? Not tested. So beware.

exact.multiplier

The weight applied to identical values in the window. Must be between 0 and 1, inclusive. See ? TTR::runPercentRank

...

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: 

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

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

runRanks(xts(c(3, 1, 2, 3), zoo::as.Date(0:3)), window = 3, ranks = 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
runRanks(xts(c(3, 1, 2, 3), zoo::as.Date(0:3)), window = 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.