Hodrick Prescott
Overview
The
hodrick prescott filter is a filter for extracting a signal from
noise. It does a fairly good job at something the signal and presenting what looks a like a trend.
Trade Signals
The hodrick filter can be used to try to determine the direction of the current trend in order to extrapolate a future price
path.
Computational Issues
The filter works through a process of linear algebra by creating a series of matrices and executing
Time Frames
One issues that can be difficult to deal with when using the Hodrick filter, is that it can be hard to specify a time frame.
When using
moving averages, one can easily specify a long or short time frame by setting the number of days to use
in the moving average. The Hodrick Prescott filter does have an input parameter that dictates the amount of smoothing to apply,
however, it is not effective at capturing longer term trends.
One strategy to deal with this issue is to artificially create a longer term framework by averaging the points in the
data series. For instance, we could collapse every 10 points into a single point by taking the average of those original points.
Then, we can apply the hodrick filter to this averaged series. Even though the filter is still detecting a shorter term
trend, each point represents 4 weeks, so the short term trend actually represents a longer time frame.
let hd = await import('/lib/time-series/filter/hodrick-prescott/v1.0.0/hodrick-prescott.srs.mjs');
let data = [{price:100}, {price:101},{price:102},{price:100},{price:99},{price:100},{price:98},{price:100},{price:102},];
let data2 = $list(data).mapAppend(p=>p.price,{
hodrick:data=>hd.hodrickPrescott(data, 10)
}).items;
Try it!