Skip to main content

rustrade_backtest/
error.rs

1//! Errors specific to the backtest engine.
2
3/// Result alias used throughout `rustrade-backtest`.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Backtest-engine error type.
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9    /// Configuration was missing a required field or had an invalid value.
10    #[error("backtest configuration error: {0}")]
11    Config(String),
12
13    /// Candle data was structurally valid but contained an unusable value
14    /// — a non-finite (`NaN`/`±inf`) or negative OHLCV field. Caught at
15    /// load time and at the start of [`crate::Backtest::run`] so a single
16    /// bad row can't silently poison the equity curve and metrics.
17    #[error("invalid candle data: {0}")]
18    Data(String),
19
20    /// The `Brain` returned an error while processing a candle.
21    #[error("brain error during backtest: {0}")]
22    Brain(String),
23
24    /// An invariant inside the engine was violated. These are bugs —
25    /// please file an issue.
26    #[error("internal backtest error: {0}")]
27    Internal(String),
28}
29
30impl From<rustrade_core::Error> for Error {
31    fn from(e: rustrade_core::Error) -> Self {
32        Self::Brain(e.to_string())
33    }
34}