Code Monkey home page Code Monkey logo

economicscenariogenerators.jl's Introduction

EconomicScenarioGenerators.jl

Stable Dev Build Status Coverage

This package is in Technical Preview Stage: The API is stabilizing and tests are passing but it has not been used in practice for very long. Please report any issues, provide feedback, and request specific features using the Discussions or Issues in this repository.

Interested in developing economic scenario generators in Julia? Consider contributing to this package. Open an issue, create a pull request, or discuss on the Julia Zulip's #actuary channel.

Usage

EconoicScenarioGenerators.jl is now available via the General Registry. Install and use in the normal way:

  1. Add EconomicScenarioGenerators via Pkg
  2. import EconomicScenarioGenerators or using EconomicScenarioGenerators in your code

Examples

Importing packages

First, import both EconomicScenarioGenerators and FinanceModels:

using EconomicScenarioGenerators
using FinanceModels

Models

Interest Rate Models

  • Vasicek
  • CoxIngersolRoss
  • HullWhite

EquityModels

  • BlackScholesMerton

Interest Rate Model Examples

Vasicek

m = Vasicek(0.136,0.0168,0.0119,Continuous(0.01)) # a, b, σ, initial Rate
s = ScenarioGenerator(
        1,  # timestep
        30, # projection horizon
        m,  # model
    )

You can collect a single generated scenario lik so:

rates = collect(s)

And the package integrates with FinanceModels.jl:

YieldCurve(s)

will produce a yield curve object:

              ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Yield Curve (FinanceModels.Yield.Spline)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀           
              ┌────────────────────────────────────────────────────────────┐           
         0.04 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ Zero rates
              │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
              │⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
              │⠀⠀⠀⠀⠀⠀⡠⠎⠉⠉⠊⠉⠑⠦⠤⠤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⡠⠤⠤⠔│           
              │⠀⠀⠀⠀⢀⠖⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠑⠦⢄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⠤⠔⠒⠊⠉⠉⠀⠀⠀⠀⠀⠀│           
              │⠀⠀⠀⢰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠓⠒⠦⠤⢄⣀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠤⠔⠒⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
              │⠀⠀⠀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠒⠒⠒⠒⠊⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
   Continuous │⠀⠀⢰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
              │⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
              │⠀⡸⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
              │⢀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
              │⡸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
              │⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉│           
              │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
        -0.01 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│           
              └────────────────────────────────────────────────────────────┘           
              ⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀time⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀30⠀        

CoxIngersolRoss

A CIR model:

m = CoxIngersollRoss(0.136,0.0168,0.0119,Continuous(0.01))

Hull White Model using a Yields.jl YieldCurve

Construct a yield curve and use that as the arbitrage-free forward curve within the Hull-White model.

using FinanceModels, EconomicScenarioGenerators
rates =[0.01, 0.01, 0.03, 0.05, 0.07, 0.16, 0.35, 0.92, 1.40, 1.74, 2.31, 2.41] ./ 100
mats = [1/12, 2/12, 3/12, 6/12, 1, 2, 3, 5, 7, 10, 20, 30]


curve = FinanceModels.fit(
    Spline.Cubic(),
    CMTYield.(rates,mats),
    Fit.Bootstrap()
)


m = HullWhite(.1,.002,curve) # a, σ, curve

s = ScenarioGenerator(
        1/12,  # timestep
        30., # projection horizon
        m,  # model
    )

Create 1000 yield curves from the scenario generator:

n = 1000
curves = [YieldCurve(s) for i in 1:n]
```julia

Plot the result:

```julia
using Plots

times = 1:30
p=plot(title="EconomicScenarioGenerators.jl Hull White Model")

# plot the zero rates
for d in curves
    plot!(p,times,rate.(zero.(d,times)),alpha=0.2,label="")
end

plot!(times,rate.(zero.(curve,times)),line=(:black, 5), label="Given Yield Curve")
p
    

image

