Internal Functions

Main Structs

StochasticIntegrals.ItoIntegralType

A struct detailing an ito integral. It contains a UnivariateFunction detailing the integrand as well as a symbol detailing an id of the integral's processes.

Usual (and most general) contructor is:

ItoIntegral(brownian_id_::Symbol, f_::UnivariateFunction)

Convenience constructor for ItoIntegrals where the integrand is a flat function is:

ItoIntegral(brownian_id_::Symbol, variance_::Real)
source
StochasticIntegrals.ItoSetType

Creates an ItoSet. This contains :

  • A correlation matrix of brownian motions.
  • A vector giving the axis labels for this correlation matrix.
  • A dict of ItoInterals. Here the keys should be ids for the ito integrals and the values should be ItoIntegrals.

Determine which Brownian processes are used in an array of ItoIntegrals.

source
StochasticIntegrals.StochasticIntegralsCovarianceType
StochasticIntegralsCovariance

This is an abstract type which represents structs that represent covariances over spans of time. The concrete instances of this type should support extracting correlations, covariances, volatilities and random number generation.

source
StochasticIntegrals.ForwardCovarianceType
ForwardCovariance

Creates an ForwardCovariance struct. This contains :

  • An Itoset.
  • The time from which the covariance period starts.
  • The time to which the covariance period extends to.

And in the constructor the following items are generated and stored in the object:

  • A covariance matrix
  • Labels for the covariance matrix.
  • The cholesky decomposition of the covariance matrix.
  • The inverse of the covariance matrix.
  • The determinant of the covariance matrix.

The constructors are:

ForwardCovariance(ito_set_::ItoSet, from_::Real, to_::Real;
                  calculate_chol::Bool = true, calculate_inverse::Bool = true, calculate_determinant::Bool = true)
ForwardCovariance(ito_set_::ItoSet, from::Union{Date,DateTime}, to::Union{Date,DateTime})
ForwardCovariance(old_ForwardCovariance::ForwardCovariance, from::Real, to::Real)
ForwardCovariance(old_ForwardCovariance::ForwardCovariance, from::Union{Date,DateTime}, to::Union{Date,DateTime})
source
StochasticIntegrals.SimpleCovarianceType
SimpleCovariance

Creates an SimpleCovariance struct. This is a simplified version of ForwardCovariance and is designed for ItoIntegrals that are constant (so correlations do not need to be recalculated). This computational saving is the only advantage - ForwardCovariance is more general. It contains the same elements as a ForwardCovariance:

  • An Itoset
  • The time from which the covariance period starts.
  • The time to which the covariance period extends to.

And in the constructor the following items are generated and stored in the object:

  • A covariance matrix
  • Labels for the covariance matrix.
  • The cholesky decomposition of the covariance matrix.
  • The inverse of the covariance matrix.
  • The determinant of the covariance matrix.

The constructors are:

SimpleCovariance(ito_set_::ItoSet, from_::Real, to_::Real;
     calculate_chol::Bool = true, calculate_inverse::Bool = true, calculate_determinant::Bool = true)
source

Random Number Generation

StochasticIntegrals.NumberGeneratorType
A `NumberGenerator` must always return a vector of uniforms when called with the function `next!(::NumberGenerator)`.
It can contain whatever it wants as long as it does that method.
source
Sobol.next!Function
next!(number_generator::NumberGenerator)

This extracts a random draw given a number generator struct (like a SobolGen, Mersenne or Stable_RNG).

source
StochasticIntegrals.get_drawsFunction
get_draws(covar::ForwardCovariance; uniform_draw::Array{T,1} = rand(length(covar.covariance_labels_))) where T<:Real

Inputs

  • covar - An ForwardCovariance or SimpleCovariance struct that you want to draw from.
  • uniform_draw- The draw vector (from the uniform distribution)

Returns

  • A Dict of draws.
source
get_draws(covar::Union{ForwardCovariance,SimpleCovariance}, num::Integer; number_generator::NumberGenerator = Mersenne(MersenneTwister(1234), length(covar.covariance_labels_)), antithetic_variates = false)

get pseudorandom draws from a ForwardCovariance struct. Other schemes (like quasirandom) can be done by inserting quasirandom numbers in as the uniformdraw. If the `antitheticvariates` control is set to true then every second set of draws will be antithetic to the previous.

Inputs

  • covar - An ForwardCovariance or SimpleCovariance struct that you want to draw from.
  • num- The number of draws you want
  • number_generator- How you want to generate random draws.
  • antithetic_variates - Do you want antithetic variate sampling.

