Skip to main content

walk_steps

Function walk_steps 

Source
pub fn walk_steps<Y, E, F>(
    walk_params: &WalkParams<Positive, Y>,
    next_y: F,
) -> Result<Vec<Step<Positive, Y>>, E>
Expand description

Runs a walk and materializes it as a vector of Steps, delegating the construction of each y-value to next_y.

This is the shared driver behind generator_positive and, behind the synthetic feature, optionstratlib_market::chains::generator_optionchain and optionstratlib_market::series::generator_optionseries.

§Contract

  • The returned vector always starts with walk_params.init_step.
  • If the walker yields no values beyond the initial one (e.g. a size-1 walk), only the initial step is returned.
  • The walk is truncated when the x-step reaches expiration (SimulationError::ExpirationReached) or when next_y returns Ok(None); any other step-advance error is propagated.
  • The result is truncated to at most walk_params.size steps.
  • With walk_params.seed set, the path, and therefore the result for a pure next_y, is identical on every run (see WalkParams); walk_steps_par returns the same steps.

§Parameters

  • walk_params - The walk configuration; walk_params.walk_type selects the stochastic process via crate::simulation::WalkTypeAble::generate_with_vol.
  • next_y - Builds the y-value for one step from (new_price, step_volatility, advanced_x_step). Returning Ok(None) ends the walk gracefully at the previous step.

§Volatility

The volatility passed to next_y is per-step wherever the model provides one: the simulated vol path for stochastic-volatility walk types (Garch, Heston, Custom, Telegraph), an expanding-window estimate free of look-ahead bias for Historical walks, and the walk type’s constant volatility parameter otherwise.

§Returns

  • Ok(Vec<Step<Positive, Y>>) - The simulated walk.
  • Err(E) - If the walker, the volatility estimation, the x-step advance, or next_y fail.

§Errors

The driver is generic over its error type: every internal failure is a SimulationError lifted into E via From, so the simulation layer carries no chain-specific error types — the chain and series generators simply instantiate E = ChainError. Walker errors include SimulationError::InsufficientHistoricalData when a Historical walk has fewer prices than walk_params.size; next_y errors are returned verbatim.