Random Walks

EC 313 Spring 2000

A Random Walk is a sequence in which each element is independent of the past history of the sequence. In 2-space,the classic Random Walk is the "drunkard's progress", where the path of the sequence is likened to the staggering of a drunkard, each successive step being in a random direction. We will first examine a Random Walk in 2-space.

This Mathematica program, by Roman Maeder (from Programming in Mathematica, (c) Addison-Wesley, 1989) is written as a Package. The RandomWalk function takes a single integer argument: the number of steps in the sequence. The initialization of the block sets the starting point for the sequence at {0,0} and defines the set of {x,y} points as a Table. The range {0, 2 Pi}, describing one complete cycle of the trigonometric (sine and cosine) functions, is defined.

For each point, the Random function is called, generating a uniform random number over this range, and the x- and y-coordinates of the step are generated as the cosine and sine of the random variate, which are constrained to the {-1, 1} interval. This ensures that the step will be of unit length (easily verified by applying the Pythagorean theorem) in a random direction. The "+=" operator is used to update the current location to incorporate the step, and the loop continues to the next point.

Following generation of the specified number of points, they are graphed in the {x,y} plane.The graph may be scaled to any desired size by selecting the graph and dragging the corner.

Implementation

BeginPackage["`RandomWalk`"]

RandomWalk::usage = "RandomWalk[n] plots a random walk of length n."

Begin["`Private`"]

RandomWalk[n_Integer] :=
	Block[{loc = {0.0, 0.0}, dir, points = Table[0, {n+1}], range = N[{0, 2Pi}]},
		points[[1]] = loc;
		Do[
			dir = Random[Real, range];
			loc += {Cos[dir], Sin[dir]};
			points[[i]] = loc,
		   {i, 2, n+1}];
		Show[ Graphics[{Point[{0,0}], Line[points]}],
		      Frame->True, AspectRatio->Automatic ]
	]

End[]

Protect[ RandomWalk ]

EndPackage[]

Execution

RandomWalk[1000];

Gaussian Random Walk

