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
impl StrategyTester
Sourcepub fn new(factory: StrategyFactory) -> Self
pub fn new(factory: StrategyFactory) -> Self
Use the built-in catalogue and any constructors the host registered in factory.
Sourcepub fn select_strategy(&mut self, name: &str) -> Result<(), &'static str>
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.
Sourcepub fn set_input(
&mut self,
id: &str,
value: InputValue,
) -> Result<(), &'static str>
pub fn set_input( &mut self, id: &str, value: InputValue, ) -> Result<(), &'static str>
Edit an input through the strategy’s own validation.
Sourcepub fn settings(&self) -> &BacktestSettings
pub fn settings(&self) -> &BacktestSettings
Current account and execution assumptions.
Sourcepub fn set_settings(
&mut self,
settings: BacktestSettings,
) -> Result<(), &'static str>
pub fn set_settings( &mut self, settings: BacktestSettings, ) -> Result<(), &'static str>
Replace assumptions, cancelling pending work and marking the report stale.
Sourcepub fn is_stale(&self) -> bool
pub fn is_stale(&self) -> bool
Whether the report no longer describes the current form or chart scope.
Sourcepub fn report(&self) -> Option<&StrategyReport>
pub fn report(&self) -> Option<&StrategyReport>
The last completed or host-supplied report.
Sourcepub fn set_report(&mut self, report: Option<StrategyReport>, bars: &[Bar])
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.
Sourcepub fn show_report(&mut self, ui: &mut Ui) -> StrategyReportAction
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.
Sourcepub fn set_history(
&mut self,
request: &StrategyHistoryRequest,
bars: Vec<Bar>,
lower: Vec<Bar>,
) -> Result<(), &'static str>
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.
Sourcepub fn history_failed(
&mut self,
request: &StrategyHistoryRequest,
message: impl Into<String>,
) -> bool
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.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for StrategyTester
impl !Send for StrategyTester
impl !Sync for StrategyTester
impl !UnwindSafe for StrategyTester
impl Freeze for StrategyTester
impl Unpin for StrategyTester
impl UnsafeUnpin for StrategyTester
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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