Skip to main content

StochasticDifferentialEquation

Struct StochasticDifferentialEquation 

Source
pub struct StochasticDifferentialEquation;
Expand description

SDE solver for dX = mu(X,t)dt + sigma(X,t)dW.

Implementations§

Source§

impl StochasticDifferentialEquation

Source

pub fn euler_maruyama<F, G>( mu: F, sigma: G, x0: f64, t0: f64, t_end: f64, n_steps: usize, seed: u64, ) -> (Vec<f64>, Vec<f64>)
where F: Fn(f64, f64) -> f64, G: Fn(f64, f64) -> f64,

Euler-Maruyama scheme: X_{n+1} = X_n + mu(X_n, t_n)*dt + sigma(X_n, t_n)*sqrt(dt)*Z.

Strong order 0.5, weak order 1.0.

Source

pub fn milstein<F, G, H>( mu: F, sigma: G, sigma_prime: H, x0: f64, t0: f64, t_end: f64, n_steps: usize, seed: u64, ) -> (Vec<f64>, Vec<f64>)
where F: Fn(f64, f64) -> f64, G: Fn(f64, f64) -> f64, H: Fn(f64, f64) -> f64,

Milstein scheme: adds a correction term for higher strong order (1.0).

X_{n+1} = X_n + mudt + sigmadW + 0.5sigmasigma’*(dW^2 - dt). sigma_prime is the derivative of sigma with respect to x.

Source

pub fn runge_kutta_maruyama<F, G>( mu: F, sigma: G, x0: f64, t0: f64, t_end: f64, n_steps: usize, seed: u64, ) -> (Vec<f64>, Vec<f64>)
where F: Fn(f64, f64) -> f64, G: Fn(f64, f64) -> f64,

Runge-Kutta (Runge-Kutta-Maruyama) order 1 scheme for Ito SDEs.

Uses a predictor step to estimate the diffusion coefficient more accurately.

Source

pub fn monte_carlo_paths<F, G>( mu: F, sigma: G, x0: f64, t0: f64, t_end: f64, n_steps: usize, n_paths: usize, seed: u64, ) -> Vec<Vec<f64>>
where F: Fn(f64, f64) -> f64 + Clone, G: Fn(f64, f64) -> f64 + Clone,

Simulate multiple paths (Monte Carlo ensemble).

Returns a matrix of shape (n_paths, n_steps+1).

Source

pub fn strong_error_estimate<F, G>( mu: F, sigma: G, x0: f64, t0: f64, t_end: f64, seed: u64, n_steps_coarse: usize, n_steps_fine: usize, ) -> f64
where F: Fn(f64, f64) -> f64 + Clone, G: Fn(f64, f64) -> f64 + Clone,

Compute the strong order of convergence from a reference solution.

Returns the estimated strong error at the terminal time.

Source

pub fn weak_order_estimate<F, G, H>( mu: F, sigma: G, functional: H, x0: f64, t0: f64, t_end: f64, n_steps: usize, n_paths: usize, seed: u64, ) -> f64
where F: Fn(f64, f64) -> f64 + Clone, G: Fn(f64, f64) -> f64 + Clone, H: Fn(f64) -> f64,

Compute the weak order of convergence via expected value of a functional.

Returns E[f(X(T))] estimated from n_paths Monte Carlo paths.

Source

pub fn stratonovich_to_ito<G, H>( strat_mu: f64, sigma_val: f64, sigma_prime: f64, _sigma: G, _sigma_p: H, ) -> f64
where G: Fn(f64, f64) -> f64, H: Fn(f64, f64) -> f64,

Stratonovich to Ito conversion: add the correction term -0.5sigmasigma’.

Returns the Ito drift given the Stratonovich drift and diffusion.

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.