Learn R Programming

Sim.DiffProc (version 2.5)

snssde: Numerical Solution of One-Dimensional SDE

Description

Different methods of simulation of solutions to stochastic differential equations one-dimensional.

Usage

snssde(N, M, T = 1, t0, x0, Dt, drift, diffusion, Output = FALSE,                
       Methods = c("SchEuler", "SchMilstein", "SchMilsteinS",
       "SchTaylor", "SchHeun", "SchRK3"), ...)

Arguments

N
size of process.
M
number of trajectories.
T
final time.
t0
initial time.
x0
initial value of the process at time t0.
Dt
time step of the simulation (discretization).
drift
drift coefficient: an expression of two variables t and x.
diffusion
diffusion coefficient: an expression of two variables t and x.
Output
if Output = TRUE write a Output to an Excel (.csv).
Methods
method of simulation ,see details.
...

Value

  • data.frame(time,x) and plot of process.

Details

The function snssde returns a trajectory of the process; i.e., x0 and the new N simulated values if M = 1. For M > 1, an mts (multidimensional trajectories) is returned, which means that M independent trajectories are simulated. Dt the best discretization Dt = (T-t0)/N. Simulation methods are usually based on discrete approximations of the continuous solution to a stochastic differential equation. The methods of approximation are classified according to their different properties. Mainly two criteria of optimality are used in the literature: the strong and the weak (orders of) convergence. The methods of simulation can be one among: Euler Order 0.5 , Milstein Order 1 , Milstein Second-Order , Ito-Taylor Order 1.5 , Heun Order 2 , Runge-Kutta Order 3.

See Also

diffBridge Creating Diffusion Bridge Models.PredCorr Predictor-Corrector Method for one-dimensional SDE. snssde2D numerical solution of two-dimensional SDE. PredCorr2D predictor-corrector method for two-dimensional SDE, snssde3D numerical solution of three-dimensional SDE, PredCorr3D Predictor-Corrector Method for three-dimensional SDE.

Examples

Run this code
## example 1
## Hull-White/Vasicek Model
## T = 1 , t0 = 0 and N = 1000 ===> Dt = 0.001 
 drift     <- expression( (3*(2-x)) )
 diffusion <- expression( (2) )
 snssde(N=1000,M=1,T=1,t0=0,x0=10,Dt=0.001,
 drift,diffusion,Output=FALSE)
 Multiple trajectories of the OU process by Euler Scheme
 snssde(N=1000,M=5,T=1,t0=0,x0=10,Dt=0.001,
 drift,diffusion,Output=FALSE)

## example 2
## Black-Scholes models
## T = 1 , t0 = 0 and N = 1000 ===> Dt = 0.001 
 drift     <- expression( (3*x) )
 diffusion <- expression( (2*x) )
 snssde(N=1000,M=1,T=1,t0=0,x0=10,Dt=0.001,drift,
 diffusion,Output=FALSE,Methods="SchMilstein")

## example 3
## Constant Elasticity of Variance (CEV) Models
## T = 1 , t0 = 0 and N = 1000 ===> Dt = 0.001 
 drift     <- expression( (0.3*x) )
 diffusion <- expression( (0.2*x^0.75) )
 snssde(N=1000,M=1,T=1,t0=0,x0=1,Dt=0.001,drift,
 diffusion,Output=FALSE,Methods="SchMilsteinS")

## example 4
## sde\ dX(t)=(0.03*t*X(t)-X(t)^3)*dt+0.1*dW(t)
## T = 100 , t0 = 0 and N = 1000 ===> Dt = 0.1 
 drift     <- expression( (0.03*t*x-x^3) )
 diffusion <- expression( (0.1) )
 snssde(N=1000,M=1,T=100,t0=0,x0=0,Dt=0.1,drift,
 diffusion,Output=FALSE,Methods="SchTaylor")

## example 5
## sde\ dX(t)=cos(t*x)*dt+sin(t*x)*dW(t) by Heun Scheme
 drift     <- expression( (cos(t*x)) )
 diffusion <- expression( (sin(t*x)) )
 snssde(N=1000,M=1,T=100,t0=0,x0=0,Dt=0.1,drift,
 diffusion,Output=FALSE,Methods="SchHeun")

## example 6
## sde\ dX(t)=exp(t)*dt+tan(t)*dW(t) by Runge-Kutta Scheme
 drift     <- expression( (exp(t)) )
 diffusion <- expression( (tan(t)) )
 snssde(N=1000,M=1,T=1,t0=0,x0=1,Dt=0.001,drift,
 diffusion,Output=FALSE,Methods="SchRK3")

Run the code above in your browser using DataLab