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 and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

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 and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Twitter Based Sentiment Analysis using Natural Language Processing (NLP)…

In this tutorial, we will be fetching REDBOXINDIA Twitter timeline and we will be doing NLP-based text sentiment analysis based on that. And give...
Rajandran R
4 min read

How to Retrieve Opening Balance, Total Turnover, Realized and…

This tutorial explores how to access the limits API functionality in Algomojo using python to retrieve the Account Balance, Total Turnover, Realized, UnRealized PNL,...
Rajandran R
1 min read

Introduction to Backtrader – Creating your First Trading Strategy…

Backtrader is an open-source python framework for backtesting, optimizing, and deploying live algorithmic trading strategies.
Rajandran R
54 sec 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