Term Structures Functions
In this section we document term structures.
Term Structure Types and Methods
DiffFusion.Termstructure
— Typeabstract type Termstructure end
An abstract term structure that provides an alias for identification.
DiffFusion.alias
— Methodalias(ts::Termstructure)
Return the term structure's alias.
DiffFusion.TermstructureResultSize
— Type@enum(
TermstructureResultSize,
TermstructureVector,
TermstructureScalar
)
Specify the dimensions/shape of the values modelled by a term structure.
For some term structures (e.g. ParameterTermstructure
and VolatilityTermstructure
) the result may be either a vector or a scalar.
CorrelationTermstructure
DiffFusion.CorrelationTermstructure
— Typeabstract type CorrelationTermstructure <: Termstructure end
An abstract correlation term structure that provides methods to calculate instantaneous correlations.
Call operator for CorrelationTermstructure
is defined as
(ts::CorrelationTermstructure)(args...) = correlation(ts, args...)
DiffFusion.correlation
— Methodcorrelation(ts::CorrelationTermstructure, alias1::String, alias2::String)
Return a scalar instantaneous correlation.
DiffFusion.correlation
— Methodcorrelation(ts::CorrelationTermstructure, aliases::AbstractVector{String})
Return a symmetric matrix of instantaneous correlations.
DiffFusion.correlation
— Methodcorrelation(ts::CorrelationTermstructure, aliases1::AbstractVector{String}, aliases2::AbstractVector{String})
Return a matrix of instantaneous correlations, each element of aliases1
versus each element of aliases2
. The size of the resulting matrix is (length(aliases1), length(aliases2))
.
DiffFusion.correlation
— Methodcorrelation(ts::CorrelationTermstructure, alias1::String, aliases2::AbstractVector{String})
Return an (1,N) matrix of instantaneous correlations.
DiffFusion.correlation
— Methodcorrelation(ts::CorrelationTermstructure, aliases1::AbstractVector{String}, alias2::String)
Return an (N, 1) matrix of instantaneous correlations.
CreditDefaultTermstructure
DiffFusion.CreditDefaultTermstructure
— Typeabstract type CreditDefaultTermstructure <: Termstructure end
An abstract credit default term structure that provides methods to calculate survival probabilities.
Call operator for CreditDefaultTermstructure
is defined as
(ts::CreditDefaultTermstructure)(args...) = survival(ts, args...)
DiffFusion.survival
— Methodsurvival(ts::CreditDefaultTermstructure, t::ModelTime)
Return the survival probability with observation time t
.
FuturesTermstructure
DiffFusion.FuturesTermstructure
— Typeabstract type FuturesTermstructure <: Termstructure end
An abstract futures term structure that provides methods to calculate prices of futures. Such prices represent risk-neutral expectations of spot prices.
Call operator for FuturesTermstructure
is defined as
(ts::FuturesTermstructure)(args...) = future_price(ts, args...)
DiffFusion.future_price
— Methodfuture_price(ts::FuturesTermstructure, t::ModelTime)
Return the price of a future with settlement time t
.
InflationTermstructure
DiffFusion.InflationTermstructure
— Typeabstract type InflationTermstructure <: Termstructure end
An abstract inflation term structure that provides methods to calculate forward inflation index. Forward inflation index is a T-forward measure expectation of (spot) inflation index values.
Call operator for InflationTermstructure
is defined as
(ts::InflationTermstructure)(args...) = inflation_index(ts, args...)
DiffFusion.inflation_index
— Methodinflation_index(ts::InflationTermstructure, t::ModelTime)
Return the forward inflation index with observation time t
.
ParameterTermstructure
DiffFusion.ParameterTermstructure
— Typeabstract type ParameterTermstructure <: Termstructure end
An abstract generic parameter term structure that provides methods to retrieve parameter values for various incarnations of signatures.
Call operator for ParameterTermstructure
is defined as
(ts::ParameterTermstructure)(args...) = value(ts, args...)
DiffFusion.value
— Functionvalue(ts::ParameterTermstructure, result_size::TermstructureResultSize = TermstructureVector)
Return a value for constant/time-homogeneous parameters.
DiffFusion.value
— Functionvalue(ts::ParameterTermstructure, t::ModelTime, result_size::TermstructureResultSize = TermstructureVector)
Return a value for a given observation time t
.
YieldTermstructure
DiffFusion.YieldTermstructure
— Typeabstract type YieldTermstructure <: Termstructure end
An abstract yield term structure that provides methods to calculate discount factors zero rates and forward rates.
Call operator for YieldTermstructure
is defined as
(ts::YieldTermstructure)(args...) = discount(ts, args...)
DiffFusion.discount
— Methoddiscount(ts::YieldTermstructure, t::ModelTime)
Return the discount factor with observation time t
.
DiffFusion.zero_rate
— Methodzero_rate(ts::YieldTermstructure, t0::ModelTime, t1::ModelTime)
Return the continuous compounded zero rate over a period t0
to t1
.
DiffFusion.zero_rate
— Methodzero_rate(ts::YieldTermstructure, t::ModelTime)
Return the continuous compounded zero rate as of today with observation time t
.
DiffFusion.forward_rate
— Functionforward_rate(ts::YieldTermstructure, t::ModelTime, dt=1.0e-6)
Return the instantaneous forward rate with observation time t
.
VolatilityTermstructure
DiffFusion.VolatilityTermstructure
— Typeabstract type VolatilityTermstructure <: Termstructure end
An abstract volatility term structure that provides methods to calculate volatility values for various incarnations of signatures.
Call operator for VolatilityTermstructure
is defined as
(ts::VolatilityTermstructure)(args...) = volatility(ts, args...)
DiffFusion.volatility
— Functionvolatility(ts::VolatilityTermstructure, t::ModelTime, result_size::TermstructureResultSize = TermstructureVector)
Return a volatility for a given observation time t
.
DiffFusion.volatility
— Methodvolatility(ts::VolatilityTermstructure, t::ModelTime, x::ModelValue)
Return a scalar volatility for a given observation time t
and underlying or strike value x
.
Correlation Term Structures
DiffFusion.CorrelationHolder
— Typestruct CorrelationHolder <: CorrelationTermstructure
alias::String
correlations::Dict{String, ModelValue}
sep::String
value_type::DataType
end
A container holding correlation values.
A CorrelationHolder allows to calculate correlation matrices based on String
alias keys (identifiers).
value_type
specifies the type of correlation entries. This ensures that all values are of consistent type. This feature is required for correlation sensitivity calculation.
DiffFusion.correlation_holder
— Functioncorrelation_holder(
alias::String,
correlations::Dict,
sep::String = "<>",
value_type::DataType = ModelValue,
)
Create a CorrelationHolder object from dictionary.
correlation_holder(
alias::String,
sep::String = "<>",
value_type::DataType = ModelValue,
)
Create an empty CorrelationHolder object.
correlation_holder(m::AssetModel)
Return the correlation holder term structure.
Return the model's CorrelationHolder
.
DiffFusion.correlation_key
— Functioncorrelation_key(ch::CorrelationHolder, alias1::String, alias2::String)
Derive the key for correlation dictionary from two aliases.
DiffFusion.set_correlation!
— Functionset_correlation!(
ch::CorrelationHolder,
alias1::String,
alias2::String,
value::ModelValue
)
Insert a new correlation value into CorrelationHolder. If a correlation already exists it is overwritten.
DiffFusion.get
— Functionget(ch::CorrelationHolder, alias1::String, alias2::String)
Implement methodology to obtain a scalar correlation from a CorrelationHolder
.
Credit Default Term Structures
DiffFusion.FlatSpreadCurve
— Typestruct FlatSpreadCurve <: CreditDefaultTermstructure
alias::String
spread::ModelValue
end
A flat credit spread curve.
DiffFusion.flat_spread_curve
— Functionflat_spread_curve(alias::String, spread::ModelValue)
Create a FlatSpreadCurve.
flat_spread_curve(spread::ModelValue)
Create a FlatSpreadCurve without alias.
DiffFusion.LogSurvivalCurve
— Typestruct LogSurvivalCurve <: CreditDefaultTermstructure
alias::String
times::AbstractVector
values::AbstractVector
end
Log-interpolated survival probabilities.
DiffFusion.survival_curve
— Functionsurvival_curve(
alias::String,
times::AbstractVector,
survival_probs::AbstractVector,
interp_method = (x,y) -> linear_interpolation(x, y, extrapolation_bc = Line()),
)
Create a LogSurvivalCurve.
survival_curve(
alias::String,
times::AbstractVector,
survival_probs::AbstractVector,
method_alias::String,
)
Create a LogSurvivalCurve for pre-defined interpolation methods.
Parameter Term Structures
DiffFusion.PiecewiseFlatParameter
— Typeabstract type PiecewiseFlatParameter <: ParameterTermstructure end
A generic vector-valued model parameter term structure with piece-wise constant interpolation and constant extrapolation.
DiffFusion.BackwardFlatParameter
— Typestruct BackwardFlatParameter <: PiecewiseFlatParameter
alias::String
times::AbstractVector
values::AbstractMatrix
end
A generic vector-valued model parameter term structure with piece-wise constant backward-flat interpolation and constant extrapolation.
DiffFusion.backward_flat_parameter
— Functionbackward_flat_parameter(
alias::String,
times::AbstractVector,
values::AbstractMatrix,
)
Create a BackwardFlatParameter object for vector-valued parameters.
backward_flat_parameter(
alias::String,
times::AbstractVector,
values::AbstractVector,
)
Create a BackwardFlatParameter object for scalar parameters.
DiffFusion.flat_parameter
— Functionflat_parameter(value::ModelValue)
Create a constant BackwardFlatParameter object.
flat_parameter(alias::String, value::ModelValue)
Create a constant BackwardFlatParameter object.
flat_parameter(value::AbstractVector)
Create a constant BackwardFlatParameter object.
flat_parameter(alias::String, value::AbstractVector)
Create a constant BackwardFlatParameter object.
DiffFusion.ForwardFlatParameter
— Typestruct ForwardFlatParameter <: PiecewiseFlatParameter
alias::String
times::AbstractVector
values::AbstractMatrix
end
A generic vector-valued model parameter term structure with piece-wise constant forward-flat interpolation and constant extrapolation.
DiffFusion.forward_flat_parameter
— Functionforward_flat_parameter(
alias::String,
times::AbstractVector,
values::AbstractMatrix,
)
Create a ForwardFlatParameter object for vector-valued parameters.
forward_flat_parameter(
alias::String,
times::AbstractVector,
values::AbstractVector,
)
Create a ForwardFlatParameter object for scalar parameters.
DiffFusion.time_idx
— Methodtime_idx(ts::BackwardFlatParameter, t)
Find the index such that T[idx-1] < t <= T[idx]
. If t
is larger than the last (or all) times T
then return length(T)+1
.
DiffFusion.time_idx
— Methodtime_idx(ts::ForwardFlatParameter, t)
Find the index such that T[idx] >= t > T[idx+1]
. If t
is smaller than the first (or all) times T
then return 0
.
Yield Term Structures
DiffFusion.FlatForward
— Typestruct FlatForward <: YieldTermstructure
alias::String
rate
end
A constant yield term structure.
DiffFusion.flat_forward
— Functionflat_forward(alias::String, rate)
Create a FlatForward yield curve.
flat_forward(rate)
Create a FlatForward yield curve without alias.
DiffFusion.ZeroCurve
— Typestruct ZeroCurve <: YieldTermstructure
alias::String
times::AbstractVector
values::AbstractVector
interpolation
end
A yield term structure based on interpolated continuous compounded zero rates.
DiffFusion.zero_curve
— Functionzero_curve(
alias::String,
times::AbstractVector,
values::AbstractVector,
interp_method = (x,y) -> linear_interpolation(x, y, extrapolation_bc = Line()),
)
Create a ZeroCurve object.
zero_curve(
times::AbstractVector,
values::AbstractVector,
interp_method = (x,y) -> linear_interpolation(x, y, extrapolation_bc = Line()),
)
Create a ZeroCurve object without alias.
zero_curve(
alias::String,
times::AbstractVector,
values::AbstractVector,
method_alias::String,
)
Create a ZeroCurve object using interpolation string.
zero_curve(
times::AbstractVector,
values::AbstractVector,
method_alias::String,
)
Create a ZeroCurve object using interpolation string.
DiffFusion.LinearZeroCurve
— Typestruct LinearZeroCurve <: YieldTermstructure
alias::String
times::AbstractVector
values::AbstractVector
end
A yield term structure based on continuous compounded zero rates with linear interpolation and flat extrapolation.
This curve aims at mitigating limitations of Zygote and ZeroCurve.
DiffFusion.linear_zero_curve
— Functionlinear_zero_curve(
alias::String,
times::AbstractVector,
values::AbstractVector,
)
Create a LinearZeroCurve.
linear_zero_curve(
times::AbstractVector,
values::AbstractVector,
)
Create a LinearZeroCurve with empty alias.
Volatility Term Structures
DiffFusion.BackwardFlatVolatility
— Typestruct BackwardFlatVolatility <: VolatilityTermstructure
alias::String
times::AbstractVector
values::AbstractMatrix
end
A vector-valued volatility term structure with piece-wise constant (backward-flat) interpolation and constant extrapolation.
DiffFusion.backward_flat_volatility
— Functionbackward_flat_volatility(
alias::String,
times::AbstractVector,
values::AbstractMatrix,
)
Create a BackwardFlatVolatility object for vector-valued volatility.
Volatility values are of size (nvols, ntimes).
backward_flat_volatility(
alias::String,
times::AbstractVector,
values::AbstractVector,
)
Create a BackwardFlatVolatility object for scalar volatility.
DiffFusion.flat_volatility
— Functionflat_volatility(alias::String, value)
Create a BackwardFlatVolatility object for a flat volatility.
flat_volatility(alias::String, value)
Create a BackwardFlatVolatility object for a flat volatility.
DiffFusion.time_idx
— Methodtime_idx(ts::BackwardFlatVolatility, t)
Find the index such that T[idx-1] < t <= T[idx]
. If t
is larger than the last (or all) times T
then return length(T)+1
.
Common Methods Overview
DiffFusion.correlation
— Functioncorrelation(ts::CorrelationTermstructure, alias1::String, alias2::String)
Return a scalar instantaneous correlation.
correlation(ts::CorrelationTermstructure, aliases::AbstractVector{String})
Return a symmetric matrix of instantaneous correlations.
correlation(ts::CorrelationTermstructure, aliases1::AbstractVector{String}, aliases2::AbstractVector{String})
Return a matrix of instantaneous correlations, each element of aliases1
versus each element of aliases2
. The size of the resulting matrix is (length(aliases1), length(aliases2))
.
correlation(ts::CorrelationTermstructure, alias1::String, aliases2::AbstractVector{String})
Return an (1,N) matrix of instantaneous correlations.
correlation(ts::CorrelationTermstructure, aliases1::AbstractVector{String}, alias2::String)
Return an (N, 1) matrix of instantaneous correlations.
correlation(ch::CorrelationHolder, alias1::String, alias2::String)
Return a scalar instantaneous correlation.
correlation(ch::CorrelationHolder, aliases1::AbstractVector{String}, aliases2::AbstractVector{String})
Return a matrix of instantaneous correlations, each element of aliases1 versus each element of aliases2. The size of the resulting matrix is (length(aliases1), length(aliases2)).
correlation(ch::CorrelationHolder, aliases::AbstractVector{String})
Return a symmetric matrix of instantaneous correlations.
DiffFusion.discount
— Functiondiscount(ts::YieldTermstructure, t::ModelTime)
Return the discount factor with observation time t
.
discount(ts::FlatForward, t::ModelTime)
Calculate discount factor.
discount(ts::ZeroCurve, t::ModelTime)
Calculate discount factor.
discount(ts::LinearZeroCurve, t::ModelTime)
Calculate discount factor.
discount(
t::ModelTime,
ts_dict::Dict{String,Termstructure},
first_alias::String,
second_alias::Union{String,Nothing} = nothing,
operation::Union{String,Nothing} = nothing,
)
Derive the discount factor for one or two of curve alias and a curve operation.
DiffFusion.value
— Functionvalue(ts::ParameterTermstructure, result_size::TermstructureResultSize = TermstructureVector)
Return a value for constant/time-homogeneous parameters.
value(ts::ParameterTermstructure, t::ModelTime, result_size::TermstructureResultSize = TermstructureVector)
Return a value for a given observation time t
.
value(ts::PiecewiseFlatParameter, result_size::TermstructureResultSize = TermstructureVector)
Return a value for constant/time-homogeneous parameters.
value(ts::PiecewiseFlatParameter, t::ModelTime, result_size::TermstructureResultSize = TermstructureVector)
Return a value for a given observation time t.
DiffFusion.volatility
— Functionvolatility(ts::VolatilityTermstructure, t::ModelTime, result_size::TermstructureResultSize = TermstructureVector)
Return a volatility for a given observation time t
.
volatility(ts::VolatilityTermstructure, t::ModelTime, x::ModelValue)
Return a scalar volatility for a given observation time t
and underlying or strike value x
.
volatility(ts::BackwardFlatVolatility, t::ModelTime, result_size::TermstructureResultSize = TermstructureVector)
Return a vector of volatilities for a given observation time t.
DiffFusion.survival
— Functionsurvival(ts::CreditDefaultTermstructure, t::ModelTime)
Return the survival probability with observation time t
.
survival(ts::FlatSpreadCurve, t::ModelTime)
Calculate survival probability.
survival(ts::LogSurvivalCurve, t::ModelTime)
Calculate survival probability.