# rmilstein: Milstein Scheme for Stochastic Differential Equations In rpgm: Fast Simulation of Normal/Exponential Random Variables and Stochastic Differential Equations / Poisson Processes

## Description

If the process X_t is the unique strong solution of the process

dX_t = b(X_t)dt + s(X_t)dW_t,

then the Milstein Scheme is X[t+h] = X[t] + b(X[t])h + s(X[t])Z + 0.5*s'(X[t])*(Z^2 - h), where Z ~ N(0,h) (variance h), and s' is the differential function of s.

## Usage

 `1` ```rmilstein(n, m, x0, b, s, sx, t0 = 0, T = 1, all_dates = TRUE, delta = NULL) ```

## Arguments

 `n` integer, number of paths. `m` integer, number of steps, the step size will be T/m. `x0` numeric, starting point of the process. `b` function, the drift, a function which can take a vector and returns a vector. `s` function, the volatility, a function which can take a vector and returns a vector. `sx` function, the differential of the volatility, a function which can take a vector and returns a vector. `t0` double, the starting date of the process. `T` double, the final date of the process. `all_dates` logical, if TRUE, returns all steps from all paths. If FALSE, only returns the n final value X_T. `delta` double, the step size.

## Value

If `all_dates = TRUE`, it returns a n x m+1 matrix : n paths with m steps (+ the first value). Else, it returns a vector of length n with the simulations of the final dates X_T.

## Author(s)

Nicolas Baradel - PGM Solutions

## References

https://en.wikipedia.org/wiki/Milstein_method

## Examples

 ```1 2 3 4``` ```mu <- 0.07 sigma <- 0.20 rmilstein(5, 10, 1, function(x) return(mu*x), function(x) return(sigma*x), function(x) return(sigma)) ```

### Example output

```     [,1]      [,2]      [,3]      [,4]     [,5]      [,6]      [,7]      [,8]
[1,]    1 1.0533625 1.0271061 1.0797720 1.119593 1.1342900 1.0944747 1.1595887
[2,]    1 1.0205794 1.0217800 1.0659556 1.101957 0.9884711 1.0210811 0.9667245
[3,]    1 0.9928005 1.0306966 1.1377521 1.017713 0.9960424 0.9632566 0.9083929
[4,]    1 1.0126124 1.0367437 1.0184944 1.104423 1.1222356 1.1555864 1.2235908
[5,]    1 0.9471298 0.9294861 0.9533129 1.007129 1.0722700 1.1954079 1.2441727
[,9]     [,10]     [,11]
[1,] 1.0653542 0.9394955 0.9397999
[2,] 0.9240472 0.9209310 1.0066068
[3,] 0.8920531 0.9033853 1.1051406
[4,] 1.3366670 1.3319782 1.3163443
[5,] 1.2064591 1.2336388 1.3236321
```

rpgm documentation built on March 18, 2018, 2:24 p.m.