tensorquant.models package

Submodules

tensorquant.models.brownian module

class tensorquant.models.brownian.ArithmeticBrownianMotion(mu, sigma, x0)[source]

Bases: StochasticProcess

diffusion(dt)[source]

Computes the diffusion term of the process, which represents the stochastic component (volatility).

Parameters:
  • t0 (float) – The current time.

  • x0 (float or numpy array) – The current value(s) of the process.

  • dt (float) – The time increment.

Returns:

The diffusion (volatility) term at time t0.

Return type:

float or numpy array

drift(dt)[source]

Computes the drift term of the process, which represents the deterministic trend.

Parameters:
  • t0 (float) – The current time.

  • x0 (float or numpy array) – The current value(s) of the process.

  • dt (float) – The time increment.

Returns:

The drift term at time t0 for the process.

Return type:

float or numpy array

evolve(t_grid, dw)[source]
Parameters:
  • t_grid – 1D tensor of shape [n_steps] with observation times, e.g. [0.25, 0.5, 0.75, 1.0]

  • dw – tensor of shape [n_paths, n_steps], standard normals

Returns:

tensor of shape [n_paths, n_steps] with simulated process values

initial_values()[source]

Returns the initial values of the process.

Returns:

The initial value(s) of the process.

Return type:

float or numpy array

size()[source]

Returns the number of dimensions of the process.

Returns:

The number of dimensions (or factors) of the stochastic process.

Return type:

int

class tensorquant.models.brownian.GeometricBrownianMotion(mu, sigma, x0)[source]

Bases: StochasticProcess

diffusion(dt)[source]

Computes the diffusion term of the process, which represents the stochastic component (volatility).

Parameters:
  • t0 (float) – The current time.

  • x0 (float or numpy array) – The current value(s) of the process.

  • dt (float) – The time increment.

Returns:

The diffusion (volatility) term at time t0.

Return type:

float or numpy array

drift(dt)[source]

Computes the drift term of the process, which represents the deterministic trend.

Parameters:
  • t0 (float) – The current time.

  • x0 (float or numpy array) – The current value(s) of the process.

  • dt (float) – The time increment.

Returns:

The drift term at time t0 for the process.

Return type:

float or numpy array

evolve(t_grid, dw)[source]
Parameters:
  • t_grid – 1D tensor of shape [n_steps] with observation times, e.g. [0.25, 0.5, 0.75, 1.0]

  • dw – tensor of shape [n_paths, n_steps], standard normals

Returns:

tensor of shape [n_paths, n_steps] with simulated process values

initial_values()[source]

Returns the initial values of the process.

Returns:

The initial value(s) of the process.

Return type:

float or numpy array

size()[source]

Returns the number of dimensions of the process.

Returns:

The number of dimensions (or factors) of the stochastic process.

Return type:

int

tensorquant.models.hullwhite module

class tensorquant.models.hullwhite.HullWhiteProcess(term_structure: RateCurve, a: float, sigma: float)[source]

Bases: StochasticProcess

Hull-White interest rate model class, which models the evolution of short rates under a mean-reverting stochastic process.

_process

Ornstein-Uhlenbeck process to simulate the short rate evolution.

Type:

OrnsteinUhlenbeckProcess

_a

Mean reversion speed (alpha).

Type:

tf.Variable

_sigma

Volatility of the process (sigma).

Type:

tf.Variable

_term_structure

The term structure (yield curve) used for forward rate calculations.

Type:

RateCurve

A_B(S: float, T: float) tuple[source]

Computes the time-dependent parameters A(S, T) and B(S, T) of a zero-coupon bond.

Parameters:
  • S (float) – Start time in years (S <= T).

  • T (float) – Maturity time in years.

Returns:

A(S, T) and B(S, T) parameters used in bond pricing.

Return type:

tuple

property a: float

Mean reversion speed (alpha) of the process.

Returns:

The mean reversion speed.

Return type:

float

alpha(t: float) float[source]

Computes the alpha (mean reversion level) term at time t.

Parameters:

