pub struct WalkForwardOptimizer { /* private fields */ }Expand description
Walk-forward optimizer: splits bars into rolling train/test windows, runs a grid search on training data, and evaluates the winning parameters on held-out test data.
The strategy factory closure receives the training bar slice and the
candidate parameter HashMap<String, f64>. It should return a
Box<dyn Strategy> initialized with those parameters.
§Example
See the module-level documentation for a complete example.
Implementations§
Source§impl WalkForwardOptimizer
impl WalkForwardOptimizer
Sourcepub fn new(
config: WalkForwardConfig,
bt_config: BacktestConfig,
) -> Result<Self, FinError>
pub fn new( config: WalkForwardConfig, bt_config: BacktestConfig, ) -> Result<Self, FinError>
Sourcepub fn run<F>(
&self,
bars: &[OhlcvBar],
make_strategy: F,
) -> Result<WalkForwardResult, FinError>
pub fn run<F>( &self, bars: &[OhlcvBar], make_strategy: F, ) -> Result<WalkForwardResult, FinError>
Runs the walk-forward optimization.
make_strategy is called once per (parameter combination × window).
It receives:
train_bars: the training slice for fittingparams: aHashMap<String, f64>with the current grid point
It must return a Box<dyn Strategy> configured with params.
§Errors
FinError::InvalidInputifbarsis too short for one window.- Propagates any
FinErrorfrom individual backtest runs.
Sourcepub fn config(&self) -> &WalkForwardConfig
pub fn config(&self) -> &WalkForwardConfig
Returns the configuration.
Sourcepub fn bt_config(&self) -> &BacktestConfig
pub fn bt_config(&self) -> &BacktestConfig
Returns the backtest configuration.
Auto Trait Implementations§
impl Freeze for WalkForwardOptimizer
impl RefUnwindSafe for WalkForwardOptimizer
impl Send for WalkForwardOptimizer
impl Sync for WalkForwardOptimizer
impl Unpin for WalkForwardOptimizer
impl UnsafeUnpin for WalkForwardOptimizer
impl UnwindSafe for WalkForwardOptimizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more