Believe it or not, but a drunk walking down the street is the basis for Stochastic Calculus. The sloppy walking motion of a drunk leads to some interesting models, some of the most complex of which are used to model financial derivatives.

A little story

Ralph really enjoys drinking pints of beer at his local pub, but unfortunately for Ralph, bars eventually close. When they do close, Ralph stumbles out the door and proceeds to perform the ‘Drunkard’s Walk’ as he wobbles down the street. With each step Ralph takes, he moves forward but he stumbles to either the left or right by a distance of one foot, where his chances of stumbling to the left or right on each step is equally likely. He will eventually make his way down to the end of the street, but he could end up far to the left or right compared to if he had walked along the straightest path.

The Stochastic Process

Below is an equation that we will use to model Ralph’s walk home.

W(n)= \begin{Bmatrix} W(n-1)+1 \: \text{with probability} \: 0.5 \\ W(n-1)-1 \: \text{with probability} \: 0.5 \end{Bmatrix} \\ \text{where} \\ W(0)=0

In this equation, W(n) is the distance in feet to the left of the straight path after the first n steps. We assume Ralph starts on the straightest path, which is why we add the condition W(0)=0.

Simulation

Too illustrate the above model of Ralph’s drunken walk, I’ve created a simple simulation. To run this simulation, simply select the number of steps you want Ralph to take, and see how far he ends up from the straightest path.

Number of drunken steps Ralph takes:

Javascript Code

For those interested, the following is the javascript code used to generate the chart above. It generates the drunkard’s path using the randomWalk() function, and generates the chart using the Google Visualization API. The call to chart.draw() inserts the chart into the specified div.

// Load Google Visualization API
google.load("visualization", "1", {packages:["linechart"]}); 
 
// Function: drawDrunkard
// n is the number of steps
function drawDrunkard(n) {
  // create and populate array
  var w = randomWalk(0.5, n);
 
  // create DataTable
  var data = new google.visualization.DataTable(); 
  data.addColumn('string', 'n'); 
  data.addColumn('number', 'Drunkard');  
 
  // populate DataTable
  data.addRows(n+1); 
  var label = '';
  for(var i=0; i<(n+1); i++){
    label = i+'';
    data.setValue(i, 0, label);
    data.setValue(i, 1, Math.round(w[i]*1000)/1000);
  }
 
  // Draw Chart 
  var chart = new google.visualization.LineChart(document.getElementById('drunkardWalk_div')); 
  chart.draw(data, {width:700, height:400, max:Math.sqrt(n), min:-1*Math.sqrt(n), enableTooltip:false, pointSize:0, legend:'none', lineSize:1, title:'Ralph\'s Walk Home', titleX:'Ralph\'s Footstep Number', titleY:'Distance to the Left of center (feet)', axisFontSize:10, titleFontSize:15}); 
}
 
// Function: randomWalk
// p is the probability of an up move
// n is the number of steps
function randomWalk(p, n) {
  var w=new Array(n+1); 
  w[0] = 0;
  var u = 0;
  for(i=1; i<(n+1); i++){
    u = Math.random();
    if(u>p){
      w[i] = w[i-1] - 1;
    } else {
      w[i] = w[i-1] + 1;          
    }
  }
  return w;
}

Leave a Reply