t (float) – The time at which alpha is calculated.

Returns:

The alpha value.

Return type:

float

diffusion(t: float, x: float) float[source]

Calculates the diffusion term of the process.

Parameters:
  • t (float) – Current time.

  • x (float) – Current value of the process.

Returns:

The diffusion value.

Return type:

float

drift(t: float, x: float) float[source]

Calculates the drift term of the process.

Parameters:
  • t (float) – Current time.

  • x (float) – Current value of the process.

Returns:

The drift value.

Return type:

float

expectation(t0: float, x0: float, dt: float) float[source]

Computes the expectation of the process over time interval dt.

Parameters:
  • t0 (float) – Start time of the interval.

  • x0 (float) – Initial value of the process at time t0.

  • dt (float) – Time increment.

Returns:

The expected value of the process at time t0 + dt.

Return type:

float

initial_values() float[source]

Returns the initial value of the short rate.

Returns:

The initial value of the short rate (x0).

Return type:

float

property sigma: float

Volatility (sigma) of the process.

Returns:

The volatility of the process.

Return type:

float

size() int[source]

Returns the dimensionality of the process.

Returns:

The dimensionality (size) of the underlying process.

Return type:

int

std_deviation(dt: float, t0=None, x0=None) float[source]

Returns the standard deviation of the process over the time interval dt.

Parameters:
  • dt (float) – Time increment.

  • t0 (float, optional) – Interface placeholder for starting time (default is None).

  • x0 (float, optional) – Interface placeholder for starting value (default is None).

Returns:

The standard deviation of the process.

Return type:

float

variance(dt: float) float[source]

Returns the variance of the process over the time interval dt.

Parameters:

dt (float) – Time increment.

Returns:

The variance of the process.

Return type:

float

property x0: float

Initial value of the process.

Returns:

The initial short rate (x0).

Return type:

float

zero_bond(S: float, T: float, rs: float) float[source]

Computes the price of a zero-coupon bond at future time S with maturity T.

Parameters:
  • S (float) – Future reference time in years.

  • T (float) – Maturity time in years.

  • rs (float) – Short rate at time S.

Returns:

Price of the zero-coupon bond.

Return type:

float

tensorquant.models.ornsteinuhlenbeck module

class tensorquant.models.ornsteinuhlenbeck.OrnsteinUhlenbeckProcess(mr_speed, volatility, x0=0.0, level=0.0)[source]

Bases: StochasticProcess

Ornstein-Uhlenbeck process class for modeling mean-reverting stochastic processes.

This class represents an Ornstein-Uhlenbeck process, which is a type of mean-reverting stochastic process. It is defined by its mean reversion speed, volatility, initial value, and long-term mean level.

mr_speed

The speed of mean reversion.

Type:

float

volatility

The volatility of the process.

Type:

float

x0

The initial value of the process. Defaults to 0.0.

Type:

float, optional

level

The long-term mean level of the process. Defaults to 0.0.

Type:

float, optional

diffusion() Tensor[source]

Returns the diffusion term of the process.

Returns:

The diffusion term (volatility) of the process.

Return type:

tensorflow.Tensor

drift(x: Tensor) Tensor[source]

Calculates the drift term of the process.

Parameters:

x (tensorflow.Tensor) – The current value of the process.

Returns:

The drift term.

Return type:

tensorflow.Tensor

expectation(x0: float, dt: float, t0=None) Tensor[source]

Calculates the expected value of the process after a time step.

Parameters:
  • x0 (float) – The initial value of the process.

  • dt (float) – The time step.

  • t0 (float, optional) – The initial time. Defaults to None.

Returns:

The expected value of the process at time t0 + dt.

Return type:

tensorflow.Tensor

initial_values()[source]

Returns the initial values of the process.

Returns:

The initial value of the process.

Return type:

float

property level

Returns the long-term mean level of the process.

Returns:

The long-term mean level of the process.

Return type:

float

property mr_speed

Returns the speed of mean reversion.

Returns:

The speed of mean reversion.