Returns

  • A Vector of Dicts of draws.
source
StochasticIntegrals.get_zero_drawsFunction
get_zero_draws(covar::ForwardCovariance)

get a draw of zero for all ItoIntegrals. This may be handy for bug hunting.

Inputs

  • covar - the ForwardCovariance struct that you want zero draws from

Outputs

  • A Dict of zero draws
source
get_zero_draws(covar::ForwardCovariance, num::Integer)

get an array of zero draws for all ItoIntegrals. May be handy for bug hunting.

Inputs

  • covar - the ForwardCovariance struct that you want zero draws from
  • num - The number of zero draws you want.

Outputs

  • A Vector of Dicts of zero draws
source

Ito Processes

StochasticIntegrals.ItoProcessType

A struct representing an Itoprocess.

Members

  • t0 - The initial time of the ItoProcess
  • value - The initial value of the ItoProcess
  • drift - The drift of the ItoProcess.
  • stochastic - The stochastic process.
source
StochasticIntegrals.evolve!Function
evolve!(itoprocess::ItoProcess, stochastic::Real, new_time::Real)

Evolve the ItoProcess forward. This changes the time (t0) as well as the value.

Inputs

  • itoprocess - The ItoProcess to be evolved.
  • stochastic - A draw from the ItoIntegral.
  • new_time - The new time.

Return

Nothing. It changes the input ItoProcess

source
evolve!(itoprocesses::Union{Dict{Symbol,ItoProcess{R}},Dict{Symbol,ItoProcess}}, stochastics::Union{Dict{Symbol,R},Dict{Symbol,Real}}, new_time::Real) where R<:Real

Evolve the ItoProcess forward. This changes the time (t0) as well as the value.

Inputs

  • itoprocesses - A Dict of ItoProcesses
  • stochastic - A Dict of draws from the ItoIntegral.
  • new_time - The new time.

Return

Nothing. It changes the input ItoProcess

source
StochasticIntegrals.evolve_covar_and_ito_processes!Function
evolve_covar_and_ito_processes!(itoprocesses::Union{Dict{Symbol,ItoProcess{R}},Dict{Symbol,ItoProcess}}, covar::ForwardCovariance, new_time::Real; number_generator::NumberGenerator) where R<:Real

Evolve the ItoProcesses forward.

Inputs

  • itoprocesses - A Dict of ItoProcesses
  • covar - The covariance matrix.
  • new_time - The new time.
  • number_generator - The number generator

Return

  • The updated ItoProcesses
  • The Covariance matrix
source
evolve_covar_and_ito_processes!(itoprocesses::Union{Dict{Symbol,ItoProcess{R}},Dict{Symbol,ItoProcess}}, covar::SimpleCovariance, new_time::Real; number_generator::NumberGenerator) where R<:Real

Evolve the ItoProcesses forward.

Inputs

  • itoprocesses - A Dict of ItoProcesses
  • covar - The covariance matrix.
  • new_time - The new time.
  • number_generator - The number generator

Return

  • The updated ItoProcesses
  • The Covariance matrix
source
StochasticIntegrals.make_ito_process_syncronous_time_seriesFunction
make_ito_process_syncronous_time_series(ito_processes::Union{Dict{Symbol,ItoProcess{T}},Dict{Symbol,ItoProcess}},
                                                 covar::Union{ForwardCovariance,SimpleCovariance}, timegap::R, total_number_of_ticks::Integer;
                                                 number_generator::NumberGenerator = Mersenne(MersenneTwister(2), length(collect(keys(ito_processes))))) where R<:Real where T<:Real

Evolve the ItoProcesses forward.

Inputs

  • itoprocesses - A Dict of ItoProcesses
  • covar - The covariance matrix.
  • timegap - The time gap between ticks.
  • total_number_of_ticks - The total number of ticks.
  • number_generator The NumberGenerator used for the RNG.

Return

  • A DataFrame with the ticks.
source
StochasticIntegrals.make_ito_process_non_syncronous_time_seriesFunction
make_ito_process_non_syncronous_time_series(ito_processes::Union{Dict{Symbol,ItoProcess{R}},Dict{Symbol,ItoProcess}},
                                                 covar::Union{ForwardCovariance,SimpleCovariance}, update_rates::Union{OrderedDict{Symbol,D},Dict{Symbol,D},OrderedDict{Symbol,Distribution},Dict{Symbol,Distribution}},
                                                 total_number_of_ticks::Integer;
                                                 timing_twister::Union{StableRNG,MersenneTwister} = MersenneTwister(1),
                                                 ito_number_generator::NumberGenerator = Mersenne(MersenneTwister(2), length(collect(keys(ito_processes))))
                                                 ) where R<:Real where D<:Distribution

