Skip to content

Commit f171001

Browse files
committed
feat: 2F CIR
1 parent e217084 commit f171001

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ The library is organized into several modules, each targeting specific areas of
2525

2626
Planned features and models under development:
2727
- **Barndorff-Nielsen & Shephard Model**: A stochastic volatility model with non-Gaussian Ornstein-Uhlenbeck processes.
28-
- **Multi-factor CIR Model**: Extends the CIR model to multiple factors, providing greater flexibility in interest rate modeling.
2928
- **Brace-Gatarek-Musiela (BGM) Model**: A market model for interest rates, modeling the evolution of forward rates.
3029
- **Wu-Zhang Model**: A stochastic volatility model with jumps in returns and volatility.
3130
- **Affine Models**: A class of models where yields are affine functions of factors, facilitating analytical solutions.

src/stochastic/interest/cir_2f.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use impl_new_derive::ImplNew;
2+
use ndarray::Array1;
3+
4+
use crate::stochastic::Sampling;
5+
6+
use super::cir::CIR;
7+
8+
#[derive(ImplNew)]
9+
pub struct CIR2F {
10+
pub x: CIR,
11+
pub y: CIR,
12+
pub phi: fn(f64) -> f64,
13+
}
14+
15+
impl Sampling<f64> for CIR2F {
16+
fn sample(&self) -> Array1<f64> {
17+
let x = self.x.sample();
18+
let y = self.y.sample();
19+
20+
let dt = self.x.t.unwrap_or(1.0) / (self.n() - 1) as f64;
21+
let phi = Array1::<f64>::from_shape_fn(self.n(), |i| (self.phi)(i as f64 * dt));
22+
23+
x + y * phi
24+
}
25+
26+
fn n(&self) -> usize {
27+
self.x.n()
28+
}
29+
30+
fn m(&self) -> Option<usize> {
31+
self.x.m()
32+
}
33+
}

0 commit comments

Comments
 (0)