Equity Model Examples

BlackScholesMerton

m = BlackScholesMerton(0.01,0.02,.15,100.)

s = ScenarioGenerator(
               1,  # timestep
               30, # projection horizon
               m,  # model
           )

Instantiate an array of the projection with collect(s).

Plotted BSM Example

Plot 100 paths:

using Plots
projections = [collect(s) for _ in 1:100]

p = plot()

for p in projections
    plot!(0:30,p,label="",alpha=0.5)
end

p

BSM Paths

Correlated Scenarios

Combined with using Copulas, you can create correlated scenarios with a given copula. See ?Correlated for the docstring on creating a correlated set of scenario generators.

Example

Create two equity paths that are 90% correlated:

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, but do need same shape
g = ClaytonCopula(2,7) # highly dependendant model
c = Correlated(ss,g)

x = collect(c) # an array of tuples

using Plots

# get the 1st/2nd value from the scenario points
plot(getindex.(x,1))
plot!(getindex.(x,2))

plot_20

Other ESG packages

economicscenariogenerators.jl's People

Contributors

alecloudenback avatar lrnv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

economicscenariogenerators.jl's Issues

Test Cases for initial release

Currently implemented models:

Interest:

Vasicek

  • Correctness
  • API (partially defined and tested)

CoxIngersollRoss

  • Correctness
  • API (partially defined and tested)

HullWhite

  • Correctness
  • API (partially defined and tested)

Equity

