knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

This R package provides functionality for stochastic differential equations in terms of:

The package supports the textbook [@Thygesen2023sde] by implementing algorithms described in the book, so it provides the computational framework to accompany the theory. It has been used to produce almost all figures in the book.

Installation

To install the package, open R and run

devtools::install_github("Uffe-H-Thygesen/SDEtools")

Alternatively, clone the github repo to your local machine and "make install" it, if you are familiar with make and makefiles.

Then load the package with

library(SDEtools)

Example

This is a basic example which shows you how to simulate a sample path, and compute the transition probability, for a double well model:

library(SDEtools)
## The double well model is dX = f(X)*dt + g(X)*dB with:
f <- function(x) x-x^3
g <- function(x) 0.5

## Define a time grid and simulate the process
tv <- seq(0,100,0.1)
sim <- heun(f,g,tv,0)

plot(tv,sim$X,type="l",ylim=c(-1.5,1.5))

## Compute the stationary density using a spatial grid
xi <- seq(-1.5,1.5,0.01)
xc <- cell.centers(xi)

## Define the diffusivity
D <- function(x) 0.5*g(x)^2

## Compute the generator
G <- fvade(f,D,xi,'r')

## Compute the stationary distribution
rho <- StationaryDistribution(G)

## Rescale and add to the plot
lines(20*rho/max(rho),xc)

Tour of features

Please see the vignettes which showcase functionality.

References



Uffe-H-Thygesen/SDEtools documentation built on Jan. 15, 2025, 6:41 p.m.