Evolve the ItoProcesses forward.

Inputs

  • itoprocesses - A Dict of ItoProcesses
  • covar - The covariance matrix.
  • update_rates - The update rates of the exponential waiting times between ticks for each asset.
  • total_number_of_ticks - The total number of ticks.
  • ito_twister The MersenneTwister used for the RNG.

Return

  • A DataFrame with the ticks.
source

Helper Functions

StochasticIntegrals.volatilityFunction
volatility(ito::ItoIntegral, on::Union{Date,DateTime})

Get the volatility of an ItoIntegral on a certain date.

Inputs

  • ito - The ItoIntegral you want the volatility for.
  • on - What instant do you want the volatility for.

Outputs

  • A scalar
source
volatility(ito::ItoSet, ito_integral_id::Symbol, on::Union{Date,DateTime})

Get volatility of an ito_integral on a date.

Inputs

  • ito - An ItoSet that you want the volatility for.
  • ito_integral_id - The key of the ito dict that you are interested in
  • on The time or instant you want the volatility for.

Returns

  • A scalar
source
volatility(covar::ForwardCovariance, index::Integer, on::Union{Date,DateTime})
volatility(covar::ForwardCovariance, id::Symbol, on::Union{Date,DateTime})

Get the volatility of an ForwardCovariance on a date.

Inputs

  • covar - An ForwardCovariance that you want the volatility for.
  • index - The key of the ito dict that you are interested in
  • on The time or instant you want the volatility for.

Returns

  • A scalar
source
StochasticIntegrals.varianceFunction
variance(ito::ItoIntegral, from::Real, to::Real)
variance(ito::ItoIntegral, base::Union{Date,DateTime}, from::Union{Date,DateTime}, to::Union{Date,DateTime})

Get the variance of an ItoIntegral from one point of time to another.

Inputs

  • ito - The ItoIntegral you want the variance for.
  • from - The time at which the integration starts.
  • to - The time at which the integration ends.

Outputs

  • A scalar
source
variance(covar::ForwardCovariance, id::Symbol)
variance(covar::ForwardCovariance, index::Integer)

Get the variance of an ForwardCovariance over a period.

Inputs

  • covar - An ForwardCovariance that you want the variance for.
  • id or index - The key/index of the ito dict that you are interested in

Returns

  • A scalar
source
StochasticIntegrals.covarianceFunction
covariance(ito1::ItoIntegral,ito2::ItoIntegral, from::Real, to::Real, gaussian_correlation::Real)
covariance(ito1::ItoIntegral,ito2::ItoIntegral, base::Union{Date,DateTime}, from::Union{Date,DateTime}, to::Union{Date,DateTime}, gaussian_correlation::Real)

Get the covariance of two ItoIntegrals over a certain period given the underlying Brownian processes have a correlation of gaussian_correlation.

Inputs

  • ito1 - The first ItoIntegral
  • ito2 - The second ItoIntegral
  • from - The start of the period
  • to - The end of the period
  • gaussian_correlation - The correlation between the brownians for each of the two itos. This should be in the range [-1,1].
  • on - What instant do you want the volatility for.

Outputs

  • A scalar
source
covariance(covar::ForwardCovariance, index_1::Integer, index_2::Integer)
covariance(covar::ForwardCovariance, id1::Symbol, id2::Symbol)

Get the covariance of two ito integrals in a ForwardCovariance over a period.

Inputs

  • covar - An ForwardCovariance that you want the covariance for.
  • index_1 or id1 - The key/index of the first ito that you are interested in
  • index_2 or id2 - The key/index of the second ito that you are interested in

Returns

  • A scalar
source
StochasticIntegrals.correlationFunction
correlation(ito::ItoSet, index1::Integer, index2::Integer)
correlation(ito::ItoSet, brownian_id1::Symbol, brownian_id2::Symbol)

Get correlation between brownian motions in an ItoSet.

Inputs

  • ito - An ItoSet that you want the correlation for two itos within.
  • index1 or brownian_id1 - The index/key for the first ito integral.
  • index2 or brownian_id2 - The index/key for the second ito integral.

Returns

  • A scalar
