craft_predict: Predict from a Fitted CRAFT Model

View source: R/regime-forecast-v5.R

craft_predictR Documentation

Predict from a Fitted CRAFT Model

Description

Uses a fitted CRAFT model to transform the latest trajectory, estimate future regime probabilities, sample future-trajectory analogues, and fit smooth forecast distributions.

Usage

craft_predict(
  object,
  newdata = NULL,
  n_draws = NULL,
  seed = NULL,
  type = c("all", "trajectory_draws", "distributions", "probabilities", "labels")
)

Arguments

object

A fitted CRAFT object returned by craft_fit().

newdata

Optional matrix or data frame containing the most recent series history. If supplied, it must contain the fitted asset columns and more rows than the fitted trajectory window. If NULL, the latest trajectory stored in object is reused.

n_draws

Optional number of sampled future-trajectory draws. Defaults to the number of draws stored in object.

seed

Optional random seed for sampling.

type

Prediction output type. "all" returns the full prediction object; "trajectory_draws" returns sampled future-trajectory rows; "distributions" returns return and level forecast distributions; "probabilities" returns transition probabilities; "labels" returns latest regime labels.

Value

For type = "all", an object of class craft_prediction, a list with latest_regime_labels, latest_regime_probabilities, trajectory_draws, sampler_trace, corr_by_horizon, return_dists, level_dists, and diagnostics. Other type values return the requested subset.

Examples


set.seed(1)
series <- data.frame(
  a = cumprod(1 + rnorm(80, 0.001, 0.01)),
  b = cumprod(1 + rnorm(80, 0.0005, 0.012))
)
fit <- craft_fit(
  series,
  window = 5,
  n_draws = 50,
  n_factors = 1,
  min_segment = 5,
  max_regimes_per_factor = 3,
  n_testing = 0,
  verbose = FALSE
)
pred <- craft_predict(fit, n_draws = 25, seed = 1)
names(pred$return_dists)


CRAFT documentation built on Nov. 2, 2026, 9:06 a.m.