Common Model Functions

Abstract Model Types

DiffFusion.ModelType
abstract type Model end

An abstract base model type. This type covers component models and hybrid composite models.

source
DiffFusion.ComponentModelType
abstract type ComponentModel <: Model end

An abstract component model type. This type implements the common interface of all component models.

source

State Variable

A model allows to simulate a stochastic process $\left(X_t\right)$. For a given $t$ the vector $X_t$ is represented by a ModelState.

DiffFusion.ModelStateType
struct ModelState
    X::AbstractMatrix
    idx::Dict{String,Int}
    params::Union{NamedTuple, Nothing}
end

A ModelState is a matrix of state variables decorated by a dictionary of alias strings and optional additional parameters.

It allows to decouple simulation of state variables and usage of state variables.

X is of size (n, p) where n represents the number of state aliases and p represents the number of paths. A matrix with a large number of paths is typically used when calling model functions for payoff evaluation.

A single realisation of risk factors is represented by an (n, 1) matrix. We use (n,1) matrix instead of (n,) vector to avoid size-dependent switches.

idx is a dictionary with n entries. Keys represent state state alias entries and values represent the corresponding positions in X.

params is a tuple (or nothing) that holds additional pre-calculated state-independent data which is used in subsequent Theta and Sigma calculations. This aims at avoiding duplicate calculations for state-dependent Theta and Sigma calculations. The params is supposed to be calculated by method simulation_parameters(...).

source
DiffFusion.model_stateFunction
model_state(X::AbstractMatrix, idx::Dict{String,Int})

Create a ModelState object and make sure it is consistent.

source
model_state(X::AbstractMatrix, m::Model, params = nothing)

Create a model state for a given model.

source

Auxilliary Methods

DiffFusion.aliasMethod
alias(m::Model)

Return the model's own alias. This is the default implementation.

source
DiffFusion.model_aliasFunction
model_alias(m::Model)

Return the aliases modelled by a model.

Typically, this coincides with the model's own alias. For composite models this is a list of component model aliases.

source
model_alias(m::CompositeModel)

Return the aliases modelled by a model.

Typical this coincides with the model's own alias. For composite models this is a list of component model aliases.

source
DiffFusion.factor_aliasFunction
factor_alias(m::Model)

Return a list of risk factor alias strings that represent the components of the multi-variate Brownian motion risk factors.

source
DiffFusion.parameter_gridFunction
parameter_grid(m::Model)

Return a list of times representing the (joint) grid points of piece-wise constant model parameters.

This method is intended to be used in conjunction with time-integration mehods that require smooth integrand functions.

source
parameter_grid(models::AbstractVector)

Return a list of times representing the (joint) grid points of piece-wise constant model parameters.

This method is intended to be used in conjunction with time-integration mehods that require smooth integrand functions.

source
parameter_grid(m::CevAssetModel)

Return a list of times representing the (joint) grid points of piece-wise constant model parameters.

This method is intended to be used in conjunction with time-integration mehods that require smooth integrand functions.

source
parameter_grid(m::LognormalAssetModel)

Return a list of times representing the (joint) grid points of piece-wise constant model parameters.

This method is intended to be used in conjunction with time-integration mehods that require smooth integrand functions.

source
parameter_grid(m::CompositeModel)

Return a list of times representing the (joint) grid points of piece-wise constant model parameters.

This method is intended to be used in conjunction with time-integration mehods that require smooth integrand functions.

source
parameter_grid(m::OrnsteinUhlenbeckModel)

Return a list of times representing the (joint) grid points of piece-wise constant model parameters.

source
parameter_grid(m::GaussianHjmModel)

Return a list of times representing the (joint) grid points of piece-wise constant model parameters.

This method is intended to be used in conjunction with time-integration mehods that require smooth integrand functions.

source
parameter_grid(m::QuasiGaussianModel)

Return a list of times representing the (joint) grid points of piece-wise constant model parameters.

source
parameter_grid(m::MarkovFutureModel)

Return a list of times representing the (joint) grid points of piece-wise constant model parameters.

This method is intended to be used in conjunction with time-integration mehods that require smooth integrand functions.

source

Model Functions for Simulation

