Serialisation Functions

In this section we document methods for serialising and de-serialising 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.serialiseFunction
serialise(o::Any)

Serialise an arbitrary object.

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::GaussianHjmModel)

Serialise GaussianHjmModel.

serialise(o::LognormalAssetModel)

Serialise LognormalAssetModel.

serialise(o::SimpleModel)

Serialise SimpleModel.

DiffFusion.serialise_keyFunction
serialise_key(alias::String)

Serialise an alias as a key.

This is required to capture object dependencies for de-serialisation.

Object De-Serialisation

DiffFusion.deserialiseFunction
deserialise(o::String, d::Union{AbstractDict, Nothing} = nothing)

De-serialise strings.

We incorporate some logic to handle external references."

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_objectFunction
deserialise_object(o::OrderedDict, d::Union{AbstractDict, Nothing} = nothing)

De-serialise objects.

Caution, this method bares the potential risk of code injection.

DiffFusion.arrayFunction
array(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_parametersFunction
model_parameters(m::GaussianHjmModel)

Extract model parameters from GaussianHjmModel.

model_parameters(m::LognormalAssetModel)

Extract model parameters from LognormalAssetModel.

model_parameters(m::SimpleModel)

Extract model parameters from SimpleModel.

DiffFusion.build_modelFunction
build_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_valuesFunction
termstructure_values(ts_dict::AbstractDict)

Extract term structure labels and values from term structure dictionary

DiffFusion.termstructure_dictionary!Function
termstructure_dictionary!(
    ts_dict::AbstractDict,
    ts_labels::AbstractVector,
    ts_values::AbstractVector,
    )

Re-build term structure dictionary from labels and values.

DiffFusion.model_parameters!Function
model_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_curvesFunction
read_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_volatilitiesFunction
read_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_volatilityFunction
read_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_parametersFunction
read_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_correlationsFunction
read_correlations(
    source,
    delim::AbstractChar,
    )

Read factor aliases and correlation values and setup a CorrelationHolder.

Arguments source and delim are passed on to DelimitedFiles.readdlm.