Algorithmic Trading

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Algorithmic Trading

What is Algorithmic Trading?

Algorithmic trading is defined as the buying and selling of financial instruments using predefined rules
called algorithms. The algorithms are tested on historical data before being used in live trading.

Algorithmic Trading Strategy: A simple example

Trading correlated stocks (pair trading) means trading a pair of stocks that are highly correlated. This
means the two stocks move in the same direction in most of the situations. The trading opportunity
appears when the two stocks move temporarily in opposite directions (the correlation between them
weakens for a period). This means that one stock will go up and the other goes down.

Pair trading strategy: Short the outperforming stock and long the underperforming stock.

Pair trade is usually done with stocks issued by companies from the same sector. Possible pair trading
opportunities are:

• Coca-Cola (KO) and Pepsi (PEP)


• Renault (RNL) and PSA Peugeot Citroen (UG)
mots2791@gmail.com
7OPR3VT6YI
• Exxon Mobil (XOM) and Chevron Corporation (CVX)

The strategy requires market timing and decision taking skills. However, it does not have much
downside risk, and it can be implemented as an algorithmic trading strategy.

Stock price evolution is very difficult to be forecasted but the spread between two correlated stocks is
easier to be predicted. The spread can also be traded separately.

If two stocks are highly correlated that does not mean that they will remain highly correlated in the long
term. Their correlation may weaken in the long term. The correlation coefficient between Coca Cola and
Pepsi stocks increased significantly during the years to 0.8421 for the first 11 months of 2015.

This file is meant for personal use by mots2791@gmail.com only.


Sharing or publishing the contents in part or full is liable for legal action.
Suppose we want to do pair trading in November. The following algorithm is considered:

If the absolute value (difference at t-1 period – average value of difference)> 2* standard deviation of
the difference

We trade as the gap between the two stock prices is widening

Else: we do not trade

Formula to be introduced:

IF(ABS(D211-AVERAGE($D$2:D212))>2*STDEV.P($D$2:D212), "TRADE", "NOT TRADE")

mots2791@gmail.com
7OPR3VT6YI

Important Terms

Stock Return rt at time t is measured as rt = ln(Pt/Pt-1)

Where Pt & Pt-1 are the stock prices at times t and t-1 respectively.

Stock Volatility is measured as Standard Deviation of the returns.

Relative Strength Index (RSI)

The Relative Strength Index is a momentum oscillator that measures the speed and change of price
movements. The RSI oscillates between zero and 100. Traditionally the RSI is considered overbought
when above 70 and oversold when below 30.

RSI = 100 – [100 / (1 + (Average of Upward Price Change / Average of Downward Price Change ) ) ]

This file is meant for personal use by mots2791@gmail.com only.


Sharing or publishing the contents in part or full is liable for legal action.
Moving Average Convergence Divergence (MACD)

Moving Average Convergence Divergence (MACD) is a trend-following momentum indicator that shows
the relationship between two moving averages of a security’s price. The MACD is calculated by
subtracting the 26-period Exponential Moving Average (EMA) from the 12-period EMA. The result of
that calculation is the MACD line. A nine-day EMA of the MACD called the "signal line," is then plotted
on top of the MACD line, which can function as a trigger for buy and sell signals. Traders may buy the
security when the MACD crosses above its signal line and sell - or short - the security when the MACD
mots2791@gmail.com
7OPR3VT6YI crosses below the signal line.

Bollinger Bands

Bollinger Bands are a technical analysis tool; specifically they are a type of trading band or envelope.
Trading bands and envelopes provide relative definitions of high and low that can be used to create
rigorous trading approaches, in pattern recognition, and for much more. Bands are usually thought of as
employing a measure of central tendency as a base such as a moving average, whereas envelopes
encompass the price structure without a clearly defined central focus, perhaps by reference to highs and
lows, or via cyclic analysis.

This file is meant for personal use by mots2791@gmail.com only.


Sharing or publishing the contents in part or full is liable for legal action.
Objective: We have chosen a stock from the banking segment which is listed on the National Stock
Exchange (NSE) of India. In a step by step way we intend to fetch the data, analyze it, interpret it and
mots2791@gmail.com
7OPR3VT6YI evaluate it in R using Technical Analysis indicators such as MACD and Bollinger with the help of Machine
Learning Techniques such as CART and Random Forest.

https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-
guide/RSI

https://www.investopedia.com/terms/m/macd.asp

https://www.bollingerbands.com/bollinger-bands

This file is meant for personal use by mots2791@gmail.com only.


Sharing or publishing the contents in part or full is liable for legal action.

You might also like