Skip to main content

optionstratlib_simulation/error/
quadratic_rough_heston.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 6/11/26
5******************************************************************************/
6
7//! Target crate (ADR-0001 D6): **simulation**. Owns `QuadraticRoughHestonError`.
8
9use optionstratlib_core::error::DecimalError;
10use rust_decimal::Decimal;
11use thiserror::Error;
12
13/// Reasons why a quadratic rough Heston kernel, simulation or price cannot be produced.
14///
15/// Raised by the constructors and functions around
16/// [`QuadraticRoughHestonParams`](crate::simulation::QuadraticRoughHestonParams).
17#[derive(Error, Debug)]
18#[non_exhaustive]
19pub enum QuadraticRoughHestonError {
20    /// The roughness exponent `alpha` is outside the open interval `(1/2, 1)`.
21    #[error("alpha {alpha} is outside the open interval (1/2, 1)")]
22    AlphaOutOfRange {
23        /// The rejected exponent.
24        alpha: Decimal,
25    },
26
27    /// The kernel was asked for no factors.
28    #[error("the kernel needs at least one factor")]
29    NoFactors,
30
31    /// The geometric ratio `x_n` of the partition is not above one.
32    #[error("the geometric ratio {ratio} is not above one")]
33    RatioNotAboveOne {
34        /// The rejected ratio.
35        ratio: Decimal,
36    },
37
38    /// A kernel weight or discount has no positive value in a `Decimal`: it overflows,
39    /// or it is smaller than the resolution of `1e-28`.
40    #[error("the kernel {quantity} of factor {index} has no positive value in a decimal")]
41    KernelOutOfRange {
42        /// `weight` or `discount`.
43        quantity: &'static str,
44        /// The factor, from 1 to the number of factors.
45        index: usize,
46    },
47
48    /// The time step is not positive: the horizon is not above zero, there are no steps,
49    /// or the step rounds to zero in a `Decimal`.
50    #[error("the step of a horizon of {horizon} years over {steps} steps is not positive")]
51    NonPositiveStep {
52        /// The horizon, in years.
53        horizon: Decimal,
54        /// The number of steps.
55        steps: usize,
56    },
57
58    /// A model or run parameter is outside its domain.
59    #[error("invalid parameter {parameter} = {value}: {reason}")]
60    InvalidParameter {
61        /// The rejected parameter.
62        parameter: &'static str,
63        /// The rejected value.
64        value: Decimal,
65        /// The condition the value breaks.
66        reason: &'static str,
67    },
68
69    /// The number of initial factors is not the number of factors of the kernel.
70    #[error("expected {expected} initial factors, got {actual}")]
71    InitialFactorCount {
72        /// The factors of the kernel.
73        expected: usize,
74        /// The initial factors supplied.
75        actual: usize,
76    },
77
78    /// A value of the simulated state stopped being finite. The variance is not truncated,
79    /// so this is how an exploding path is reported.
80    #[error("the simulated {quantity} is not finite at step {step}")]
81    NonFinite {
82        /// `spot`, `z` or `variance`.
83        quantity: &'static str,
84        /// The step of the grid, from 1 to its number of steps.
85        step: usize,
86    },
87
88    /// A buffer of the requested size cannot be allocated.
89    #[error("cannot allocate {len} entries for the {buffer}")]
90    BufferTooLarge {
91        /// What the buffer holds.
92        buffer: &'static str,
93        /// The entries requested.
94        len: usize,
95    },
96
97    /// A value does not fit a `Decimal`, or `Decimal` arithmetic failed.
98    #[error(transparent)]
99    Decimal(#[from] DecimalError),
100}