As interesting as this drunkard's progress might be (and as "Brownian motion," it describes the motion of molecules in a fluid,such as the atmosphere or water) the application of the Random Walk in economics and finance has taken a different tack.The Gaussian random walk,where each element of a series is taken to be the last element plus a random element,is a special case of the simple autoregressive (AR(1)) model
 (Subscript[y, t]) =  θ (Subscript[y, t - 1]) + (Subscript[ϵ, t]),  
      with ϵ~N(0, (σ^2) ). 
 The Random Walk is the AR(1) model with θ = 1, which may be rewritten as 
 Δ(Subscript[y, t]) = (Subscript[ϵ, t]) where Δ is the first difference operator.
 
 The AR(1) process, with | θ |< 1, has a zero mean, a finite variance and infinite memory: that is, the value of \(TraditionalForm\`\(\(y\_t\)\(\ \)\(at\)\(\ \)\(every\)\(\ \)\(point\)\(\ \)\(in\)\(\ \)\(time\)\(\ \)\)\)can be written as a weighted average of all past values of y, with the weights as powers of θ. When θ -> 1, however, the dynamics of this process change completely. The process is no longer covariance stationary: that is, neither its mean nor its variance is constant over time. In fact, the variance of the process is infinite, as may be readily shown. At the same time, the memory of the process vanishes: no longer does the past history of the process have any predictive power for future realizations. The level of \(TraditionalForm\`\(\(y\_t\ depends\)\(,\)\(\ \)\(of\ course\)\(,\)\(\ \)\(on\)\(\ \)\)\)the previous value; but the increments in the series (the Δ(Subscript[y, t])) are purely random. Compare this to the motion of the AR(1) process, where the best prediction of the process tomorrow is θ (Subscript[y, t]), so that the predicted change will be (θ – 1) (Subscript[y, t]). Since one can estimate θ from a suitably long history of (Subscript[y, t]), the predictions from an AR(1) process will be mean-reverting (toward the mean of zero). The optimal predictions from a random walk are naïve forecasts: that is, the best prediction of the change in the series is zero, so the best forecast of where it will be tomorrow is where it is today. 
 
 This has great relevance for the behavior of the prices of financial assets in efficient markets. One definition of market efficiency is that no available information can be used to systematically predict price movements, for all such information should be already incorporated into the market's price of that asset. Thus, studies have often cited that, e.g., stock prices on major markets follow a random walk, as exemplified by Malkiel's famous book A Random Walk Down Wall Street. One may question whether stock prices are generated by an efficient market; the presence of private ("insider") information may impart deviations from efficiency, as may many other microstructure features of the market (such as the NYSE's specialist system). But the random walk model of stock prices has very powerful predictions–implying, for instance, that the entire body of "technical analysis" practiced by chartists is quite worthless. Fundamental analysis–focusing on firms' financials, and market prospects–can be of value, for it can generate informed forecasts of future firm value; but patterns in stock price or stock index movements, in a truly random-walk environment, will have no predictive power (despite the army of "technicians" looking for "head and shoulders" and "inverted double bottom" patterns, "resistance" and "support", and deviations from a moving average).
 
 With this background, let us use Mathematica to generate some random walk stock price trajectories, and compare them to historical trajectories of stock prices.

BeginPackage["`GaussianRandomWalk`"];

GaussianRandomWalk::usage = "GaussianRandomWalk[n,sigma] plots a Gaussian random walk of length n with a standard deviation of the error process equal to sigma."
priceHistory::usage = "priceHistory is the simulated price history generated by GaussianRandomWalk."
logPriceRel::usage = "logPriceRel is the simulated returns series generated by GaussianRandomWalk."
Begin["`Private`"] ;
Needs["Statistics`NormalDistribution`"];
GaussianRandomWalk[n_Integer,sigma_Real] :=
	Block[{loc = 100.0, z, ndist, points = Table[0, {n+1}]},
		logPriceRel=Table[0,{n+1}];
		points[[1]] = loc;
		ndist=NormalDistribution[0,sigma];
		z=RandomArray[ndist,n+1];
		Do[
			loc += z[[i]];
			points[[i]] = loc;
			logPriceRel[[i]] = Log[points[[i]]]-Log[points[[i-1]]],
		   {i, 2, n+1}];
		   priceHistory=points;
		  	ListPlot[points,{PlotJoined->True}]
	];
End[];
Protect[ GaussianRandomWalk ];
EndPackage[];

GaussianRandomWalk[500, 2.0]

<< Statistics`DescriptiveStatistics`
Mean[logPriceRel]
Quartiles[logPriceRel]
DispersionReport[logPriceRel]
ShapeReport[logPriceRel]
ListPlot[logPriceRel]

<< Statistics`DataManipulation`
<< Graphics`Graphics`
freq = 
        BinCounts[
          logPriceRel, {-0.05, 0.05, 0.01}];
midpts = 
        Table[x, {x, -0.045, 0.045, 0.01}];
BarChart[Transpose[{freq, midpts}]]

Get FTA All Share price index and nominal returns, monthly, 1965-1995 (372 observations) from http://www.lboro.ac.uk/departments/ec/cup/data.html

SetDirectory["Sleek4:[SleekShare]:[Mills2ed]"]
ftaprice =  
        ReadList["FTAPRICE.txt"];
ftaret = ReadList["FTARET.txt"];

ListPlot[ftaprice, {PlotJoined -> True}]

<< Statistics`DescriptiveStatistics`
<< Statistics`DataManipulation`
<< Graphics`Graphics`
Mean[ftaret]
Quartiles[ftaret]
DispersionReport[ftaret]
ShapeReport[ftaret]
ListPlot[ftaret]

freq = 
        BinCounts[
          ftaret, {-0.15, 0.25, 0.05}];
midpts = 
        Table[x, {x, -0.125, 0.225, 0.05}];
BarChart[Transpose[{freq, midpts}]]