Serialisation Functions
In this section we document methods for serialising and de-serialising DiffFusion.jl objects.
We serialise objects into ordered dictionaries of the general form
typename : TypeName
constructor : function_name
field_name_1 : field_value_1
...
field_name_n : field_value_n
Dictionary keys are strings, dictionary values are strings, numbers o ordered dictionaries of component structures.
We utilise multiple dispatch to specify serialisation recursively.
Object Serialisation
DiffFusion.serialise
— Functionserialise(o::Any)
Serialise an arbitrary object.
serialise(o::Future)
Serialise a Future object from a remotecall(...)
.
This operation is blocking. We require that the result is calculated such that it actually can be serialised.
serialise(o::Nothing)
Serialise Nothing.
serialise(o::AbstractString)
Serialise String.
serialise(o::Integer)
Serialise Integer.
serialise(o::ModelValue)
Serialise Float.
serialise(o::AbstractDict)
Serialise dictionaries.
serialise(o::AbstractVector)
Serialise vectors.
serialise(o::AbstractMatrix)
Serialise matrices.
serialise(o::AbstractArray)
Serialise d-dimensional arrays.
serialise(o::FlatForward)
Serialise FlatForward.
serialise(o::ZeroCurve)
Serialise ZeroCurve.
serialise(o::LinearZeroCurve)
Serialise LinearZeroCurve.
serialise(o::BackwardFlatVolatility)
Serialise BackwardFlatVolatility.
serialise(o::PiecewiseFlatParameter)
Serialise PiecewiseFlatParameter.
serialise(o::CorrelationHolder)
Serialise CorrelationHolder.
serialise(o::Context)
Serialise model Context.
serialise(o::BenchmarkTimesScaling)
Serialise a BenchmarkTimesScaling enumeration object.
serialise(o::GaussianHjmModel)
Serialise GaussianHjmModel.
serialise(o::LognormalAssetModel)
Serialise LognormalAssetModel.
serialise(o::CevAssetModel)
Serialise CevAssetModel.
serialise(o::SimpleModel)
Serialise SimpleModel.
DiffFusion.serialise_struct
— Functionserialise_struct(o::Any)
Create a dictionary from an arbitrary struct object
DiffFusion._serialise_key_references
— ConstantIdentifyiers used to specify a reference for serialisation.
DiffFusion.serialise_key
— Functionserialise_key(alias::String)
Serialise an alias as a key.
This is required to capture object dependencies for de-serialisation.
DiffFusion.serialise_as_list
— Functionserialise_as_list(o::SimpleModel)
Serialise SimpleModel as a list and capture references.
Object De-Serialisation
DiffFusion.deserialise
— Functiondeserialise(o::String, d::Union{AbstractDict, Nothing} = nothing)
De-serialise strings.
We incorporate some logic to handle external references.
We allow that the repository disctionary d
contains remote call Futures
. However, we want to ensure that the method returns actual objects. Thus, we fetch
any Future
within this method.
deserialise(o::Number, d::Union{AbstractDict, Nothing} = nothing)
De-serialise numbers.
deserialise(o::AbstractDict, d::Union{AbstractDict, Nothing} = nothing)
De-serialise dictionary.
deserialise(o::AbstractVector, d::Union{AbstractDict, Nothing} = nothing)
De-serialise vector or matrix.
DiffFusion.deserialise_object
— Functiondeserialise_object(o::OrderedDict, d::Union{AbstractDict, Nothing} = nothing)
De-serialise objects.
Caution, this method bares the potential risk of code injection.
DiffFusion.deserialise_from_list
— Functiondeserialise_from_list(dict_list::AbstractVector)
De-serialise a list of objects and capture references.
DiffFusion.array
— Functionarray(data::AbstractVector, dims)
Convert vector data
into d-dimensional array. Here, d
is length(dims)
.
Parameter dims
is a vector or tuple of number of elements per dimension.
Data vector data
must be of appropriate length, i.e. length(data) == prod(dims)
.
Rebuild Models
This subsection contains methods to extract term structures and re-build models.
Methods are intended to be used for sensitivity calculations. For that purpose we need to identify model parameters as inputs to the valuation function.
Model parameters for a model m::Model
are stored in a Dict{String, Any}
of the form
"type" => typeof(m),
"alias" => m.alias,
[parameter identifier] => [parameter value(s)]
...
DiffFusion.model_parameters
— Functionmodel_parameters(m::GaussianHjmModel)
Extract model parameters from GaussianHjmModel.
model_parameters(m::LognormalAssetModel)
Extract model parameters from LognormalAssetModel.
model_parameters(m::CevAssetModel)
Extract model parameters from CevAssetModel.
model_parameters(m::SimpleModel)
Extract model parameters from SimpleModel.
DiffFusion.build_model
— Functionbuild_model(
alias::String,
param_dict::Dict,
model_dict::Dict,
)
Re-build a model from model parameters dictionary.
Alias identifies the model which is to be build. Input parameter term structures are stored in paramdict. The modeldict is used to reference quanto models.
DiffFusion.termstructure_values
— Functiontermstructure_values(ts_dict::AbstractDict)
Extract term structure labels and values from term structure dictionary
DiffFusion.termstructure_dictionary!
— Functiontermstructure_dictionary!(
ts_dict::AbstractDict,
ts_labels::AbstractVector,
ts_values::AbstractVector,
)
Re-build term structure dictionary from labels and values.
DiffFusion.model_volatility_values
— Functionmodel_volatility_values(
alias::String,
param_dict::Dict,
)
Extract volatility labels and values from model parameters.
DiffFusion.model_parameters!
— Functionmodel_parameters!(
param_dict::Dict,
param_labels::AbstractVector,
param_values::AbstractVector,
)
Re-build model parameter dictionary from volatility labels and values.
Read Term Structures From CSV Files
DiffFusion.read_zero_curves
— Functionread_zero_curves(
source,
delim::AbstractChar,
method_alias::String = "LINEAR"
)
Read times and values from CSV file and create ZeroCurve.
Arguments source
and delim
are passed on to DelimitedFiles.readdlm
.
method_alias
is the interpolation string used in interpolation_methods
.
DiffFusion.read_volatilities
— Functionread_volatilities(
source,
delim::AbstractChar,
)
Read times and values from CSV file and create scalar-valued BackwardFlatVolatility.
Arguments source
and delim
are passed on to DelimitedFiles.readdlm
.
DiffFusion.read_volatility
— Functionread_volatility(
source,
delim::AbstractChar,
)
Read times and values from CSV file and create a single vector-valued BackwardFlatVolatility.
Arguments source
and delim
are passed on to DelimitedFiles.readdlm
.
Termstructure alias
is read from the first data column header.
DiffFusion.read_parameters
— Functionread_parameters(
source,
delim::AbstractChar,
param_func::Function = forward_flat_parameter,
)
Read times and values from CSV file and create scalar-valued ParameterTermstructures.
Arguments source
and delim
are passed on to DelimitedFiles.readdlm
.
constructor
is the constructor called to create the term structure. It is used to apply method to read ForwardFlatParameter
and BackwardFlatParameter
.
DiffFusion.read_correlations
— Functionread_correlations(
source,
delim::AbstractChar,
)
Read factor aliases and correlation values and setup a CorrelationHolder
.
Arguments source
and delim
are passed on to DelimitedFiles.readdlm
.