Saturday, October 20, 2012

Linear Filter and the Stock Market


A few blog posts ago I talked about a linear filter to separate a complex signal into individual components.  Really all this is doing is estimating weights (prices) by multiplying the individual components (number of items) by their weights and evaluating if this predicts the actual total signal (total price).  These weights are adjusted up or down to improve the accuracy.  The actual procedure is given by this equation:

where w' is the updated weight in the next learning cycle and r, the learning rate, is a small number to prevent over corrections.

In addition to estimating the individual weights/prices what is happening is the filter is getting better and better at estimating the total signal/cost.  Here is a plot over the 200 days of learning. 


The guess price (total cents) quickly zeros in close to the actual price with the absolute error dropping and then fine tuning the remaining small errors. 

I was curious how this might work with an actual example.  So I downloaded historical closing prices, over the last year, of the 30 companies in the Dow Jones Industrial Average.  Below is a plot of the prices (dollars per share) on a log scale over the last year. 



I set up the filter to use the closing prices the previous day of all 30 companies to predict the closing price the next day of 3M, as an example company.  In the plot below you can see that it quickly zeroed in to track/predict 3M share prices.


And, below is a plot of the learned weights for each company.


There are a few things I would like to point out about this.  First of all, once the prediction zeros in, the weights don't change much at all for the rest of the learning period.  The highest positive weight in predicting 3M the next day is not 3M; it is BAC, Bank of America.  IBM actually has a small negative weight, suggesting that the previous closing price of IBM should be subtracted, in a small amount, to generate the predicted price of 3M the next day.

All in all this generates a nice correlation, after the first 20 days of initial learning, between predicted (y-axis) and actual (x-axis) closing prices of 3M on the following day.


However, as usual there is more to this story, which I will follow up on in a later blog post. 

No comments: