Statistics - Random Walk

1 - Walk

A random walk is a mathematical formalization of a path that consists of a succession of random steps. For example, the price of a fluctuating stock can be modelled as random walks. Half the time it goes up, half the time it goes down.

3 - Example

On a javascript canvas

width=600;
height=300;
 
randomWalk = ( function() {
  let y = height/2, values = [y];
  for (let x = 0; x < width; ++x) values.push(y = y + (Math.random() - 0.5) * 40 + (height/2 - y) * 0.1);
  return values;
})()
 
canvas = document.getElementById("graph");
context = canvas.getContext("2d");
context.beginPath();
context.moveTo(0, randomWalk[0]);
for (let x = 0; x < width; ++x) context.lineTo(x, randomWalk[x]);
context.lineJoin = context.lineCap = "round";
context.strokeStyle = "black";
context.stroke();
<canvas id="graph" width="600" height="300"></canvas>

data_mining/walk.txt · Last modified: 2018/03/28 22:47 by gerardnico