Using the sde package in R, I would like to simulate the following model for stock prices $p_t$:

$mathrm{d}sigma^2_t = (theta_1 – theta_2sigma^2_t)mathrm{d}t + theta_3sigma_tmathrm{d}W_{sigma,t}$ (CIR model used for stochastic volatility)

$mathrm{d}log{p_t} = sigma_tmathrm{d}W_{p,t}$

where correlation between $W_{p,t}$ and $W_{sigma,t}$ is possibly non-zero.

Q: Is that possible? Is it even possible to simulate multivariate SDEs in the "sde" package the way one can in S+FinMetrics using the `gensim`

functions? Is there another package in R that might do this?

I'm able to simulate the variance process simply enough with the following code:

`library(sde) sig2 <- sde.sim(X0=0.04, theta=c(0.3141, 8.0369, 0.43), model="CIR") `

I can then simulate the price series (starting with initial price = 100) using:

`logr <- rnorm(n=length(sig2),sd=sqrt(sig2)) logp <- cumsum(c(log(100),logr)) p <- exp(logp) `

But this approach seems unnecessarily clunky and can't capture non-zero correlation between the Brownian Motions.

#### Best Answer

## Hull-White/Vasicek Model: dX(t) = 3*(2-x)*dt+ 2*dw(t)

`> library(Sim.DiffProc) > 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=50,T=1,t0=0,x0=10,Dt=0.001,drift,diffusion,Output=FALSE) `

You can also use the package Sim.DiffProcGUI (Graphical User Interface for Simulation of Diffusion Processes).

### Similar Posts:

- Solved – Random walk with drift are differences white noise
- Solved – Autocovariance of an ARMA(2,1) process – derivation of analytical model for $gamma( k)$
- Solved – MA(1) model – prove that correlation of order two equals to zero
- Solved – How to simulate ARIMA with drift(using r)
- Solved – How to show that $E[(hattheta -theta)^2]<Var(bar X)=dfrac{1}{n}$