euler | R Documentation |
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)
)
f |
function f(x) or f(t,x) giving the drift term in the SDE |
g |
function g(x) or g(t,x) giving the noise term in the SDE |
times |
numeric vector of time points, increasing |
x0 |
numeric vector giving the initial condition |
B |
sample path of (multivariate) BrowniaĆ motion. If omitted, a sample is drawn using rvBM |
p |
Optional projection function that at each time poins projects the state, e.g. to enforce non-negativeness |
h |
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.