R/sdetools.R
euler.Rd
Euler simulation of an Ito stochastic differential equation dX = f dt + g dB
euler(
f,
g,
times,
x0,
B = NULL,
p = function(x) x,
h = NULL,
r = NULL,
S0 = 1,
Stau = runif(1)
)
function f(x) or f(t,x) giving the drift term in the SDE
function g(x) or g(t,x) giving the noise term in the SDE
numeric vector of time points, increasing
numeric vector giving the initial condition
sample path of (multivariate) Browniań motion. If omitted, a sample is drawn using rvBM
Optional projection function that at each time poins projects the state, e.g. to enforce non-negativeness
Optional stopping function; the simulation terminates if h(t,x)<=0
times <- seq(0,10,0.1)
# Plot a sample path of the solution of the SDE dX=-X dt + dB
plot(times,euler(function(x)-x,function(x)1,times,0)$X,type="l")
# Plot a sample path of the solution of the 2D time-varying SDE dX=(AX + FU) dt + G dB
A <- array(c(0,-1,1,-0.1),c(2,2))
F <- G <- array(c(0,1),c(2,1))
f <- function(t,x) A %*% x + F * sin(2*t)
g <- function(x) G
BM <- rBM(times)
plot(times,euler(f,g,times,c(0,0),BM)$X[,1],type="l")
# Add solution corresponding to different initial condition, same noise
lines(times,euler(f,g,times,c(1,0),BM)$X[,1],type="l",lty="dashed")