a Wave Theory     part II

Once upon a time, long long ago ...
>When you were young and foolish?
Yes. I worked on a sorta wave theory, to see if stock prices had any periodicity.

In some kinda Wave Theory we obtained the equation:

(1)        P(n+1) = [ 2-(2π/T)2 ] P(n) - P(n-1) + (2π/T)2 P0


  • T is some kind of period (like T = 5 days)
  • P0 is some Moving Average (example: a 30 day Volume-weighted Moving Average: VMA)
  • P(n) is today's stock price and P(n-1) is the price yesterday
  • P(n+1) is the next stock price in the sequence ... namely tomorrow's price.
To understand the behaviour of a sequence defined by (1), we suppose P0 is constant at $20 and we start with
P(1) = $25, P(2) = $26 then use Equation (1) to calculate P(3), P(4), etc. for various values of T. We get:

Notice that the price sequence defined by (1) oscillates about P0 with a period very nearly equal to the value of T. Of course, we want P0 to change as time progresses ... so we make it equal to some Moving Average (and there are plenty of moving averages to choose from).

>Were you trying to predict tomorrow's price, based upon the last two prices?
Yes, the last two prices, P(n) and P(n-1), and the moving average, P0. I tried to determine if the predicted price,
that's P(n+1), went UP or DOWN when the actual stock price went UP or DOWN. I was encouraged when I was right about 75% - 80% of the time. Alas, when I tried it on a larger collection of stocks, I was only right about 50% of the time.  

>So you decided it was easier to toss a coin, eh?
Well, I decided to look again at equation (1) because I had nothing better to do while camping and ...
>Do you have a picture?

See Figure 1? It shows a couple of months of GE stock in 2002:
the actual closing price along with the predicted price, P(n+1), given by equation (1) with T = 5 and P0 = 30-day VMA.

>I can see why you gave up on that theory! It's a lousy predictor and ...
The UP/DOWN agreement is 48%. See the predictions with a black dot-in-the-centre? Them's the good ones (that went UP or DOWN when the stock price went UP or DOWN).

>I'm confused. Is P(n+1) tomorrow's price?
No. P(n+1) is tomorrow's price. P(n+1) is my prediction. See the difference in colour? The actual stock prices are P(1), P(2), P(3), ...
My predictions are P(1), P(2), P(3), ...

Okay, look at Figure 2.
There, we used T = 5 and P0 = 2-day VMA and the match seems better, although the UP/DOWN agreement is only 39%.

>So it's worse, not better ... yet it looks better, eh?
Yes. That's because the Average Absolute Error is less.
In Figure 1, the Average Error was 13% whereas in Figure 2 it's just 2%.

>Hey! I'd be happy with 2%!
Actually, the daily change in stock price was about 2% so I wouldn't be too pleased with 2%. I could just assume that tomorrow's price will be today's price and I get a 2% error, on average. What I want is some scheme which, at the end of each day, looks at the past few closing prices and predicts tomorrow's price so that I can Buy or Sell and ...

Figure 1

Figure 2

>Every day? You want to trade every day? You're kidding, right?
Ay, there's the rub. What I'd like to do is use something other than daily prices and hopefully get a good UP/DOWN agreement and a good Average Error measure (meaning an error much less than the changes in stock price) and wait until the probability of my prediction is best (whatever that means) and ...

>Wake me when you're finished ...
Just think about it. Daily prices are erratic. They jump up and down and involve violent reaction to breaking news and they're finicky and nervous and ...
Okay. We'll consider NOT the daily prices but, for example, the 5-day moving average. That's the average closing price over the previous week. It's much smoother. That's what we'll use for our P(n) and P(n-1): today's 5-day average and yesterday's 5-day average. P(n+1) will then be tomorrow's predicted 5-day average. We'll play with the value of T and the number of values to use in the P0 moving average and ...

>Huh? The number of values in the P0 average? What does that ...?
Remember, we're not using the actual stock prices any more, for our P(n) and P(n-1). Instead we're using the 5-day moving averages. Since P0 was (originally) a moving average of our stock prices, it's now a moving average of our 5-day moving averages.

>I haven't the faintest idea what you just said! A moving average of moving averages?
Suppose P0 is the 3-day Moving Average of the stock prices. Then P0 = (1/3)[P(n)+P(n-1)+P(n-2)]
Now suppose we replace P(n), P(n-1), P(n-2) etc. by the 5-day Moving Averages of the stock prices.

>P(n) is today's 5-day moving average and P(n-1) is yesterday's 5-day moving ...
Exactly. Then P0 = (1/3)[P(n)+P(n-1)+P(n-2)] makes P0 ...

