Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Hodrick Prescott Filter Analysis – Python

48 sec read

Wikipedia says

The Hodrick–Prescott filter (also known as Hodrick–Prescott decomposition) is a mathematical tool used in macroeconomics, especially in real business cycle theory, to remove the cyclical component of a time series from raw data.

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!

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Mastering VectorBT Backtesting and Optimization – Part 1 –…

VectorBT is an advanced backtesting library designed for Python programmers and quantitative analysts. It is particularly beneficial for those who require a fast, flexible,...
Rajandran R
5 min read

How to Fetch Realtime Stock Market Quotes using SmartAPI…

SmartAPI, provided by Angel Broking, offers a robust solution for traders and developers looking to integrate real-time stock market data into their applications. Utilizing...
Rajandran R
6 min read

Mastering Python F-String Formatting: A Trader’s Guide

F-String, introduced in Python 3.6, stands for "Formatted String Literals." It's a way to format strings in Python, allowing for easier and more readable...
Rajandran R
5 min read

4 Replies to “Hodrick Prescott Filter Analysis – Python”

  1. I know for a fact that Prescott filter is re-calculating the past bars and so is not reliable due to repainting. So how can it be used for trading?

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More