View source: R/regime-forecast-v5.R
| craft_fit | R Documentation |
Runs the CRAFT end-to-end workflow: trajectory embedding, past and future regime detection, transition probability estimation, future-trajectory sampling, correlation diagnostics, distribution fitting, and optional internal backtesting.
craft_fit(
series,
volumes = NULL,
window = 20,
n_draws = 1000,
n_factors = 3,
var_threshold = 0.95,
horizon = NULL,
seed = 42,
transition_alpha = 1,
transition_min_count = 1,
transition_key_sep = "\r",
valid_frac = 0.2,
valid_split = c("last", "random", "blocked"),
n_testing = 0L,
backtest_parallel = TRUE,
backtest_workers = NULL,
backtest_min_train = NULL,
sampler_weight = c("uniform", "weighted_bal_acc", "bal_acc", "weighted_acc", "acc"),
tail_penalty_lambda = 0,
tail_penalty_threshold = 3,
tail_penalty_power = 2,
tail_penalty_aggregation = c("mean", "max", "sum"),
tail_penalty_scope = c("forecast", "all"),
volume_alpha = 1,
max_regimes_per_factor = 6,
factor_selection = "fixed",
min_segment = 30L,
past_regime_args = list(),
future_regime_args = list(),
return_train_probs = TRUE,
verbose = TRUE
)
series |
A data frame or matrix of numeric time series in columns. |
volumes |
Optional matrix or data frame of volumes with the same dimensions as |
window |
Trajectory window length used for lag and lead embeddings. |
n_draws |
Number of future-trajectory rows to sample. |
n_factors |
Number of SVD factors when fixed factor selection is used. |
var_threshold |
Cumulative variance threshold for variance-based factor selection. |
horizon |
Optional forecast horizon. If |
seed |
Optional random seed. |
transition_alpha |
Additive smoothing parameter for transition probabilities. |
transition_min_count |
Minimum count for memorized transition rows before fallback to global probabilities. |
transition_key_sep |
Internal separator used for transition-state keys. |
valid_frac |
Fraction of rows reserved for transition-model validation. |
valid_split |
Validation split strategy. |
n_testing |
Number of internal backtest origins. Use zero to skip backtesting. |
backtest_parallel |
Logical. If |
backtest_workers |
Optional number of parallel workers. |
backtest_min_train |
Optional minimum training length for backtest origins. |
sampler_weight |
Metric used to weight target regimes during future-trajectory sampling. |
tail_penalty_lambda |
Strength of the optional tail penalty applied to candidate rows. |
tail_penalty_threshold |
Robust z-score threshold for tail penalties. |
tail_penalty_power |
Power applied to excess robust z-scores. |
tail_penalty_aggregation |
Aggregation used for row-level tail penalties. |
tail_penalty_scope |
Whether the tail penalty uses forecast-horizon columns or all forward-trajectory columns. |
volume_alpha |
Exponent for volume-derived time weights. |
max_regimes_per_factor |
Maximum regimes per SVD factor. |
factor_selection |
SVD factor selection strategy passed to |
min_segment |
Minimum segment length for changepoint regime detection. |
past_regime_args |
Additional arguments passed to past-trajectory regime detection. |
future_regime_args |
Additional arguments passed to future-trajectory regime detection. |
return_train_probs |
Logical. If |
verbose |
Logical. If |
An object of class craft_fit, represented as a
list containing trajectories, regime models, labels, transition probabilities,
sampled trajectory draws, fitted return and level distributions, diagnostics,
classifier details, optional backtest results, validation metrics, and the information needed by craft_predict(), including trajectory_draws.
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
)
names(fit$return_dists)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.