EconomicScenarioGenerators.EconomicScenarioGenerators — Module
EconomicScenarioGeneratorsEconomic scenario generation: short-rate models (Vasicek, CoxIngersollRoss, HullWhite), an equity model (BlackScholesMerton), and copula-correlated multi-model simulation (Correlated).
For single-model interest-rate scenario generation, prefer FinanceModels.ShortRate.{Vasicek, CoxIngersollRoss, HullWhite} together with FinanceModels.simulate/pv_mc (FinanceModels ≥ 6), which are the maintained successors of this package's generators. This package remains the home of Correlated — copula-correlated simulation across multiple models — which FinanceModels does not provide.
EconomicScenarioGenerators.BlackScholesMerton — Type
BlackScholesMerton(r,q,σ,initial)An equity price model where initial is the initial value of the security.
ris the risk free rateqis the dividend yieldσis the volatility for the unit period
Example
julia> using EconomicScenarioGenerators, Random
julia> m = BlackScholesMerton(0.01,0.02,.15,100.)
BlackScholesMerton{Float64, Float64, Float64}(0.01, 0.02, 0.15, 100.0)
julia> s = ScenarioGenerator(1/252, 1.0, m, Xoshiro(123));
julia> prices = collect(s);
julia> length(prices)
253
julia> first(prices), last(prices)
(100.0, 85.41947139805312)EconomicScenarioGenerators.Correlated — Type
Correlated(v::Vector{ScenarioGenerator},copula,RNG::AbstractRNG)Uses the given copula to correlate the outcomes of the underlying ScenarioGenerators. The copula returns the sampled CDF which the individual models will interpret according to their own logic (e.g. the random variate for the BlackScholesMerton model assumes a normal variate within the diffusion process).
The time and timestep of the underlying ScenarioGenerators are asserted to be the same upon construction.
Like ScenarioGenerator, a Correlated is a Transducers.jl-foldable collection (collectable; no iterate protocol). Each element is an NTuple holding all models' values at one timestep — collect(c) returns a vector over timesteps of n-tuples, not one time series per model.
Examples
using EconomicScenarioGenerators, Copulas
m = BlackScholesMerton(0.01,0.02,.15,100.)
s = ScenarioGenerator(
1, # timestep
30, # projection horizon
m, # model
)
ss = [s,s] # these don't have to be the exact same
g = ClaytonCopula(2,7)
c = Correlated(ss,g)
# collect a vector of two correlated paths.
collect(c)EconomicScenarioGenerators.CoxIngersollRoss — Type
CoxIngersollRoss(a,b,σ,initial::FinanceCore.Rate)A one-factor interest rate model. Parameters:
acharacterizes the speed of mean reversionbis the long term mean levelσis the instantaneous volatility
Via Wikipedia: https://en.wikipedia.org/wiki/Cox%E2%80%93Ingersoll%E2%80%93Ross_model
Discretization: partial-truncation Euler (Deelstra–Delbaen) — the diffusion term uses √(max(r, 0)) so that a path which crosses zero does not throw a DomainError, while the drift continues to pull the untruncated state back toward b.
Can be reinterpreted as a yield curve from FinanceModels.jl with YieldCurve(s::ScenarioGenerator)
Example
julia> using EconomicScenarioGenerators, FinanceModels, Random
julia> m = CoxIngersollRoss(0.136,0.0168,0.0119,Continuous(0.01))
CoxIngersollRoss{Rate{Float64, Continuous}}(0.136, 0.0168, 0.0119, Continuous(0.01))
julia> s = ScenarioGenerator(
0.5, # timestep
30.0, # projection horizon
m,
Xoshiro(1) # optional RNG for reproducibility
);
julia> rates = collect(s);
julia> length(rates)
61
julia> first(rates), last(rates)
(Continuous(0.01), Continuous(0.019221574072034602))
julia> YieldCurve(s) isa FinanceModels.Yield.AbstractYieldModel # build a curve from a fresh path
trueEconomicScenarioGenerators.HullWhite — Type
HullWhite(a,σ,curve)A one-factor interest rate model that should be market consistent with the given curve. curve may be:
- a FinanceModels.jl yield model (requires
using FinanceModels), in which case θ is derived from the curve's instantaneous forwards via automatic differentiation, or - a
FinanceCore.Rateor plainReal, interpreted as a flat (continuously compounded, forReal) curve with a closed-form θ.
Via Wikipedia
EconomicScenarioGenerators.ScenarioGenerator — Type
ScenarioGenerator(timestep::M,endtime::N,model,RNG::AbstractRNG) where {M<:Real, N<:Real}A ScenarioGenerator yields the time series of the model at gridpoints 0:timestep:endtime. It takes the parameters of the scenario generation such as timestep and endtime (the time horizon). model is any EconomicModel from the EconomicScenarioGenerators package.
A ScenarioGenerator is a Transducers.jl-foldable collection: it can be collected or used with transducer pipelines (sg |> Map(f) |> collect). It does not implement Julia's iterate protocol, so for x in sg is not supported.
Examples
using EconomicScenarioGenerators, FinanceModels
m = Vasicek(0.136,0.0168,0.0119,Continuous(0.01)) # a, b, σ, initial Rate
s = ScenarioGenerator(
1, # timestep
30, # projection horizon
m, # model
)EconomicScenarioGenerators.Vasicek — Type
Vasicek(a,b,σ,initial::FinanceCore.Rate)A one-factor interest rate model. Parameters:
acharacterizes the speed of mean reversionbis the long term mean levelσis the instantaneous volatility
See more on Wikipedia: https://en.wikipedia.org/wiki/Vasicek_model
Can be reinterpreted as a yield curve from FinanceModels.jl with YieldCurve(s::ScenarioGenerator)
Example
julia> using EconomicScenarioGenerators, FinanceModels, Random
julia> m = Vasicek(0.136,0.0168,0.0119,Continuous(0.01))
Vasicek{Rate{Float64, Continuous}}(0.136, 0.0168, 0.0119, Continuous(0.01))
julia> s = ScenarioGenerator(
0.5, # timestep
30.0, # projection horizon
m,
Xoshiro(1) # optional RNG for reproducibility
);
julia> rates = collect(s);
julia> length(rates)
61
julia> first(rates), last(rates)
(Continuous(0.01), Continuous(0.03707878263496358))
julia> YieldCurve(s) isa FinanceModels.Yield.AbstractYieldModel # build a curve from a fresh path
true