Skip to main content

TrinomialLattice

Struct TrinomialLattice 

Source
pub struct TrinomialLattice {
    pub dt: f64,
    pub dx: f64,
    /* private fields */
}
Expand description

A recombining trinomial lattice over the integer state grid x_j = j * dx (the caller maps j to its own state, e.g. r(i, j) = alpha_i + j * dx for a fitted short-rate tree).

Built from a per-node branching closure, so edge-switching trees (Hull-White clamping) and plain diffusions use the same engine. The per-layer index ranges follow from reachability. Discounting is per nodedf(layer, j) — because for fixed income the short rate lives on the node; equity-style trees pass a constant.

Fields§

§dt: f64§dx: f64

Implementations§

Source§

impl TrinomialLattice

Source

pub fn build( n: usize, dt: f64, dx: f64, branching: &dyn Fn(usize, i32) -> TrinomialBranch, ) -> Result<TrinomialLattice, RustyQLibError>

Build n steps of the lattice from the branching rule. Probabilities are validated per node; targets may shift by at most one index per step (|target - j| <= 1), which keeps the tree recombining.

Source

pub fn steps(&self) -> usize

Source

pub fn layer_range(&self, i: usize) -> (i32, i32)

Node index range (j_min, j_max) of a layer.

Source

pub fn price( &self, node_df: &dyn Fn(usize, i32) -> f64, terminal: &dyn Fn(i32) -> f64, exercise: Option<&dyn Fn(usize, i32, f64) -> f64>, ) -> f64

Backward induction. node_df(i, j) is the one-step discount at the node (state-dependent: e^{-r(i,j) dt} on a short-rate tree); terminal(j) values the final layer; exercise (when given) maps (layer, j, continuation) to the node value.

Source

pub fn arrow_debreu(&self, node_df: &dyn Fn(usize, i32) -> f64) -> Vec<Vec<f64>>

Arrow-Debreu state prices by forward induction: Q[i][j - j_min[i]] is the value today of receiving 1 at node (i, j). The workhorse of short-rate curve fitting — Hull-White’s alpha_i shifts solve sum_j Q[i][j] e^{-(alpha_i + j dx) dt} = P(0, t_{i+1}) layer by layer. sum_j Q[n][j] is the tree’s discount factor to t_n.

Trait Implementations§

Source§

impl Clone for TrinomialLattice

Source§

fn clone(&self) -> TrinomialLattice

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TrinomialLattice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V