trajectory_reframer: Build Lag or Lead Trajectory Features for One Series

View source: R/trajectory-embedding.R

trajectory_reframerR Documentation

Build Lag or Lead Trajectory Features for One Series

Description

Creates cumulative scaled lag or lead trajectory features for a single time series. For a backward trajectory, horizon h at time t is x[t] / x[t - h] - 1. For a forward trajectory, horizon h is x[t + h] / x[t] - 1.

Usage

trajectory_reframer(ts, k, mode = c("backward", "forward"), ts_name = NULL)

Arguments

ts

A numeric vector or time-series-like object.

k

Positive integer number of lag or lead horizons to create.

mode

Direction of the trajectory. "backward" creates cumulative lag changes; "forward" creates cumulative lead changes.

ts_name

Optional name used as the prefix for output columns.

Value

An object of class trajectory_reframer, represented as a list with trajectory, ts, k, and mode.

Examples

x <- c(100, 102, 105, 103, 108)
traj <- trajectory_reframer(x, k = 2, mode = "backward", ts_name = "price")
head(traj$trajectory)

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