diff --git a/src/quant/bonds/cir.rs b/src/quant/bonds/cir.rs index ed8d148..4174e46 100644 --- a/src/quant/bonds/cir.rs +++ b/src/quant/bonds/cir.rs @@ -5,7 +5,7 @@ use crate::quant::r#trait::Price; /// where R(t) is the short rate. #[derive(Default, Debug)] pub struct CIR { - /// Initial short rate + /// Short rate pub r_t: f64, /// Long-term mean of the short rate pub theta: f64, @@ -23,7 +23,16 @@ pub struct CIR { impl Price for CIR { fn price(&self) -> f64 { - todo!() + let tau = self.calculate_tau_in_days(); + + let h = (self.theta.powi(2) + 2.0 * self.sigma.powi(2)).sqrt(); + let A = ((2.0 * h * ((self.theta + h) * (tau / 2.0)).exp()) + / (2.0 * h + (self.theta + h) * ((h * tau).exp() - 1.0))) + .powf((2.0 * self.theta * self.mu) / (self.sigma.powi(2))); + let B = + (2.0 * ((h * tau).exp() - 1.0)) / (2.0 * h + (self.theta + h) * ((h * tau).exp() - 1.0)); + + A * (self.r_t * B).exp() } fn tau(&self) -> Option { diff --git a/src/quant/bonds/vasicek.rs b/src/quant/bonds/vasicek.rs index 53d22b8..398360e 100644 --- a/src/quant/bonds/vasicek.rs +++ b/src/quant/bonds/vasicek.rs @@ -23,9 +23,13 @@ pub struct Vasicek { impl Price for Vasicek { fn price(&self) -> f64 { - // Itt definiálhatod a Vasicek modell árképzési képletét - // Placeholder érték visszaadása - 0.0 + let tau = self.calculate_tau_in_days(); + + let B = (1.0 - (-self.theta * tau).exp()) / self.theta; + let A = (self.mu - (self.sigma.powi(2) / (2.0 * self.theta.powi(2)))) * (B - tau) + - (self.sigma.powi(2) / (4.0 * self.theta)) * B.powi(2); + + (A - B * self.r_t).exp() } fn tau(&self) -> Option {