Learn R Programming

PortfolioTesteR (version 0.1.4)

scores_oos_only: Mask score tables to out-of-sample decision dates

Description

Utility used in the chapter’s diagnostics: keep scores only on dates when a portfolio decision was actually made (non-zero realised weights); set other dates to NA. Inputs are wide by symbol with a Date column.

Usage

scores_oos_only(scores_dt, weights_wide)

Value

A copy of scores_dt where rows not matching decision dates are set to NA

(except the Date column). If either input is empty, returns scores_dt[0].

Arguments

scores_dt

Wide table of model scores with columns Date, SYM1, SYM2, … (one column per symbol).

weights_wide

Wide table of realised portfolio weights with columns Date, SYM1, SYM2, … (one column per symbol). Decision dates are inferred as rows where any symbol weight is non-zero.

See Also

pt_collect_results()

Other Chapter3-helpers: pt_collect_results()

Examples

Run this code
# Toy example
dates <- as.Date("2020-01-01") + 7*(0:5)
scores <- data.frame(
  Date = dates,
  AAA = seq(0.1, 0.6, length.out = 6),
  BBB = rev(seq(0.1, 0.6, length.out = 6))
)
weights <- data.frame(
  Date = dates,
  AAA  = c(0, 0.1, 0, 0.2, 0, 0.15),
  BBB  = c(0, 0,   0, 0,   0, 0   )
)
scores_oos_only(scores, weights)

Run the code above in your browser using DataLab