Saturday, April 17, 2010

Painting the Trend with a Twist

Most of you are familiar with painting the tape using the direction of the linear regression line-of-best-fit as an indication of trend.  That's a good start, this analysis ups the ante a notch by measuring how unusual the standard error of the regression estimate is relative to that line.

Okay, don't get freaked out by the Stats-101 reference!  It's simply a measure of how accurately the predicted trend line is fitting the actual price series!  In this case, we are referencing that accuracy level relative to historical norms to decide whether we are in fact in more of a mean-reverting versus a trending environment.  Think of it as a "third state".

The color key below employs a smoothed monthly look back period with up-trends in green, down-trends in red, and mean-reversion oriented periods in purple.  I expect that this concept could be advanced significantly with further study, but here is a first pass graphical look at the idea going back ten years using the S&P 500 (SPY) as inspiration:


Anonymous said...

This sounds very interesting. May I ask which calculation you used to identify this "third state"?


Anonymous said...

Very interesting notion.
Question: you assume three stages ( quite logical). But what relative levels of the standard error correspond to each one ?
Example: is the upper third of the standard error values indicative of mean reversion ?

jgpietsch said...

Hi Gang, the posted graphic uses one month standard error readings at extreme 99th percentile levels. Best, Jeff

Anonymous said...

Jeff, standard error from what, a 200day moving average?


jgpietsch said...

Hi Alec, here we are looking at the standard error of the regression estimate, not of the mean:

Best, J

Anonymous said...

Jeff, I haven't heard about the SE of the estimate before, but from what I just read it's the deviation from the estimated values. Now which are these estimated values, how did you calculate these, if they aren't a mean?

The calculation itself seems to be very similar to the standard deviation, see here:

Standard Deviation: σ = √[ ∑(x-x')^2 / N ]
St. Error of the Est.: Se = √[ ∑(x-x')^2 / N-2 ]

I'd appreciate any help you can give me to recreate the Se as I'd like to write some ruby code and run it over a database of 80 ETFs I'm watching.


jgpietsch said...

Hi Alec, the estimated values are those generated by a standard time-series based linear regression using the ordinary least squares line of best fit method. This is a bit different than what you described, which would have been more akin to a z-score, if I understood your implication. Best, Jeff

Anonymous said...

Jeff, I hope I no understood what you're doing:

For each day:

1) calculate the linear regression based on the past X days.

2) identify the standard error of the estimate for todays close based on the linear regression mentioned above.

3) compare this result with the previous Y days, if it's in the 99th percentile, mark it purple.

In case I got it right, the only thing I'd love to know is the number of days you're using for X and Y... unless you don't want to publish them. :)


jgpietsch said...

Hi Alec, it looks like you are close enough to be able to properly experiment. Best, Jeff