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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// MATHEMATICS MODULE
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//! Mathematics related items.
//!
//! ### Optimization and Root Finding
//!
//! - [x] Gradient Descent
//! - [x] Newton-Raphson
//!
//! Note: the reason you need to specify the lifetimes and use the type `Variable` is because the gradient descent optimiser uses the `RustQuant::autodiff` module to compute the gradients. This is a slight inconvenience, but the speed-up is enormous when working with functions with many inputs (when compared with using finite-difference quotients).
//!
//! ```rust
//! use RustQuant::math::*;
//! use RustQuant::autodiff::*;
//!
//! // Define the objective function.
//! fn himmelblau<'v>(variables: &[Variable<'v>]) -> Variable<'v> {
//! let x = variables[0];
//! let y = variables[1];
//!
//! ((x.powf(2.0) + y - 11.0).powf(2.0) + (x + y.powf(2.0) - 7.0).powf(2.0))
//! }
//!
//! // Create a new GradientDescent object with:
//! // - Step size: 0.005
//! // - Iterations: 10000
//! // - Tolerance: sqrt(machine epsilon)
//! let gd = GradientDescent::new(0.005, 10000, Some(std::f64::EPSILON.sqrt()));
//!
//! // Perform the optimisation with:
//! // - Initial guess (10.0, 10.0),
//! // - Verbose output.
//! let result = gd.optimize(&himmelblau, &vec![10.0, 10.0], true);
//!
//! // Print the result.
//! println!("{:?}", result.minimizer);
//! ```
//!
//! ### Integration
//!
//! - Numerical Integration (needed for Heston model, for example):
//! - [x] Tanh-Sinh (double exponential) quadrature
//!
//! ```rust
//! use RustQuant::math::*;
//!
//! // Define a function to integrate: e^(sin(x))
//! fn f(x: f64) -> f64 {
//! (x.sin()).exp()
//! }
//!
//! // Integrate from 0 to 5.
//! let integral = integrate(f, 0.0, 5.0);
//!
//! // ~ 7.18911925
//! println!("Integral = {}", integral);
//! ```
//!
//! ### Risk-Reward Metrics
//!
//! - [x] Risk-Reward Measures (Sharpe, Treynor, Sortino, etc)
/// Statistical distributions.
pub use *;
/// Numerical integration routines.
/// The primary (useful) integrator is the Tanh-Sinh (double exponential) implementation.
pub use *;
/// Numerical optimization and root-finding routines.
pub use *;
/// Fast fourier transform.
pub use *;
/// Interpolation routines.
pub use *;
/// Simple risk/reward measures.
pub use *;
/// Root-finding routines.
pub use *;
/// Sequences of numbers and associated functions.
pub use *;
/// Statistic trait.
pub use *;