DiffFusion.ThetaFunction
Theta(
    m::Model,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the deterministic drift component for simulation over the time period [s, t]. If Theta is state-dependent a state vector X must be supplied. The method returns a vector of length(state_alias).

source
Theta(
    m::CevAssetModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the deterministic drift component for simulation over the time period [s, t].

source
Theta(
    m::LognormalAssetModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the deterministic drift component for simulation over the time period [s, t].

source
Theta(
    m::CoxIngersollRossModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the deterministic drift component for simulation over the time period [s, t].

source
Theta(
    m::SimpleModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the deterministic drift component for simulation over the time period [s, t].

source
Theta(
    m::DiagonalModel,
    s::ModelTime,
    t::ModelTime,
    X::ModelState,
    )

Return the deterministic drift component for simulation over the time period [s, t].

source
Theta(
    m::OrnsteinUhlenbeckModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the deterministic drift component for simulation over the time period [s, t].

source
Theta(
    m::GaussianHjmModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the deterministic drift component for simulation over the time period [s, t]. If Theta is state-dependent a state vector X must be supplied. The method returns a vector of length(state_alias).

source
Theta(
    m::QuasiGaussianModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the deterministic drift component for simulation over the time period [s, t] and using the state vector X.

Method returns a vector of length(state_alias).

source
Theta(
    m::MarkovFutureModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the deterministic drift component for simulation over the time period [s, t]. If Theta is state-dependent a state vector X must be supplied. The method returns a vector of length(state_alias).

source
DiffFusion.H_TFunction
H_T(
    m::Model,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t]. If H is state-dependent a state vector X must be supplied. We use the transposed of H to

  • allow for efficient sparse CSC matrix insertion and
  • allow for efficient multiplication X' * H' = (H * X)'.

The state vector X may effectively be a subset of all states. To accommodate this, we use a dedicated list of state aliases state_alias_H for the result matrix. The method returns a (sparse) matrix of size (length(state_alias_H), length(state_alias)).

source
H_T(
    m::CevAssetModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t].

source
H_T(
    m::LognormalAssetModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t].

source
H_T(
    m::CoxIngersollRossModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t].

There is no benefit in allowing HT to be state-dependent. If HT would need to be state-dependent then it should be incorporated into Theta.

source
H_T(
    m::SimpleModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t].

source
H_T(
    m::DiagonalModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t].

source
H_T(
    m::OrnsteinUhlenbeckModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t].

source
H_T(
    m::GaussianHjmModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t].

source
H_T(
    m::QuasiGaussianModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t].

source
H_T(
    m::MarkovFutureModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return the transposed of the convection matrix H for simulation over the time period [s, t].

source
DiffFusion.Sigma_TFunction
Sigma_T(
    m::Model,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return a matrix-valued function representing the volatility matrix function.

The signature of the resulting function is (u::ModelTime). Here, u represents the observation time.

The state vector is required if Sigma(u) depends on X_s.

The result of an evaluation of Sigma_T(...)(u) is a matrix of size (length(state_alias_Sigma), length(factor_alias_Sigma)).

Models may have state variables that do not depend on Brownian motion. The state aliases of such state variables are excluded from statealiasSigma. Consequently, statealiasSigma lists all state variables that actually do depend on the Brownian motions. The specification of statealiasSigma allows for the calculation of a full-rank covariance matrix without large blocks of zero entries.

The Brownian motion relevant for a model may effectively be a subset of all Brownian motions. To accommodate this, we use a dedicated list of factor aliases factor_alias_Sigma for the size of the result matrix of a function evaluation.

The transposed '_T' is convention to simplify notation for covariance calculation.

source
Sigma_T(
    m::CevAssetModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return a matrix-valued function representing the volatility matrix function.

The signature of the resulting function is (u::ModelTime). Here, u represents the observation time.

source
Sigma_T(
    m::LognormalAssetModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return a matrix-valued function representing the volatility matrix function.

The signature of the resulting function is (u::ModelTime). Here, u represents the observation time.

source
Sigma_T(
    m::CoxIngersollRossModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return a matrix-valued function representing the volatility matrix function.

source
Sigma_T(
    m::SimpleModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return a matrix-valued function representing the volatility matrix function.

The signature of the resulting function is (u::ModelTime). Here, u represents the observation time.

source
Sigma_T(
    m::DiagonalModel,
    s::ModelTime,
    t::ModelTime,
    X::ModelState,
    )

Return a matrix-valued function representing the volatility matrix function.

The signature of the resulting function is (u::ModelTime). Here, u represents the observation time.

source
Sigma_T(
    m::OrnsteinUhlenbeckModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return a matrix-valued function representing the volatility matrix function.

The signature of the resulting function is (u::ModelTime). Here, u represents the observation time.

source
Sigma_T(
    m::GaussianHjmModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return a matrix-valued function representing the volatility matrix function.

source
Sigma_T(
    m::QuasiGaussianModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return a matrix-valued function representing the volatility matrix function.

source
Sigma_T(
    m::MarkovFutureModel,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Return a matrix-valued function representing the volatility matrix function.

source
DiffFusion.state_dependent_ThetaFunction
state_dependent_Theta(m::Model)

Return whether Theta requires a state vector input X.

source
state_dependent_Theta(m::CevAssetModel)

Return whether Theta requires a state vector input X.

source
state_dependent_Theta(m::LognormalAssetModel)

Return whether Theta requires a state vector input X.

source
state_dependent_Theta(m::CoxIngersollRossModel)

Return whether Theta requires a state vector input X.

source
state_dependent_Theta(m::CompositeModel)

Return whether Theta requires a state vector input X.

source
state_dependent_Theta(m::OrnsteinUhlenbeckModel)

Return whether Theta requires a state vector input X.

source
state_dependent_Theta(m::GaussianHjmModel)

Return whether Theta requires a state vector input X.

source
state_dependent_Theta(m::QuasiGaussianModel)

Return whether Theta requires a state vector input X.

source
state_dependent_Theta(m::MarkovFutureModel)

Return whether Theta requires a state vector input X.

source
DiffFusion.state_dependent_HFunction
state_dependent_H(m::Model)

Return whether H requires a state vector input X.

source
state_dependent_H(m::CevAssetModel)

Return whether H requires a state vector input X.

source
state_dependent_H(m::LognormalAssetModel)

Return whether H requires a state vector input X.

source
state_dependent_H(m::CoxIngersollRossModel)

Return whether H requires a state vector input X.

source
state_dependent_H(m::CompositeModel)

Return whether H requires a state vector input X.

source
state_dependent_H(m::OrnsteinUhlenbeckModel)

Return whether H requires a state vector input X.

source
state_dependent_H(m::GaussianHjmModel)

Return whether H requires a state vector input X.

source
state_dependent_H(m::QuasiGaussianModel)

Return whether H requires a state vector input X.

source
state_dependent_H(m::MarkovFutureModel)

Return whether H requires a state vector input X.

source
DiffFusion.state_dependent_SigmaFunction
state_dependent_Sigma(m::Model)

Return whether Sigma requires a state vector input X.

source
state_dependent_Sigma(m::CevAssetModel)

Return whether Sigma requires a state vector input X.

source
state_dependent_Sigma(m::LognormalAssetModel)

Return whether Sigma requires a state vector input X.

source
state_dependent_Sigma(m::CoxIngersollRossModel)

Return whether Sigma requires a state vector input X.

source
state_dependent_Sigma(m::CompositeModel)

Return whether Sigma requires a state vector input X.

source
state_dependent_Sigma(m::OrnsteinUhlenbeckModel)

Return whether Sigma requires a state vector input X.

source
state_dependent_Sigma(m::GaussianHjmModel)

Return whether Sigma requires a state vector input X.

source

Return whether Sigma requires a state vector input X.

source
state_dependent_Sigma(m::MarkovFutureModel)

Return whether Sigma requires a state vector input X.

source
DiffFusion.state_alias_HFunction
state_alias_H(m::Model)

Return a list of state alias strings required for (H * X) calculation.

source
state_alias_H(m::CevAssetModel)

Return a list of state alias strings required for (H * X) calculation.

source
state_alias_H(m::LognormalAssetModel)

Return a list of state alias strings required for (H * X) calculation.

source
state_alias_H(m::CoxIngersollRossModel)

Return a list of state alias strings required for (H * X) calculation.

source
state_alias_H(m::CompositeModel)

Return a list of state alias strings required for (H * X) calculation.

source
state_alias_H(m::OrnsteinUhlenbeckModel)

Return a list of state alias strings required for (H * X) calculation.

source
state_alias_H(m::GaussianHjmModel)

Return a list of state alias strings required for (H * X) calculation.

source
state_alias_H(m::QuasiGaussianModel)

Return a list of state alias strings required for (H * X) calculation.

source
state_alias_H(m::MarkovFutureModel)

Return a list of state alias strings required for (H * X) calculation.

source
DiffFusion.state_alias_SigmaFunction
state_alias_Sigma(m::Model)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

source
state_alias_Sigma(m::CevAssetModel)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

source
state_alias_Sigma(m::LognormalAssetModel)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

source
state_alias_Sigma(m::CoxIngersollRossModel)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

source
state_alias_Sigma(m::CompositeModel)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

This is a default behaviour. It is supposed to be overwritten for derived Model types.

source
state_alias_Sigma(m::DiagonalModel)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

source
state_alias_Sigma(m::OrnsteinUhlenbeckModel)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

source
state_alias_Sigma(m::GaussianHjmModel)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

source
state_alias_Sigma(m::QuasiGaussianModel)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

Note, auxiliary variable y is not included here.

source
state_alias_Sigma(m::MarkovFutureModel)

Return a list of state alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

source
DiffFusion.factor_alias_SigmaFunction
factor_alias_Sigma(m::Model)

Return a list of factor alias strings required for (Sigma(u)' Gamma Sigma(u)) calculation.

source
factor_alias_Sigma(m::CevAssetModel)

Return a list of factor alias strings required for (Sigma(u)^T Gamma Sigma(u)) calculation.

source
factor_alias_Sigma(m::LognormalAssetModel)

Return a list of factor alias strings required for (Sigma(u)^T Gamma Sigma(u)) calculation.

source
factor_alias_Sigma(m::CoxIngersollRossModel)

Return a list of factor alias strings required for (Sigma(u)^T Gamma Sigma(u)) calculation.

source
factor_alias_Sigma(m::CompositeModel)

Return a list of factor alias strings required for (Sigma(u)^T Gamma Sigma(u)) calculation.

source
factor_alias_Sigma(m::OrnsteinUhlenbeckModel)

Return a list of factor alias strings required for (Sigma(u)^T Gamma Sigma(u)) calculation.

source
factor_alias_Sigma(m::GaussianHjmModel)

Return a list of factor alias strings required for (Sigma(u)^T Gamma Sigma(u)) calculation.

source

Return a list of factor alias strings required for (Sigma(u)^T Gamma Sigma(u)) calculation.

source
factor_alias_Sigma(m::MarkovFutureModel)

Return a list of factor alias strings required for (Sigma(u)^T Gamma Sigma(u)) calculation.

source
DiffFusion.covarianceFunction
covariance(
    m::Model,
    Gamma::Matrix,
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Calculate the covariance matrix over a time interval.

source
covariance(
    m::Model,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    )

Calculate the covariance matrix over a time interval.

source
DiffFusion.volatility_and_correlationFunction
volatility_and_correlation(
    m::Model,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    X::Union{ModelState, Nothing} = nothing,
    vol_eps::ModelValue = 1.0e-8,  # avoid division by zero
    )

Calculate the volatility vector and correlation matrix over a time interval.

source
DiffFusion.simulation_parametersFunction
simulation_parameters(
    m::Model,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    )

Pre-calculate parameters that are used in state-dependent Theta and Sigma calculation.

source
simulation_parameters(
    m::CevAssetModel,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    )

Pre-calculate parameters that are used in state-dependent Theta and Sigma calculation.

source
simulation_parameters(
    m::LognormalAssetModel,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    )

Pre-calculate parameters that are used in state-dependent Theta and Sigma calculation.

For LognormalAssetModel there are no valuations that should be cached.

source
simulation_parameters(
    m::CevAssetModel,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    )

Pre-calculate parameters that are used in state-dependent Theta and Sigma calculation.

source
simulation_parameters(
    m::DiagonalModel,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    )

Pre-calculate parameters that are used in state-dependent Theta and Sigma calculation.

source
simulation_parameters(
    m::OrnsteinUhlenbeckModel,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    )

Pre-calculate parameters that are used in state-dependent Theta and Sigma calculation.

For OrnsteinUhlenbeckModel there are no valuations that should be cached.

source
simulation_parameters(
    m::GaussianHjmModel,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    )

Pre-calculate parameters that are used in state-dependent Theta and Sigma calculation.

For GaussianHjmModel there are no valuations that should be cached.

source
simulation_parameters(
    m::QuasiGaussianModel,
    ch::Union{CorrelationHolder, Nothing},
    s::ModelTime,
    t::ModelTime,
    )

Pre-calculate parameters that are used in state-dependent Theta and Sigma calculation.

For QuasiGaussianModel there are no valuations that should be cached.

source
DiffFusion.diagonal_volatilityFunction
diagonal_volatility(
    m::Model,
    s::ModelTime,
    t::ModelTime,
    X::ModelState,
    )

Calculate the path-dependent volatilities for a given model.

X is supposed to hold a state matrix of size (n, p). Here, n is length(state_alias(m)) and p is the number of paths.

The method returns a matrix of size (n, p).

source
diagonal_volatility(
    m::CevAssetModel,
    s::ModelTime,
    t::ModelTime,
    X::ModelState,
    )

Calculate the path-dependent volatilities for CevAssetModel.

X is supposed to hold a state matrix of size (n, p). Here, n is length(state_alias(m)) and p is the number of paths.

The method returns a matrix of size (n, p).

source
diagonal_volatility(
    m::CoxIngersollRossModel,
    s::ModelTime,
    t::ModelTime,
    X::ModelState,
    )

Calculate the path-dependent volatilities for CoxIngersollRossModel.

X is supposed to hold a state matrix of size (n, p). Here, n is length(state_alias(m)) and p is the number of paths.

The method returns a matrix of size (n, p).

source
diagonal_volatility(
    m::DiagonalModel,
    s::ModelTime,
    t::ModelTime,
    X::ModelState,
    )

Calculate the path-dependent volatilities for a given model.

X is supposed to hold a state matrix of size (n, p). Here, n is length(state_alias(m)) and p is the number of paths.

The method returns a matrix of size (n, p).

source