Ito Process - Simulations

Overview


An Ito process is an extension of the brownian motion. It is the workhorse of continuous time stochastic processes.
{% dX = u(x,t)dt + \sigma(x,t) dW %}

Simulating an Ito Process


Simulating an Ito process (or set of processes) can be accomplished using the ito module, hosted in the davinci library.


let ito = await import('/lib/statistics/simulations/v1.0.0/ito.mjs');
let data = [];
for(let i=0;i<5;i++){ 
  let sims=ito.generate(300, ()=>0, ()=>0.05)
  sims=sims.map(p =>({
    value:p,
    sim:(i+1).toString()
  }));
  data = [...data,...sims]
}

$val.set('data',data);

					
Try it!
copy

Correlated Ito Process


To generate a set of correlated Ito processes requires generating correlated guassian variables. Generating correlated guassians are provided for by the generateMultiple method of the ito library. The third parameter is a function that returns the covariance matrix.


let ito = await import('/lib/statistics/simulations/v1.0.0/ito.mjs');

let data = [];
for(let i=0;i<5;i++){ 
  let sims=ito.generateMultiple(300, ()=>[[0],[0]], ()=> [[1,0.5],[0.5,1]])
  sims = sims.map(p =>{
    return {
      value:p,
      sim:(i+1).toString()
    }
  });
  data = [...data,...sims]
}

					
Try it!

Geometric Brownian Motion


When simulating a Geometric Brownian Motion, care must be taken. The generic formula for a GBM is
{% d X(t) = \alpha X(t) dt + \sigma X(t) dW(t) %}
The important thing to note here is that the coefficients of each term are variable (that is, they each include an X(t) term). When running the simulation, we need to provide functions for the drift and volatility terms that multiply by the last value in the series.


let ito = await import('/lib/statistics/simulations/v1.0.0/ito.mjs');

let alpha = 0.01;
let vol = 0.2;
let mu = series => alpha * series[series.length-1];
let sigma = series => vol * series[series.length-1];
let data = [];
for(let i=0;i<5;i++){ 
  let sims=ito.generate(300, mu, sigma)
  sims = sims.map(p =>({
      value:p,
      sim:(i+1).toString()
  }));
  data = [...data,...sims]
}

					


There is a complication with this code however. Because we are discretizing the time interval, the value of X could go negative at some point, whereas in the theoretical geometric brownian motion, it cannot. The better way to run this simulation is to recognize the alternative way to write a geometric brownian motion as
{% d log X(t) = r dt + \sigma dW(t) %}
That is, we simulate the log of X, instead of X itself. Then to translate back, we just need the following:


  sims = sims.map(p =>({
      value:Math.exp(p),
      sim:(i+1).toString()
  }));
					


The full code is provided.


let ito = await import('/lib/statistics/simulations/v1.0.0/ito.mjs');

let init=0;
let r = 0.01;
let vol = 0.2;
let mu = (series)=> r;
let sigma = (series)=> vol;
let data = [];
for(let i=0;i<5;i++){ 
  let sims=ito.generate(300, mu, ()=>0.05, init)
  sims = sims.map(p =>({
      value:Math.exp(p),
      sim:(i+1).toString()
  }));
  data = [...data,...sims]
}

					

Contents