pub struct TermLattice {
pub times: Vec<f64>,
pub dx: f64,
pub p_up: Vec<f64>,
pub df: Vec<f64>,
}Expand description
A recombining binomial lattice under time-dependent parameters: term structures of rates, carry and volatility applied directly on the tree.
Construction (the standard variance-grid method):
- The time grid is warped so every step accrues equal variance
w = V(T)/n, whereV(t)is the cumulative variance supplied by the caller. Fixed log-spacingdx = sqrt(w)then keeps the tree recombining even though volatility varies with time. - Each step’s drift is matched exactly by a per-step probability from the forward rate and carry over that step, and each step discounts with its own forward discount factor.
So flat inputs reduce to the classic CRR tree, while curved inputs reprice the exact term structure: for a European payoff the tree converges to Black-Scholes with the equivalent average variance and the curve’s exact discount factor.
Fields§
§times: Vec<f64>Layer times t_0 = 0 .. t_n = T (unequal spacing in general).
dx: f64Fixed log-spacing between adjacent nodes.
p_up: Vec<f64>Per-step up-probability (drift-matched from the forward rates).
df: Vec<f64>Per-step discount factor (forward rate over the step).
Implementations§
Source§impl TermLattice
impl TermLattice
Sourcepub fn build(
n: usize,
t: f64,
forward_rate: &dyn Fn(f64, f64) -> f64,
forward_carry: &dyn Fn(f64, f64) -> f64,
total_variance: &dyn Fn(f64) -> f64,
) -> Result<TermLattice, RustyQLibError>
pub fn build( n: usize, t: f64, forward_rate: &dyn Fn(f64, f64) -> f64, forward_carry: &dyn Fn(f64, f64) -> f64, total_variance: &dyn Fn(f64) -> f64, ) -> Result<TermLattice, RustyQLibError>
Build the grid for n steps over [0, t].
forward_rate(t1, t2): continuously compounded forward rate over the step (from a discount curve:ln(df(t1)/df(t2)) / (t2 - t1)).forward_carry(t1, t2): forward dividend + borrow yield over the step; the drift per step israte - carry.total_variance(t): cumulative variancesigma(t)^2 * t(or an integral of instantaneous variance); must be strictly increasing — a calendar-arbitrage-free vol term structure.
pub fn steps(&self) -> usize
Sourcepub fn price(
&self,
s0: f64,
terminal: &dyn Fn(f64) -> f64,
exercise: Option<&dyn Fn(usize, f64, f64, f64) -> f64>,
) -> f64
pub fn price( &self, s0: f64, terminal: &dyn Fn(f64) -> f64, exercise: Option<&dyn Fn(usize, f64, f64, f64) -> f64>, ) -> f64
Backward induction on the rolling array with per-step
probabilities and discounting. The early-exercise closure receives
(step, time, spot, continuation) — time-aware because the layer
times are unequal.
Sourcepub fn price_with_greeks(
&self,
s0: f64,
terminal: &dyn Fn(f64) -> f64,
exercise: Option<&dyn Fn(usize, f64, f64, f64) -> f64>,
) -> LatticeSolution
pub fn price_with_greeks( &self, s0: f64, terminal: &dyn Fn(f64) -> f64, exercise: Option<&dyn Fn(usize, f64, f64, f64) -> f64>, ) -> LatticeSolution
The same induction as price (identical price, bit
for bit) keeping the first two layers, so the value and the tree
delta/gamma/theta come out of one pass. The log-grid is symmetric,
so the second-layer center returns exactly to s0 and theta needs
no drift correction; the elapsed time is the grid’s own times[2]
(the layer times are unequal).
Trait Implementations§
Source§impl Clone for TermLattice
impl Clone for TermLattice
Source§fn clone(&self) -> TermLattice
fn clone(&self) -> TermLattice
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more