lbapplyr: Apply Rolling Functions From LBStart to LBEnd Wrapper around...

Description Usage Arguments Examples

Description

Apply Rolling Functions From LBStart to LBEnd Wrapper around rollapplyr so that we can easily apply rolling functions over lagged windows

Usage

1
lbapplyr(data, FUN, lbstart = 63, lbend = 0, ...)

Arguments

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.

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
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

jmuhlenkamp/conditionalAR documentation built on May 30, 2019, 1:59 p.m.