Skip to contents

Captures detect_regime() arguments without running detection. Returns a closure that the consumer (fit_* or backtest()) invokes on its own internal triangle. The point is conditional / deferred detection – the change points depend on which cells the caller decides to expose:

  • In fit_ratio() / fit_loss() / fit_premium(), the spec is invoked on the full triangle the user passed in.

  • In backtest(), the spec is invoked on the masked triangle of each holdout fold, never on the full triangle. Held-out diagonals are removed before detect_regime() sees the data, so the detected change points depend only on cells the masked fit can also see. This is the leakage-safe contract of regime_spec().

Contrast with regime_at(), which produces an eager "Regime" object whose change points are fixed at construction time (independent of the fold's masked data).

Use regime_spec() when you want change points to be re-detected per fold so backtest honestly answers "given the data available at this fold, what regime structure would I have picked?" Use regime_at() when you want a fixed regime tested across folds.

Usage

regime_spec(...)

Arguments

...

kwargs passed verbatim to detect_regime() when the spec is invoked (e.g. loss, by, min_run, method).

Value

A function of one argument (a "Triangle") returning a "Regime" object. The caller decides which triangle to pass (full vs. masked); inside backtest() this is always the masked training triangle.

Examples

if (FALSE) { # \dontrun{
# Capture detection arguments, defer execution until fit time.
spec <- regime_spec(loss = "loss_ata")

# In fit_ratio(): closure is invoked on the user's `tri`.
fit <- fit_ratio(tri, loss_regime = regime_spec(loss = "loss_ata"))

# In backtest(): closure is invoked on the *masked* triangle of
# each holdout fold, so detected change points never peek at
# held-out cells.
bt <- backtest(tri, holdout = 6L,
               loss_regime = regime_spec(loss = "loss_ata"))
} # }