>It makes P0 a moving average of moving averages. Okay. I get it. Uh ... how about a picture?
Okay. Look at Figure 4.
  • The cyan points are the actual 5-day Moving Average of stock prices. They're our P(n), P(n-1) etc. (See how smooth, compared to the raw, daily prices in Figure 1?)
  • The magenta line is the 5-day average of these P(n), P(n-1) etc.. That's our P0.
  • Our predicted values, using T=6, are in red ... and the UP/DOWN agreement is 77%, meaning that 77% of the time our predicted price went up (or down) when the actual P(n) went up (or down). The "good predictions" (which correctly predicted the direction UP or DN) have a black centre.

Figure 4
>What's that Extrapolation thing? The little white circle?
So far we've been predicting tomorrow's value ... that's our P(n+1) ... then, tomorrow, at the end of the day, we do it again using tomorrow's actual closing value in order to predict the value for the next day. In other words, we're always using the actual values for P(n) and P(n-1), not our predicted values, P(n) and P(n-1). In other words, we keep correcting our prediction, replacing it with the actual value in order to do the next prediction. In other words ...
>Please! A picture is worth a thousand other words!
Okay, look at Figure 5. It shows
  1. the actual stock prices (GE in May/June, 2000)
  2. the 4-day moving average of those prices
    (that's our P(n), remember?).
  3. the 9-day moving average of the P(n)
    (which we're using for our P0).
  4. The predictions P(n+1).
  5. Those "good" predictions which correctly predicted the UP/DOWN movement of the P(n).
  6. And, during the last week (that's 5 market days), we didn't use the actual P(n) values but our predicted P(n) values. That's our "Extrapolation", over the last 5 days. Them's the little white circles.

Figure 5
>And you got an 80% UP/DOWN agreement in the predictions? Wow!
Hold on. The UP/DN agreement refers to the whole time range on the chart. That just means we correctly predicted whether the P(n), the 4-day average of stock prices, would go UP or DOWN. Three of the four stock prices in that 4-day average are actual prices, not our predictions, so we'd expect to get a good UP/DOWN agreement. If we used all four of the actual prices we'd have a 100% UP/DOWN agreement, right?

That brings us to that "Extrapolation", for the last five days. Here we stopped looking at the actual stock prices
(and the P(n), their moving averages) and just used our predicted values.

>But, if the black dots in the center of the white circles mean what I think they mean ...
Yes. They correctly predicted the UP/DOWN movement ... 4 out of those last 5 days.

>I assume you used those numbers, 4-day average, 9-day average, T = 5 ... just to get a good result?
Uh ... well ... I used a spreadsheet which ran through a bunch of values and picked the best.
It was entertaining to watch the chart change.
Here is a sample, with just a few different values for the two averages and T-value.
Look closely and you'll notice that some are very bad and some are pretty good. In particular, watch the last week's worth of predictions where we use JUST the predicted values to calculate the two averages.

>So, what are your conclusions?
That, if you're lucky, you can pick parameters which will tell you whether the stock price will go UP or DOWN and your predictions will be good ... perhaps 80% of the time.

>This is some kind of market timing strategy?
Yes ... and everybuddy knows how well Timing works

>Well, I'd still like to play with the spreadsheet.
Sure. It looks like
To download a .ZIPd version, RIGHT-click here and Save Target.

At the request of Rick C. the spreadsheet (as of October 1/03) gives a prediction of tomorrow's price.
You just stick in the stock symbol and click a button or two.
The accuracy is guaranteed ... or your money back

A final note:

Let's rewrite Equation (1) like so:

(2a)        P(n+1) = (2 - x) P(n) - P(n-1) +xP0
(2b)        P0 = P(n)+P(n-1)+P(n-2)+P(n-3)   is the 4-day average of the Ps.

Substituting (2b) into Equation (2a) gives our predicted price as:
(2c)        P(n+1) = (2 - x)P(n) - P(n-1) +x{P(n)+P(n-1)+P(n-2)+P(n-3) }
= 2P(n) + (x-1)P(n-1) + x P(n-2) + xP(n-3)

Of course, if we're doing m-day averages, we'd get:
(2d)       P(n+1) = 2P(n) + (x-1)P(n-1) + x P(n-2) + x P(n-3) + x P(n-4) + ... + xP(n-m+1)

In general then, our predicted price, P, will be a moving average of the Ps.

If the Ps are themselves moving averages of the actual prices, then our predicted price will be a moving average of the actual prices ... but a very curious moving average. Indeed, if all the actual stock prices were equal to, say, K, then one would expect that the predicted price would be K. However, Equation (2c) gives a predicted price of (1 + 3x) K if we're using a 4-day average and, more generally, we'd get [1 + (m-1)x] K if we're using an m-day average.

To make the predicted price more palatable (to some :^), we could write it as:

(3)        P(n+1) = {(2 - x) P(n) - P(n-1) +xP0} / {1 + (m-1)x}
       P0 = P(n)+P(n-1)+P(n-2)+...+P(n-m+1)   is the m-day average of the Ps.

That'd make P(n+1) = K when all the P = K.


Good idea.

for Part III