Return type:

float

size()[source]

Returns the size of the state space.

Returns:

The size of the state space, which is 1 for this process.

Return type:

int

std_deviation(dt: float, t0=None, x0=None) Tensor[source]

Calculates the standard deviation of the process after a time step.

Parameters:
  • dt (float) – The time step.

  • t0 (float, optional) – The initial time. Defaults to None.

  • x0 (float, optional) – The initial value. Defaults to None.

Returns:

The standard deviation of the process at time t0 + dt.

Return type:

tensorflow.Tensor

variance(dt: float) Tensor[source]

Calculates the variance of the process after a time step.

Parameters:

dt (float) – The time step.

Returns:

The variance of the process at time t0 + dt.

Return type:

tensorflow.Tensor

property volatility

Returns the volatility of the process.

Returns:

The volatility of the process.

Return type:

float

property x0

Returns the initial value of the process.

Returns:

The initial value of the process.

Return type:

float

tensorquant.models.stochasticprocess module

class tensorquant.models.stochasticprocess.StochasticProcess[source]

Bases: ABC

Abstract base class for stochastic processes. This defines the common interface for different types of stochastic processes used in mathematical finance and other fields.

size()[source]

Returns the number of dimensions of the process.

initial_values()[source]

Returns the initial value(s) of the process.

drift(t0, x0, dt)[source]

Computes the drift term of the process.

diffusion(t0, x0, dt)[source]

Computes the diffusion (volatility) term of the process.

expectation(t0, x0, dt)[source]

Returns the expected value of the process after a time increment dt.

std_deviation(t0, x0, dt)[source]

Returns the standard deviation of the process after a time increment dt.

evolve(t0, x0, dt, dw)[source]

Simulates the evolution of the process over a time increment dt using a random term dw.

abstract diffusion(t0, x0, dt)[source]

Computes the diffusion term of the process, which represents the stochastic component (volatility).

Parameters:
  • t0 (float) – The current time.

  • x0 (float or numpy array) – The current value(s) of the process.

  • dt (float) – The time increment.

Returns:

The diffusion (volatility) term at time t0.

Return type:

float or numpy array

abstract drift(t0, x0, dt)[source]

Computes the drift term of the process, which represents the deterministic trend.

Parameters:
  • t0 (float) – The current time.

  • x0 (float or numpy array) – The current value(s) of the process.

  • dt (float) – The time increment.

Returns:

The drift term at time t0 for the process.

Return type:

float or numpy array

evolve(t0, x0, dt, dw)[source]

Simulates the evolution of the process over a time increment dt using the Euler scheme.

Parameters:
  • t0 (float) – The current time.

  • x0 (float or numpy array) – The current value(s) of the process.

  • dt (float) – The time increment.

  • dw (float or numpy array) – The random term (typically drawn from a normal distribution).

Returns:

The new value(s) of the process at time t0 + dt.

Return type:

float or numpy array

expectation(t0, x0, dt)[source]

Computes the expectation (mean) of the process at time t0 + dt, using Euler discretization.

Parameters:
  • t0 (float) – The current time.

  • x0 (float or numpy array) – The current value(s) of the process.

  • dt (float) – The time increment.

Returns:

The expected value(s) of the process at time t0 + dt.

Return type:

float or numpy array

property factors

Returns the number of factors (dimensions) in the process.

Returns:

The number of factors (same as size()).

Return type:

int

abstract initial_values()[source]

Returns the initial values of the process.

Returns:

The initial value(s) of the process.

Return type:

float or numpy array

abstract size()[source]

Returns the number of dimensions of the process.

Returns:

The number of dimensions (or factors) of the stochastic process.

Return type:

int

std_deviation(t0, x0, dt)[source]

Computes the standard deviation of the process at time t0 + dt.

Parameters:
  • t0 (float) – The current time.

  • x0 (float or numpy array) – The current value(s) of the process.

  • dt (float) – The time increment.

Returns:

The standard deviation of the process at time t0 + dt.

Return type:

float or numpy array

Module contents