use crate::error::{DecimalError, StrategyError};
use crate::prelude::GraphError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum SimulationError {
#[error("Walk generation failed: {reason}")]
WalkError {
reason: String,
},
#[error("Invalid simulation parameters: {reason}")]
InvalidParameters {
reason: String,
},
#[error("Step calculation failed: {reason}")]
StepError {
reason: String,
},
#[error("Simulation error: {reason}")]
OtherError {
reason: String,
},
#[error(transparent)]
GraphError(#[from] GraphError),
#[error(transparent)]
PositiveError(#[from] positive::PositiveError),
}
impl SimulationError {
pub fn walk_error(reason: &str) -> Self {
SimulationError::WalkError {
reason: reason.to_string(),
}
}
pub fn invalid_parameters(reason: &str) -> Self {
SimulationError::InvalidParameters {
reason: reason.to_string(),
}
}
pub fn step_error(reason: &str) -> Self {
SimulationError::StepError {
reason: reason.to_string(),
}
}
pub fn other(reason: &str) -> Self {
SimulationError::OtherError {
reason: reason.to_string(),
}
}
}
impl From<Box<dyn std::error::Error>> for SimulationError {
fn from(err: Box<dyn std::error::Error>) -> Self {
SimulationError::OtherError {
reason: err.to_string(),
}
}
}
impl From<String> for SimulationError {
fn from(s: String) -> Self {
SimulationError::OtherError { reason: s }
}
}
impl From<&str> for SimulationError {
fn from(s: &str) -> Self {
SimulationError::OtherError {
reason: s.to_string(),
}
}
}
impl From<DecimalError> for SimulationError {
fn from(err: DecimalError) -> Self {
SimulationError::OtherError {
reason: err.to_string(),
}
}
}
impl From<crate::error::OptionsError> for SimulationError {
fn from(err: crate::error::OptionsError) -> Self {
SimulationError::OtherError {
reason: err.to_string(),
}
}
}
impl From<crate::error::PricingError> for SimulationError {
fn from(err: crate::error::PricingError) -> Self {
SimulationError::OtherError {
reason: err.to_string(),
}
}
}
impl From<expiration_date::error::ExpirationDateError> for SimulationError {
fn from(err: expiration_date::error::ExpirationDateError) -> Self {
SimulationError::OtherError {
reason: err.to_string(),
}
}
}
impl From<StrategyError> for SimulationError {
fn from(err: StrategyError) -> Self {
SimulationError::OtherError {
reason: err.to_string(),
}
}
}
pub type SimulationResult<T> = Result<T, SimulationError>;