Hodrick Prescott Filter (HP Filter) does Time series decomposition which involves separating a time series into several distinct components(Cycle component and Trend Component). And this filter looks like it can be applied to any time-series data especially with stock prices to understand the underlying trend and the cycle involved in it.
Here is a simple ipython notebook example for Hodrick Prescott Filter Analysis. We use statsmodel library to compute the Hodrick Prescott Filter Components, Matplotlib to plot the data, NSEpy to retrieve the stock data from NSEIndia and Pandas to handle the time series data.[iframe src=”https://www.marketcalls.in/wp-content/uploads/2015/11/hp.html”]
The above chart shows the Stock TCS price and HP Filter components trend and cycles component. You might have noticed that the trend component is ultra-smooth and very good in forecasting the future of medium TCS price direction. And the Cycle Component extreme values suggest a possible trend reversal. To my view, it should be a better tool for traders and investors to know the underlying trend. Especially HP filter suits both trend followers and mean reversion traders!