Solved – Using the sde package in R to simulate a SV model with leverage

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.

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:

Rate this post

Leave a Comment