source
correlation(covar::ForwardCovariance, index_1::Integer, index_2::Integer)
correlation(covar::ForwardCovariance, id1::Symbol, id2::Symbol)

Get the correlation of two ItoIntegrals over a period.

Inputs

  • covar - An ForwardCovariance that you want the correlation for.
  • index_1 or id1 - The key/index of the first ito that you are interested in
  • index_2 or id2 - The key/index of the second ito that you are interested in

Returns

  • A scalar
source
StochasticIntegrals.pdfFunction
pdf(covar::ForwardCovariance, coordinates::Dict{Symbol,Real})

get the value of the pdf at some coordinates. Note that it is assumed that the mean of the multivariate gaussian is the zero vector.

Inputs

  • covar - the ForwardCovariance struct that you want to evaluate the pdf
  • coordinates - The coordinates you want to examine.

Outputs

  • A scalar
source
StochasticIntegrals.make_covariance_matrixFunction
make_covariance_matrix(ito_set_::ItoSet, from::Real, to::Real)

Make a covariance matrix given an ItoSet and a period of time. This returns a Hermitian covariance matrix as well as a vector of symbols representing the axis labelling on this Hermitian.

Inputs

  • ito_set_ - An ItoSet you want to make a covariance matrix from.
  • from - The (numeric) time from which the covariance span starts.
  • to - The (numeric) time at which the covariance span ends.

Returns

  • A Hermitian covariance matrix.
  • A Vector{Symbol} of labels for the covariance matrix.
source
StochasticIntegrals.log_likelihoodFunction
log_likelihood(covar::ForwardCovariance, coordinates::Dict{Symbol,Real})

get the log likelihood at some coordinates. Note that it is assumed that the mean of the multivariate gaussian is the zero vector.

Inputs

  • covar - the ForwardCovariance struct that you want to evaluate the log likelihood.
  • coordinates - The coordinates you want to examine.

Outputs

  • A scalar
source
StochasticIntegrals.brownians_in_useFunction
brownians_in_use(itos::Array{ItoIntegral,1}, brownians::Array{Symbol,1})

Determine which Browninan processes are used in an array of ItoIntegrals.

Inputs

  • itos - A dict containing each of the ito integrals
  • brownians - All possible brownians

Outputs

  • A Vector of what brownians are in use in itos
  • A Vector with the indices of these brownians.
source
StochasticIntegrals.update!Function
update!(sc::SimpleCovariance, from::Real, to::Real)

This takes a SimpleCovariance and updates it for a new span in time. The new span in time is between from and to. For SimpleCovariance this is done by just adjusting the covariances for the new time span (with corresponding adjustments) to the cholesky, inverse, etc.

The corresponding technique for a ForwardCovariance (which is also a StochasticIntegralsCovariance) is to feed it into a new ForwardCovariance constructor which will recalculate for the new span.

Inputs

  • sc - The SimpleCovariance struct.
  • from - The time from which you want the covariance for.
  • to - The time to which you want the covariance for.

Returns

Nothing. It juts updates the sc struct you pass in as an input.

source

Internal Functions

StochasticIntegrals.to_drawsFunction
to_draws(X::Array{T,2}; labels::Array{Symbol,1} = Symbol.("x", 1:size(X)[2]))
to_draws(dd::DataFrame; labels::Array{Symbol,1} =  Symbol.(names(dd)))

Convert array or dataframe to a vector of Dicts containing draws.

source
StochasticIntegrals.to_dataframeFunction
to_dataframe(X::Array{T,2}; labels::Array{Symbol,1} = Symbol.("x", 1:size(X)[2]))
to_dataframe(draws::Array{Dict{Symbol,T},1}; labels::Array{Symbol,1}  = collect(keys(draws[1])))

Convert Arrays or Vectors of Dicts to a DataFrame.

source
StochasticIntegrals.to_arrayFunction
to_array(draws::Array{Dict{Symbol,T},1}; labels::Array{Symbol,1}  = collect(keys(draws[1]))) where T<:Real
to_array(dd::DataFrame; labels::Array{Symbol,1} =  Symbol.(names(dd)))

Convert draws or a DataFrame to an array and a vector of column labels.

source
StochasticIntegrals.get_confidence_hypercubeFunction
get_confidence_hypercube(covar::ForwardCovariance, confidence_level::Real, data::Array{T,2}; tuning_parameter::Real = 1.0)

This returns the endpoints of a hypercube that contains confidence_level (%) of the dataset.

source