BlackScholesMerton (#12)

  • Correctness
  • API (partially defined and tested)

Testing

  • Correctness would be for properties (ie moments, point to point relationships, arbitrage free vs calibration curve)
  • API would test for defined methods and iteration protocol

Add AAA ESG

Interest Rates

What needs to be done for interest rate scenarios:

  • Expose easier way to use constrained NelsonSiegel curves from Yields.jl
  • Port logic from AAA sample notebook in Learn repository
  • Should return a yield curve for each generated scenario/timestep.

Equity

What needs to be done for equity scenarios:

Reference: https://www.actuary.org/sites/default/files/pdf/life/c3supp_march05.pdf

Make package more integrated with FinanceModels

v0.5 updated the package to be compatible in a basic way, but left a few design questions unresolved:

  • is it a bad idea to return a tuple instead of an array?
  • How should these models be thought of w.r.t. FinanceModels. Are they subtypes of FinanceModels or do they need to be converted/wrapped?
    • Thought: individual scenario outcomes can be used to create a corresponding singular FinanceModel object, but can also be wrapped in a (to be developed) MonteCarlo object such that MonteCarlo valuations can be performed.
    • Is YieldCurve the right function to create an indivual instantiation?

Add yield curves as output from short rate models

The current output from the short rate models is currently the short rate itself. All these models have the neat feature that the yield curve at a simulated future point depends only on the short rate, the time, and initial state information. It would be good to have access to those, e.g. through

yield_curve(srm::ShortRateModel, short_rate, time)

Alternatively, one could build an iterator that gave both short rate and curve, or only the curve.

Uncessesary Allocations?

Why is there no speedup with pre-allocating the destination container?

m = BlackScholesMerton(0.01,0.02,.15,100.)
s = ScenarioGenerator(1/252,1.,m,Random.Xoshiro(123))
n = 10_000

function fc!(z,s)
    for v in z
        copyto!(v,s)
    end
end

using BenchmarkTools
@benchmark [collect($s) for _ in 1:n]

# this is virtually the same time as above and has a ton of allocations
@benchmark fc!(zc,$s) setup=(zc = [zeros(253) for _ in 1:n])


g(v,i) = copyto!(v,i)

# this doesn't allocate
@benchmark g(v,1:1000) setup=(v=zeros(Int,1000))


struct Squares
    count::Int
end

Base.iterate(S::Squares, state=1) = state > S.count ? nothing : (state*state, state+1)

Base.eltype(::Type{Squares}) = Int # Note that this is defined for the type
Base.length(S::Squares) = S.count

# this doesn't allocate
@benchmark copyto!(v,Squares(100)) setup=(v=zeros(Int,100))

Interest Rates: avoiding negative discount factors?

Currently, the implementation in the YieldCurve function will error if the discount factor becomes negative (e.g. turn the volatility parameter on the hull white tests up and it will encounter this scenario). Investigate alternative formulations which don't let the discount factor go negative.

RNG Management

What's the best way to handle passing an RNG for performance and control over generated scenarios?

current version fails to compile at first `using`

Hi, congratulations for your initiative!

I just tried cloning Yields.jl + EconomicScenarioGenerators.jl , then dev'd them. But it errors , when I try using EconomicScenarioGenerators.

Here the error message, AbstractEconomicModel not defined. I tried debugging, but other errors shot up and I did not get anywhere...

Thank you again!

julia>  Pkg.develop(path = ".\\..\\22T2_yields\\Yields.jl")
   Resolving package versions...
    Updating `C:\proj\Rprojs\PS1908\julia\22T2_ESG\Project.toml`
  [d7e99b2f] ~ Yields v1.2.0 `https://github.com/JuliaActuary/Yields.jl.git#master`  v1.2.0 `..\22T2_yields\Yields.jl`
    Updating `C:\proj\Rprojs\PS1908\julia\22T2_ESG\Manifest.toml`
  [d7e99b2f] ~ Yields v1.2.0 `https://github.com/JuliaActuary/Yields.jl.git#master`  v1.2.0 `..\22T2_yields\Yields.jl`

julia>  Pkg.develop(path = ".\\EconomicScenarioGenerators.jl")
   Resolving package versions...
    Updating `C:\proj\Rprojs\PS1908\julia\22T2_ESG\Project.toml`
  [1d18cbdc] + EconomicScenarioGenerators v0.1.1 `EconomicScenarioGenerators.jl`
    Updating `C:\proj\Rprojs\PS1908\julia\22T2_ESG\Manifest.toml`
  [4fba245c] + ArrayInterface v6.0.16
  [30b0a656] + ArrayInterfaceCore v0.1.10
  [b0d46f97] + ArrayInterfaceStaticArrays v0.1.2
  [1d18cbdc] + EconomicScenarioGenerators v0.1.1 `EconomicScenarioGenerators.jl`
  [615f187c] + IfElse v0.1.1
  [2ee39098] + LabelledArrays v1.10.2
  [aedffcd0] + Static v0.6.6
  [4607b0f0] + SuiteSparse

julia> using EconomicScenarioGenerators
[ Info: Precompiling EconomicScenarioGenerators [1d18cbdc-9ca7-45fd-a8b2-b9434f9145be]
ERROR: LoadError: UndefVarError: AbstractEconomicModel not defined
Stacktrace:
 [1] top-level scope
   @ C:\proj\Rprojs\PS1908\julia\22T2_ESG\EconomicScenarioGenerators.jl\src\EconomicScenarioGenerators.jl:10
 [2] include
   @ .\Base.jl:418 [inlined]
 [3] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)
   @ Base .\loading.jl:1318
 [4] top-level scope
   @ none:1
 [5] eval
   @ .\boot.jl:373 [inlined]
 [6] eval(x::Expr)
   @ Base.MainInclude .\client.jl:453
 [7] top-level scope
   @ none:1
in expression starting at C:\proj\Rprojs\PS1908\julia\22T2_ESG\EconomicScenarioGenerators.jl\src\EconomicScenarioGenerators.jl:1
ERROR: Failed to precompile EconomicScenarioGenerators [1d18cbdc-9ca7-45fd-a8b2-b9434f9145be] to C:\Users\elm\.julia\compiled\v1.7\EconomicScenarioGenerators\jl_41ED.tmp.
Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:33
  [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, ignore_loaded_modules::Bool)
    @ Base .\loading.jl:1466
  [3] compilecache(pkg::Base.PkgId, path::String)
    @ Base .\loading.jl:1410
  [4] _require(pkg::Base.PkgId)
    @ Base .\loading.jl:1120
  [5] require(uuidkey::Base.PkgId)
    @ Base .\loading.jl:1013
  [6] require(into::Module, mod::Symbol)
    @ Base .\loading.jl:997
  [7] eval
    @ .\boot.jl:373 [inlined]
  [8] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:1196
  [9] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base .\essentials.jl:716
 [10] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:714
 [11] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
    @ VSCodeServer c:\Users\elm\.vscode\extensions\julialang.language-julia-1.6.17\scripts\packages\VSCodeServer\src\eval.jl:211
 [12] (::VSCodeServer.var"#65#69"{Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\elm\.vscode\extensions\julialang.language-julia-1.6.17\scripts\packages\VSCodeServer\src\eval.jl:155
 [13] withpath(f::VSCodeServer.var"#65#69"{Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer c:\Users\elm\.vscode\extensions\julialang.language-julia-1.6.17\scripts\packages\VSCodeServer\src\repl.jl:184
 [14] (::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\elm\.vscode\extensions\julialang.language-julia-1.6.17\scripts\packages\VSCodeServer\src\eval.jl:153
 [15] hideprompt(f::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer c:\Users\elm\.vscode\extensions\julialang.language-julia-1.6.17\scripts\packages\VSCodeServer\src\repl.jl:36
 [16] (::VSCodeServer.var"#63#67"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\elm\.vscode\extensions\julialang.language-julia-1.6.17\scripts\packages\VSCodeServer\src\eval.jl:124
 [17] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging .\logging.jl:511
 [18] with_logger
    @ .\logging.jl:623 [inlined]
 [19] (::VSCodeServer.var"#62#66"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\elm\.vscode\extensions\julialang.language-julia-1.6.17\scripts\packages\VSCodeServer\src\eval.jl:201
 [20] #invokelatest#2
    @ .\essentials.jl:716 [inlined]
 [21] invokelatest(::Any)
    @ Base .\essentials.jl:714
 [22] macro expansion
    @ c:\Users\elm\.vscode\extensions\julialang.language-julia-1.6.17\scripts\packages\VSCodeServer\src\eval.jl:34 [inlined]
 [23] (::VSCodeServer.var"#60#61")()
    @ VSCodeServer .\task.jl:423

(22T2_ESG) pkg> st
      Status `C:\proj\Rprojs\PS1908\julia\22T2_ESG\Project.toml`
  [1d18cbdc] EconomicScenarioGenerators v0.1.1 `EconomicScenarioGenerators.jl`
  [d7e99b2f] Yields v1.2.0 `..\22T2_yields\Yields.jl`

ScenarioGenerator parameters

 s = ScenarioGenerator(
                      1/252,  # timestep
                      1., # projection horizon
                      m,  # model
                  )
julia> collect(s)
ERROR: ArgumentError: destination has fewer elements than required

Maybe 1 / ( 1/252) doesn't divide neatly?

Hull White Market Consistency

Why is this test broken? @kasperrisager I could use your expertise again 🤔

The test is intended to check that we can re-create a market price using the observed input curve.

This is the last issue to resolve before announcing the package as a technical preview more widely.

FinanceModels Compatibility

Followup to #46 , need to resolve issue with switching interpolation package from BSplineKit to DataInterpolations in FinanceModels v4.8

Local testing broken, seems related to market consistency issue

Hello, thank you for this package!

test results.

some what long session log, can skip to the bottom.

PS C:\proj\PS1908\julia\ESG_24T2\EconomicScenarioGenerators.jl\test> julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.2 (2024-03-01)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.10) pkg> activate .
  Activating project at `C:\proj\PS1908\julia\ESG_24T2\EconomicScenarioGenerators.jl\test`

(test) pkg> st
Status `C:\proj\PS1908\julia\ESG_24T2\EconomicScenarioGenerators.jl\test\Project.toml`
  [ae264745] Copulas v0.1.23
  [31c24e10] Distributions v0.25.108
  [1d18cbdc] EconomicScenarioGenerators v0.6.0 `C:\proj\PS1908\julia\ESG_24T2\EconomicScenarioGenerators.jl#main`
  [b9b1ffdd] FinanceCore v2.1.1
  [77f2ae65] FinanceModels v4.9.1
  [09f84164] HypothesisTests v0.11.0
  [860ef19b] StableRNGs v1.0.2
  [2913bbd2] StatsBase v0.34.3
  [28d57a85] Transducers v0.4.81
  [8dfed614] Test

(test) pkg> test EconomicScenarioGenerators
     Testing EconomicScenarioGenerators
      Status `C:\Users\elm\AppData\Local\Temp\jl_Bka5oe\Project.toml`
  [ae264745] Copulas v0.1.23
  [31c24e10] Distributions v0.25.108
  [1d18cbdc] EconomicScenarioGenerators v0.6.0 `C:\proj\PS1908\julia\ESG_24T2\EconomicScenarioGenerators.jl#main`
  [b9b1ffdd] FinanceCore v2.1.1
  [77f2ae65] FinanceModels v4.9.1
  [09f84164] HypothesisTests v0.11.0
  [860ef19b] StableRNGs v1.0.2
  [2913bbd2] StatsBase v0.34.3
  [28d57a85] Transducers v0.4.81
  [8dfed614] Test
      Status `C:\Users\elm\AppData\Local\Temp\jl_Bka5oe\Manifest.toml`
⌅ [47edcb42] ADTypes v0.2.7
  [1520ce14] AbstractTrees v0.4.5
  [d88a00a0] AccessibleOptimization v0.1.1
  [7d9f7c33] Accessors v0.1.36
  [33016aad] AccessorsExtra v0.1.68
  [79e6a3ab] Adapt v4.0.4
  [66dad0bd] AliasTables v1.0.0
  [dce04be8] ArgCheck v2.3.0
  [4fba245c] ArrayInterface v7.10.0
  [198e06fe] BangBang v0.4.1
  [9718e550] Baselet v0.1.1
  [62783981] BitTwiddlingConvenienceFunctions v0.1.5
  [2a0fbf3d] CPUSummary v0.2.4
  [49dc2e85] Calculus v0.5.1
  [d360d2e6] ChainRulesCore v1.23.0
  [fb6a15b2] CloseOpenIntervals v0.1.12
  [861a8166] Combinatorics v1.0.2
  [38540f10] CommonSolve v0.2.4
  [bbf7d656] CommonSubexpressions v0.3.0
  [34da2185] Compat v4.14.0
  [a33af91c] CompositionsBase v0.1.2
  [88cd18e8] ConsoleProgressMonitor v0.1.2
  [187b0558] ConstructionBase v1.5.5
  [ae264745] Copulas v0.1.23
  [adafc99b] CpuId v0.3.1
  [a8cc5b0e] Crayons v4.1.1
  [667455a9] Cubature v1.5.1
  [9a962f9c] DataAPI v1.16.0
  [82cc6244] DataInterpolations v4.7.2
  [02685ad9] DataPipes v0.3.14
  [864edb3b] DataStructures v0.18.20
  [e2d170a0] DataValueInterfaces v1.0.0
  [244e2a9f] DefineSingletons v0.1.2
  [163ba53b] DiffResults v1.1.0
  [b552c78f] DiffRules v1.15.1
  [b4f34e82] Distances v0.10.11
  [31c24e10] Distributions v0.25.108
  [ffbed154] DocStringExtensions v0.9.3
  [fa6b7ba4] DualNumbers v0.6.8
  [1d18cbdc] EconomicScenarioGenerators v0.6.0 `C:\proj\PS1908\julia\ESG_24T2\EconomicScenarioGenerators.jl#main`
  [4e289a0a] EnumX v1.0.4
  [e2ba6199] ExprTools v0.1.10
  [1a297f60] FillArrays v1.10.0
  [b9b1ffdd] FinanceCore v2.1.1
  [77f2ae65] FinanceModels v4.9.1
  [64ca27bc] FindFirstFunctions v1.2.0
  [f6369f11] ForwardDiff v0.10.36
  [069b7b12] FunctionWrappers v1.1.3
  [77dc65aa] FunctionWrappersWrappers v0.1.3
  [46192b85] GPUArraysCore v0.1.6
  [3e5b6fbb] HostCPUFeatures v0.1.16
  [34004b35] HypergeometricFunctions v0.3.23
  [09f84164] HypothesisTests v0.11.0
  [615f187c] IfElse v0.1.1
  [22cec73e] InitialValues v0.3.1
  [18e54dd8] IntegerMathUtils v0.1.2
  [8197267c] IntervalSets v0.7.10
  [3587e190] InverseFunctions v0.1.13
  [92d709cd] IrrationalConstants v0.2.2
  [82899510] IteratorInterfaceExtensions v1.0.0
  [692b3bcd] JLLWrappers v1.5.0
  [358108f5] JMcDM v0.7.15
  [b964fa9f] LaTeXStrings v1.3.1
  [10f19ff3] LayoutPointers v0.1.15
  [1d6d02ad] LeftChildRightSiblingTrees v0.2.0
  [2ab3a3ac] LogExpFunctions v0.3.27
  [e6f89c97] LoggingExtras v1.0.3
  [bdcacae8] LoopVectorization v0.12.169
  [1914dd2f] MacroTools v0.5.13
  [d125e4d3] ManualMemory v0.1.8
  [bcdb8e00] Metaheuristics v3.3.5
  [128add7d] MicroCollections v0.2.0
  [e1d29d7a] Missings v1.2.0
  [37188c8d] MvNormalCDF v0.3.1
  [77ba4419] NaNMath v1.0.2
  [6fe1bfb0] OffsetArrays v1.14.0
  [7f7a1694] Optimization v3.24.3
  [bca83a33] OptimizationBase v0.0.5
  [3aafef2f] OptimizationMetaheuristics v0.2.0
  [bac558e1] OrderedCollections v1.6.3
  [90014a1f] PDMats v0.11.31
  [1d0040c9] PolyesterWeave v0.2.1
  [aea7be01] PrecompileTools v1.2.1
  [21216c6a] Preferences v1.4.3
  [08abe8d2] PrettyTables v2.3.1
  [27ebfcd6] Primes v0.5.6
  [33c8b6b6] ProgressLogging v0.1.4
  [92933f4c] ProgressMeter v1.10.0
  [1fd47b50] QuadGK v2.9.4
  [3cdcf5f2] RecipesBase v1.3.4
  [731186ca] RecursiveArrayTools v3.13.0
  [189a3867] Reexport v1.2.2
  [ae029012] Requires v1.3.0
  [79098fc4] Rmath v0.7.1
  [f2b01f46] Roots v2.1.5
  [7e49a35a] RuntimeGeneratedFunctions v0.5.13
  [94e857df] SIMDTypes v0.1.0
  [476501e8] SLEEFPirates v0.6.42
  [0bca4576] SciMLBase v2.34.0
  [c0aeaf25] SciMLOperators v0.3.8
  [53ae85a6] SciMLStructures v1.1.0
  [eb7571c6] SearchSpaces v0.2.0
  [efcf1570] Setfield v1.1.1
  [66db9d55] SnoopPrecompile v1.0.3
  [a2af1166] SortingAlgorithms v1.2.1
  [276daf66] SpecialFunctions v2.3.1
  [171d559e] SplittablesBase v0.1.15
  [860ef19b] StableRNGs v1.0.2
  [aedffcd0] Static v0.8.10
  [0d7ed370] StaticArrayInterface v1.5.0
  [90137ffa] StaticArrays v1.9.3
  [1e83bf80] StaticArraysCore v1.4.2
  [82ae8749] StatsAPI v1.7.0
  [2913bbd2] StatsBase v0.34.3
  [4c63d2b9] StatsFuns v1.3.1
  [892a3eda] StringManipulation v0.3.4
  [2efcf032] SymbolicIndexingInterface v0.3.16
  [3783bdb8] TableTraits v1.0.1
  [bd369af6] Tables v1.11.1
⌅ [6aa5eb33] TaylorSeries v0.16.0
  [5d786b92] TerminalLoggers v0.1.7
  [8290d209] ThreadingUtilities v0.5.2
  [28d57a85] Transducers v0.4.81
  [3a884ed6] UnPack v1.0.2
  [3d5dd08c] VectorizationBase v0.21.66
  [48feb556] WilliamsonTransforms v0.1.4
  [7bc98958] Cubature_jll v1.0.5+0
  [efe28fd5] OpenSpecFun_jll v0.5.5+0
  [f50d1b31] Rmath_jll v0.4.0+0
  [0dad84c5] ArgTools v1.1.1
  [56f22d72] Artifacts
  [2a0f44e3] Base64
  [ade2ca70] Dates
  [8ba89e20] Distributed
  [f43a241f] Downloads v1.6.0
  [7b1f6079] FileWatching
  [9fa8497b] Future
  [b77e0a4c] InteractiveUtils
  [b27032c2] LibCURL v0.6.4
  [76f85450] LibGit2
  [8f399da3] Libdl
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [d6f4376e] Markdown
  [ca575930] NetworkOptions v1.2.0
  [44cfe95a] Pkg v1.10.0
  [de0858da] Printf
  [3fa0cd96] REPL
  [9a3f8284] Random
  [ea8e919c] SHA v0.7.0
  [9e88b42a] Serialization
  [6462fe0b] Sockets
  [2f01184e] SparseArrays v1.10.0
  [10745b16] Statistics v1.10.0
  [4607b0f0] SuiteSparse
  [fa267f1f] TOML v1.0.3
  [a4e569a6] Tar v1.10.0
  [8dfed614] Test
  [cf7118a7] UUIDs
  [4ec0a83e] Unicode
  [e66e0078] CompilerSupportLibraries_jll v1.1.0+0
  [deac9b47] LibCURL_jll v8.4.0+0
  [e37daf67] LibGit2_jll v1.6.4+0
  [29816b5a] LibSSH2_jll v1.11.0+1
  [c8ffd9c3] MbedTLS_jll v2.28.2+1
  [14a3606d] MozillaCACerts_jll v2023.1.10
  [4536629a] OpenBLAS_jll v0.3.23+4
  [05823500] OpenLibm_jll v0.8.1+2
  [bea87d4a] SuiteSparse_jll v7.2.1+1
  [83775a58] Zlib_jll v1.2.13+1
  [8e850b90] libblastrampoline_jll v5.8.0+1
  [8e850ede] nghttp2_jll v1.52.0+1
  [3f19e933] p7zip_jll v17.4.0+2
        Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading.Precompiling project...
  2 dependencies successfully precompiled in 15 seconds. 184 already precompiled.
     Testing Running tests...
Market Consistency: Test Failed at C:\Users\elm\.julia\packages\EconomicScenarioGenerators\QS4Ec\test\interest.jl:116
  Expression: ≈(mean(samples), market_price, rtol = 0.01)
   Evaluated: 155.73565310766418 ≈ 165.10176108340627 (rtol=0.01)

Stacktrace:
  [1] macro expansion
    @ C:\desktop\Julia-1.10.2\share\julia\stdlib\v1.10\Test\src\Test.jl:672 [inlined]
  [2] macro expansion
    @ C:\Users\elm\.julia\packages\EconomicScenarioGenerators\QS4Ec\test\interest.jl:116 [inlined]
  [3] macro expansion
    @ C:\desktop\Julia-1.10.2\share\julia\stdlib\v1.10\Test\src\Test.jl:1577 [inlined]
  [4] macro expansion
    @ C:\Users\elm\.julia\packages\EconomicScenarioGenerators\QS4Ec\test\interest.jl:112 [inlined]
  [5] macro expansion
    @ C:\desktop\Julia-1.10.2\share\julia\stdlib\v1.10\Test\src\Test.jl:1577 [inlined]
  [6] macro expansion
    @ C:\Users\elm\.julia\packages\EconomicScenarioGenerators\QS4Ec\test\interest.jl:77 [inlined]
  [7] macro expansion
    @ C:\desktop\Julia-1.10.2\share\julia\stdlib\v1.10\Test\src\Test.jl:1577 [inlined]
  [8] macro expansion
    @ C:\Users\elm\.julia\packages\EconomicScenarioGenerators\QS4Ec\test\interest.jl:76 [inlined]
  [9] macro expansion
    @ C:\desktop\Julia-1.10.2\share\julia\stdlib\v1.10\Test\src\Test.jl:1577 [inlined]
 [10] top-level scope
    @ C:\Users\elm\.julia\packages\EconomicScenarioGenerators\QS4Ec\test\interest.jl:4
Test Summary:            | Pass  Fail  Total  Time
InterestRateModel        |   19     1     20  7.7s
  Vasicek                |    6            6  0.9s
  CoxIngersollRoss       |    6            6  0.3s
  Hull White             |    7     1      8  6.5s
    with AbstractYield   |    3     1      4  5.5s
      Market Consistency |          1      1  2.1s
    with Rate            |    4            4  1.0s
ERROR: LoadError: Some tests did not pass: 19 passed, 1 failed, 0 errored, 0 broken.
in expression starting at C:\Users\elm\.julia\packages\EconomicScenarioGenerators\QS4Ec\test\interest.jl:2
in expression starting at C:\Users\elm\.julia\packages\EconomicScenarioGenerators\QS4Ec\test\runtests.jl:13
ERROR: Package EconomicScenarioGenerators errored during testing

some context

I ran tests because i had somewhat strange results running the instructions form the help pages

using FinanceModels, EconomicScenarioGenerators
rates =[0.01, 0.01, 0.03, 0.05, 0.07, 0.16, 0.35, 0.92, 1.40, 1.74, 2.31, 2.41] ./ 100
mats = [1/12, 2/12, 3/12, 6/12, 1, 2, 3, 5, 7, 10, 20, 30]


curve = FinanceModels.fit(
    Spline.Cubic(),
    CMTYield.(rates,mats),
    Fit.Bootstrap()
)


m = HullWhite(.1,.002,curve) # a, σ, curve

s = ScenarioGenerator(
    # 1/12,  # timestep
    1,  # timestep
        30., # projection horizon
        m,  # model
    )

n = 1000
curves = [YieldCurve(s) for i in 1:n];

using Plots

times = 1:30
p=plot(title="EconomicScenarioGenerators.jl Hull White Model")

# plot the zero rates
for d in curves
    plot!(p,times,rate.(zero.(d,times)),alpha=0.2,label="")
end

plot!(times,rate.(zero.(curve,times)),line=(:black, 5), label="Given Yield Curve")
p
    

I systematically got charts like here, where simulated curves were shifted upwards as compared to the initial curve, which does not look right : The scenarios should average to the input market data, so as to be market consistent. I am not completely sure if this applies in the price space or yield space, but anyway the chart seems off.

See attached file (chart saved from vscode into an SVG file, need to load an svg extension in VSCode in order to display it there)
plot_3

  • It looks related to issue #28 and #32 ?

Happy to help!

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.