Description Usage Arguments Examples
Apply Rolling Functions From LBStart to LBEnd Wrapper around rollapplyr so that we can easily apply rolling functions over lagged windows
1 |
data |
An 'xts' object that is passed to 'rollapplyr'. |
FUN |
The function to be applied. |
lbstart |
The start of the lookback window. |
lbend |
The end of the lookback window. |
... |
Other arguments passed to rollapplyr. |
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 | growth <- diff(log(stocks))
signal <- rollAR(growth, rep(1/9,9))
# Rolling 10-day long-short hitrate
hits <- lbapplyr(compute_hits(growth, signal, "longshort"), sum, 9, 0)
bets <- lbapplyr(abs(compute_bets(signal, "longshort")), sum, 9, 0)
hr_ls <- hits/bets
# Rolling 10-day long hitrate
hits <- lbapplyr(compute_hits(growth, signal, "long"), sum, 9, 0)
bets <- lbapplyr(abs(compute_bets(signal, "long")), sum, 9, 0)
hr_long <- hits/bets
# Rolling 10-day uprate
hits <- lbapplyr(compute_hits(growth, signal, "alwayslong"), sum, 9, 0)
bets <- lbapplyr(abs(compute_bets(signal, "alwayslong")), sum, 9, 0)
hr_up <- hits/bets
# Rolling 10-day short hitrate
hits <- lbapplyr(compute_hits(growth, signal, "short"), sum, 9, 0)
bets <- lbapplyr(abs(compute_bets(signal, "short")), sum, 9, 0)
hr_short <- hits/bets
# Rolling 10-day downrate
hits <- lbapplyr(compute_hits(growth, signal, "alwaysshort"), sum, 9, 0)
bets <- lbapplyr(abs(compute_bets(signal, "alwaysshort")), sum, 9, 0)
hr_down <- hits/bets
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.