Skip to main content

WalkForwardOptimizer

Struct WalkForwardOptimizer 

Source
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

Source

pub fn new( config: WalkForwardConfig, bt_config: BacktestConfig, ) -> Result<Self, FinError>

Constructs a new optimizer.

§Errors

Returns FinError::InvalidInput if the config is invalid.

Source

pub fn run<F>( &self, bars: &[OhlcvBar], make_strategy: F, ) -> Result<WalkForwardResult, FinError>
where F: FnMut(&[OhlcvBar], &HashMap<String, f64>) -> Box<dyn Strategy>,

Runs the walk-forward optimization.

make_strategy is called once per (parameter combination × window). It receives:

  • train_bars: the training slice for fitting
  • params: a HashMap<String, f64> with the current grid point

It must return a Box<dyn Strategy> configured with params.

§Errors
Source

pub fn config(&self) -> &WalkForwardConfig

Returns the configuration.

Source

pub fn bt_config(&self) -> &BacktestConfig

Returns the backtest configuration.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.