Skip to content

Tools for working with stochastic differential equation models in Julia

License

Notifications You must be signed in to change notification settings

Godisemo/SDEModels.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SDEModels

Tools for working with stochastic differential equation models.

Build Status Coverage Status codecov.io

See the talk from JuliaCon 2018 about SDEModels.jl

The main feature of this package is that it allows you to define SDE models in a compact form, similar to the mathematical definition.

@sde_model BlackScholes dS = r*S*dt + σ*S*dW

The @sde_model macro figures out the properties of your model, and generates all code that is necessary. In this case, the code generated is:

  struct BlackScholes <: AbstractSDE{1,1} # 1 dimension and 1 wiener process
    r::Float64
    s::Float64
  end

  function drift(model::BlackScholes, x)
    model.r * x
  end

  function diffusion(model::BlackScholes, x)
    model.σ * x
  end

It is easy to see how defining your models can become cumbersome, especially when you are working with multidimensional SDEs. You can define multivariate models as

@sde_model Heston begin
  dS =     r*S*dt + sqrt(V)*S*dW1
  dV = κ*-V)*dt + σ*sqrt(V)*dW2
  dW1*dW2 = ρ*dt
end

which generates the code

  # the parameters are arranged in the order of appearance
  struct Heston <: AbstractSDE{2,2} # 2 dimension and 2 wiener process
    r::Float64
    κ::Float64
    θ::Float64
    σ::Float64
    ρ::Float64
  end

  # x is assumed to be arranged in the order of appearance, i.e [S, V]
  function drift(model::Heston, x)
    [model.r * x[1]
     model.κ*(model.θ-x[2])]
  end

  function diffusion(model::Heston, x)
    [sqrt(x[2])*x[1]        0
     model.σ*√x[2]*model.ρ  model.σ*sqrt(x[2])*sqrt(1-model.ρ^2)]
  end

About

Tools for working with stochastic differential equation models in Julia

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages