Skip to main content

StrategyTester

Struct StrategyTester 

Source
pub struct StrategyTester { /* private fields */ }
Expand description

A factory-backed strategy tester, available with ui and strategies.

Call Self::show with completed bars of the chart’s current symbol and interval. Run and optimisation use a snapshot of those bars and yield between execution batches on native and web builds. Host strategy preparation and callbacks must be bounded, as documented on Backtest::run_async. Edits cancel pending work and retain the previous report as stale. History replies are tied to a request id and discarded after an edit or scope change. Give each tester its own egui id scope.

Implementations§

Source§

impl StrategyTester

Source

pub fn new(factory: StrategyFactory) -> Self

Use the built-in catalogue and any constructors the host registered in factory.

Source

pub fn strategy(&self) -> &str

Current strategy name in the factory.

Source

pub fn select_strategy(&mut self, name: &str) -> Result<(), &'static str>

Select a strategy and restore its declared defaults. Unknown names leave the form intact.

Source

pub fn set_input( &mut self, id: &str, value: InputValue, ) -> Result<(), &'static str>

Edit an input through the strategy’s own validation.

Source

pub fn settings(&self) -> &BacktestSettings

Current account and execution assumptions.

Source

pub fn set_settings( &mut self, settings: BacktestSettings, ) -> Result<(), &'static str>

Replace assumptions, cancelling pending work and marking the report stale.

Source

pub fn is_stale(&self) -> bool

Whether the report no longer describes the current form or chart scope.

Source

pub fn report(&self) -> Option<&StrategyReport>

The last completed or host-supplied report.

Source

pub fn set_report(&mut self, report: Option<StrategyReport>, bars: &[Bar])

Replace or clear a host report, cancelling pending work. A host report is not a run of the current form, so it stays stale until Run completes.

Source

pub fn show_report(&mut self, ui: &mut Ui) -> StrategyReportAction

Show only the report, without the tester form, while a host-managed run supplies updates.

Source

pub fn set_history( &mut self, request: &StrategyHistoryRequest, bars: Vec<Bar>, lower: Vec<Bar>, ) -> Result<(), &'static str>

Supply both histories for the exact pending request. A superseded reply is rejected. Empty finer history is refused rather than silently using chart-bar fills.

Source

pub fn history_failed( &mut self, request: &StrategyHistoryRequest, message: impl Into<String>, ) -> bool

Show the host’s failure for the exact pending request. Returns false for a late failure.

Source

pub fn show( &mut self, ui: &mut Ui, symbol: &str, timeframe: Timeframe, bars: &[Bar], ) -> Vec<StrategyTesterAction>

Draw the form, advance pending execution by one batch and return all host intents. Bars must belong to symbol and timeframe; do not include the live, unfinished bar.

Trait Implementations§

Source§

impl Default for StrategyTester

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.