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 timeseries 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.
Above chart shows the Stock TCS price and HP Filter components trend and cycle component. You might have noticed that trend component is ultra smooth and very good in forecasting the future of medium TCS price direction. And the Cycle Component extreme values suggests 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!