| roll_fit_predict_seq | R Documentation |
Rolling fit/predict for sequence models (flattened steps-by-p features)
roll_fit_predict_seq(
features_list,
labels,
steps = 26L,
horizon = 4L,
fit_fn,
predict_fn,
is_periods = 156L,
oos_periods = 4L,
step = 4L,
group = c("pooled", "per_symbol", "per_group"),
group_map = NULL,
normalize = c("none", "zscore", "minmax"),
min_train_samples = 50L,
na_action = c("omit", "zero")
)
features_list |
list of panels to be stacked over |
labels |
future-return panel aligned to the features. |
steps |
int; lookback length (e.g., 26). |
horizon |
int; label horizon (e.g., 4). |
fit_fn |
function |
predict_fn |
function |
is_periods, oos_periods, step |
ints; in-sample length, out-of-sample length, and step size for the rolling window. |
group |
one of |
group_map |
optional |
normalize |
|
min_train_samples |
Optional minimum IS samples required to fit; if not met, skip fit. |
na_action |
|
wide panel of scores.
data(sample_prices_weekly); data(sample_prices_daily)
mom <- panel_lag(calc_momentum(sample_prices_weekly, 12), 1)
vol <- panel_lag(align_to_timeframe(
calc_rolling_volatility(sample_prices_daily, 20),
sample_prices_weekly$Date, "forward_fill"), 1)
Y <- make_labels(sample_prices_weekly, horizon = 4, type = "log")
fit_lm <- function(X,y){ Xc <- cbind(1,X); list(coef=stats::lm.fit(Xc,y)$coefficients) }
pred_lm <- function(m,X){ as.numeric(cbind(1,X) %*% m$coef) }
S <- roll_fit_predict_seq(list(mom=mom, vol=vol), Y,
steps = 26, horizon = 4,
fit_fn = fit_lm, predict_fn = pred_lm,
is_periods = 104, oos_periods = 4, step = 4)
head(S)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.