dummy-link

6

2

0

1

# SDEModels

Tools for working with stochastic differential equation models.

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
``````

04/27/2017

4 months ago

128 commits