Skip to main content

BacktestModel

Trait BacktestModel 

Source
pub trait BacktestModel {
    type Event;
    type State: Clone;
    type Action: Clone;

    // Required methods
    fn initial_state(&self) -> Self::State;
    fn initial_value(&self, state: &Self::State) -> f64;
    fn timestamp(&self, event: &Self::Event) -> i64;
    fn decide(
        &mut self,
        event: &Self::Event,
        state: &Self::State,
    ) -> Result<Vec<Self::Action>, String>;
    fn apply(
        &mut self,
        event: &Self::Event,
        action: &Self::Action,
        state: &mut Self::State,
    ) -> Result<(), String>;
    fn value(&self, event: &Self::Event, state: &Self::State) -> f64;
}
Expand description

Product-supplied deterministic replay behavior.

Required Associated Types§

Source

type Event

Historical input event type.

Source

type State: Clone

Replay state carried between events.

Source

type Action: Clone

Decision produced by the model.

Required Methods§

Source

fn initial_state(&self) -> Self::State

State before the first event.

Source

fn initial_value(&self, state: &Self::State) -> f64

Starting value used for return and drawdown.

Source

fn timestamp(&self, event: &Self::Event) -> i64

Monotonic timestamp of an event.

Source

fn decide( &mut self, event: &Self::Event, state: &Self::State, ) -> Result<Vec<Self::Action>, String>

Produce decisions from the current event and pre-transition state.

Source

fn apply( &mut self, event: &Self::Event, action: &Self::Action, state: &mut Self::State, ) -> Result<(), String>

Apply one decision. The model owns domain-specific transition rules.

Source

fn value(&self, event: &Self::Event, state: &Self::State) -> f64

Mark the state after all actions for the event have been applied.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§