1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/******************************************************************************
Author: Joaquín Béjar García
Email: jb@taunais.com
Date: 11/8/24
******************************************************************************/
use Positive;
use Decimal;
use dec;
/// Mathematical constant representing π (pi) with high precision using Decimal type.
/// Used for circular calculations, angle conversions, and geometric computations.
pub const PI: Decimal = dec!;
/// Represents zero as a 64-bit floating point number.
/// Used as a baseline value for numerical comparisons and calculations.
pub const ZERO: f64 = 0.0;
/// Small decimal value used as a threshold for convergence tests and equality comparisons.
/// Represents a general tolerance level for numerical algorithms.
pub const TOLERANCE: Decimal = dec!;
/// Extremely small decimal value used for high-precision calculations.
/// Represents the smallest meaningful difference in numerical computations.
pub const EPSILON: Decimal = dec!;
/// Minimum allowed volatility value as a Positive decimal.
/// Prevents numerical issues in financial calculations with near-zero volatility.
pub const MIN_VOLATILITY: Positive = unsafe ;
/// Maximum allowed volatility value as a Positive decimal (100%).
/// Sets an upper bound for volatility inputs in financial models.
pub const MAX_VOLATILITY: Positive = HUNDRED;
/// Multiplier defining the lower bound for strike price ranges (98% of reference price).
/// Used to establish the minimum strike price in option chains or pricing models.
pub const STRIKE_PRICE_LOWER_BOUND_MULTIPLIER: f64 = 0.98;
/// Multiplier defining the upper bound for strike price ranges (102% of reference price).
/// Used to establish the maximum strike price in option chains or pricing models.
pub const STRIKE_PRICE_UPPER_BOUND_MULTIPLIER: f64 = 1.02;
/// Standard number of trading days in a year as a Positive decimal.
/// Used for business day-based financial calculations.
pub const TRADING_DAYS: Positive = unsafe ;
/// Standard number of trading hours in a market day as a Positive decimal.
/// Typically represents a standard U.S. market session (9:30 AM to 4:00 PM).
pub const TRADING_HOURS: Positive = unsafe ;
/// Number of seconds in an hour as a Positive decimal value.
/// Used for time-based conversions and calculations.
pub const SECONDS_PER_HOUR: Positive = unsafe ;
/// Number of minutes in an hour as a Positive decimal value.
/// Used for time-based conversions and calculations.
pub const MINUTES_PER_HOUR: Positive = unsafe ;
/// Number of milliseconds in a second as a Positive decimal value.
/// Used for precise time measurements and conversions.
pub const MILLISECONDS_PER_SECOND: Positive =
unsafe ;
/// Number of microseconds in a second as a Positive decimal value.
/// Used for high-precision time measurements and conversions.
pub const MICROSECONDS_PER_SECOND: Positive =
unsafe ;
/// Standard number of weeks in a year as a Positive decimal value.
/// Used for time-based financial calculations and annualization.
pub const WEEKS_PER_YEAR: Positive = unsafe ;
/// Number of months in a year as a Positive decimal value.
/// Used for monthly-based financial calculations and conversions.
pub const MONTHS_PER_YEAR: Positive = unsafe ;
/// Number of quarters in a year as a Positive decimal value.
/// Used for quarterly financial calculations and reporting periods.
pub const QUARTERS_PER_YEAR: Positive = unsafe ;
/// Maximum number of iterations for implied volatility calculation algorithms.
/// Prevents infinite loops in numerical methods like Newton-Raphson or bisection.
pub const MAX_ITERATIONS_IV: u32 = 1000;
/// Convergence tolerance for implied volatility calculations.
/// Determines when the implied volatility solver has reached sufficient precision.
pub const IV_TOLERANCE: Decimal = dec!;