next up previous
Next: Periodogram Analysis of the Up: No Title Previous: Reading in the Data

Simulating from the Model.

  Next, we use the model of a geometric random walk to to develop a simulation model which will produce probabilistically indistinguishable Dow-Jones series if the model is true. We produce 19 simulated series and plot those in a 4 by 5 matrix of plots with the real one plotted in a random position.

The basic idea of the simulation is that if the geometric random walk model of (1) is true, then the at's are given by  
 \begin{displaymath}
a_t \; = \; Z_t - Z_{t-1} \; = \; \nabla Z_t ,\end{displaymath} (2)
the differenced Zt series. Now if they are independent and have a common distribution (no matter what that distribution is), then if we randomly reorder the values of them, it will be the same from a probabilistic point of view. The Splus function ``sample'' allows us to do that random reordering. Let $\tilde{a}_t$ denote the reordered values. Then keeping the starting value of the random walk the same Z0, we obtain another random walk by  
 \begin{displaymath}
\tilde{Z}_t \; = \; {Z}_0 \, + \, \tilde{a}_t .\end{displaymath} (3)
Of course, we have to exponentiate to get back to the original scale.

Here's the Splus code to do the shuffling and plotting. The ``cumsum'' function computes cumulative sums - exactly what is needed to undo the differencing.

> #First get help on the "sample" function. I always forget how it works.
> help(sample,window=T)
Starting an X11 help window for 'sample' with less as the pager.
> #OK, the plain vanilla sample function is all I need for
> #  randomly reshuffling the dldj values.  But first let's get a random
> #  sample of size 1 from the integers 1 to 20 to get random spot for the
> #  real one.
> real1_sample(1:20,size=1)
> # Oh, yeah, let's try out the cumsum function on a trivial case:
> #   get the cumulative sums of the sequence 1,2,3:
> cumsum(1:3)
[1] 1 3 6
> # Notice it doesn't start at 0, so I have to add that in
> par(mfrow=c(4,5)) #this says to plot multiple figures by rows in
> #   a 4 by 5 matrix of plots
> for(i in 1:20) {
+ if(i == real1) tsplot(dj)
+ else tsplot(10^(dj[1]+c(0,cumsum(sample(dldj)))))}
> #Hmm.  I think I know where it is.  Let's see if I'm right.
> real1
[1] XX-CENSORED
> #that's it!  Ask me if things aren't clear to you.
The plot is in Figure 3. Can you spot the real one? Of course, if you went to class, you know where it is.


  
Figure 3: Nineteen simulated Dow-Jones series and the real one (somewhere).
\begin{figure}
\centering

\setlength {\unitlength}{1 in}
 
\begin{picture}
(6,5...
 ...ale=80}}

\thicklines 
 \end{picture}
\setlength {\unitlength}{1 pt}\end{figure}


next up previous
Next: Periodogram Analysis of the Up: No Title Previous: Reading in the Data
Dennis Cox
2/13/1999