Quantitative Finance offers plethora of indicators and tools to predict future price movements of Stocks, commodities or any other traded instruments. Linear Regression is one of them through which price direction is speculated using statistical techniques. It has found it’s application in multiple proven trading systems used by hedge funds and large institutional investors. In this post, we will explore Linear regression trading system which is based on the principle of Mean reversion. We shall also understand the definition of linear regression and linear regression channel in simple terms.
Please visit Trading Tuitions Academy to learn AFL coding and create your own Trading systems.
Linear Regression line and Linear Regression channel
Linear Regression line is the straight line drawn through the price points in a chart, which most effectively covers all the prices for a given period. It is a kind of ‘best fit’ line which shows the fair value of trading instrument. Any deviation from the linear regression line is considered to be the deviation of price from it’s supposed to be fair value. It is like a trend line and gives an idea of ongoing price trend in the chart.
Linear Regression channel contains two extra lines above and below the standard linear regression line. These extra lines are formed by calculating 1 or 2 standard deviations of linear regression line. If 1 standard deviation is used then linear regression channel covers 68% of prices for a given period, while if 2 standard deviations are used then it covers 95% of prices. Hence linear regression channel can effectively determine overbought and oversold areas, which makes it a perfect tool to develop mean reversion strategies.
Below is the simple illustration for Linear regression channel.
Linear Regression Trading System – AFL Overview
|Indicators Used||Linear Regression, Standard Deviation|
|Position Size||100% of Equity|
|Brokerage||100 per order|
Linear Regression Trading System– AFL Code
This AFL code was originally published at Marketcalls.in. We have modified it to make it suitable for intraday trading and added various backtesting conditions.
Click here to download AFL code for this system.
Also Read: Donchian Channel Trend following system
Linear Regression Trading System- Backtest Report
Linear Regression Trading system does not offer huge returns as it it based on mean reversion, but it is quite consistent owing to low drawdown value. It is suitable for intraday scalping.
|Scrip Name||NSE Nifty|
|Backtest Period||26-Feb-2008 to 30-Jun-2017|
|Net Profit %||268.45%|
|Annual Return %||14.71%|
|Number of Trades||136|
|Winning Trade %||55.88%|
|Average holding Period||3.05 periods|
|Max consecutive losses||4|
|Max system % drawdown||-13.37%|
|Max Trade % drawdown||-13.86%|
Download the detailed backtest report here.
The equity curve is smooth and stable.
Additional Amibroker settings for backtesting
Goto Symbol–>Information, and specify the lot size and margin requirement. The below screenshot shows lot size of 75 and margin requirement of 10% for NSE Nifty:
All the AFL’s posted in this section are for learning purpose. Trading Tuitions does not necessarily own these AFL’s and we don’t have any intellectual property rights on them. We might copy useful AFL’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at email@example.com