Have you ever been intrigued with how hedge funds build trading strategies using complex technical indicators? How HFT hedge fund managers make volumes of trades by using simple mathematical stock indicators? This article is a great introduction to the world of algorithmic trading, and how to come up with your own simple trading strategy based on historical data.

This is the third post in the application of machine learning in trading series. If you haven’t already, I would recommend checking out the first two posts: Martingale Gambling Strategy and Understanding Tree-Based Learners.

Image for post

In this article, we will explore multiple technical indicators for time-series stock price data and a theoretically optimal strategy that has been tuned to beat the benchmark strategy. The indicators developed in this project will be used to design an intuition-based and machine learning-based trading strategies in the forthcoming projects. Indicators use price and volume information to provide additional information through mathematical calculations about the current buying or selling potential of a particular stock. There are four major types of indicators: trend, momentum, volume, and volatility.

The technical indicators discussed in this paper are as follows:

  1. Bollinger Bands® (BB Value): Bollinger bands® are a volatility indicator that uses a simple moving average (middle band) and two bands (upper band and lower band) based on two standard deviations from the moving average. Bollinger bands® help assess buying and selling positions based on the position of the stock price as compared to the bands.
  2. **Relative Strength Index (RSI): **Relative Strength Index is a momentum oscillator that identifies if the market is overbought or oversold based on the magnitude of recent price changes. The RSI can have a reading from 0 to 100 where above 70% indicates an overbought market while below 30% indicates an oversold market.
  3. **Momentum: **As the name suggests, momentum is another momentum-based oscillator. Momentum is the relative price movement of a stock over a rolling time window. It is calculated by comparing the current stock price (as the numerator) with a historical stock price (as the denominator). Positive momentum values indicate a bullish market, and negative momentum values indicate a bearish market.
  4. **Volatility (Z-score): **Z-score is a volatility indicator that helps gauge dispersion of returns for a given stock or market index. In most cases, the higher the absolute volatility, the riskier the stock. Z-score is calculated using the rolling mean and rolling standard deviation of a stock over a time window to calculate the number of standard deviations the current stock price lies from the mean.
  5. **Moving Average Convergence Divergence: **The Moving Average Convergence Divergence (or MACD) is a trend indicator that is calculated using exponential moving averages to formulate a fast line, a slow line and a histogram for the divergence between the fast and slow line. The difference and directions of the fast and slow lines signifies the buying and selling opportunities for stocks based on a historical rolling time window.

Experimentation Details

The experimentation details, dates and rules have been mentioned below to ensure consistency:

Data:_ Historical stock prices data_

Symbol:_ JPM_

Time Period:_ January 1, 2008 to December 31, 2009_

Starting Cash:_ $100,000_

Allowable Positions:_ 1000 shares long, 1000 shares short, 0 shares._

Benchmark:_ The performance of a portfolio starting with $100,000 cash, investing in 1000 shares of JPM and holding that position._

Transaction Costs:_ Commission: $0.00, Impact: 0.00._

Technical Indicators

Technical indicators are defined as heuristic or mathematical calculations based on the price and volume (in some cases open interest). As stated in the introduction, there are four types of technical indicators: trend, momentum, volume and volatility. A handful of technical indicators such as Bollinger bands®, relative strength index (RSI), momentum, volatility (z-score) and MACD have been explored in this project that include trend, volatility and momentum-based indicators. In this section, we will be diving in deeper and discussing each technical indicator.

Bollinger Bands® (BB Value)

Description:

Bollinger Bands® is a technical indicator that is defined1 by a set of lines plotted two standard deviations above and below from a simple moving average (SMA) of the stock price. Bollinger Bands® were developed by John Bollinger. They comprise of three lines: a simple moving average (middle band), an upper band, and a lower band. The upper band and lower bands are typically 2 standard deviations above and below respectively from a 14-day simple moving average.

Upper Band = (Rolling Mean) + (2 * Standard Deviation)

Lower Band = (Rolling Mean) + (2 * Standard Deviation)

BB Value = (Prices — Rolling Mean) / (2 * Standard Deviation)

**Signal: **Standard deviation is a measure of volatility, and hence when the markets become more volatile the bands widen, and vice versa.

Buying position: When the stock price tends to falls below the lower band, it indicates a good buying position. In this case, BB Value is less than 0.

Selling position: When the stock price tends to rise above the upper band, it indicates a good selling position. In this case, BB Value is greater than 1.

#algorithmic-trading #data-science #hedge-funds #money-mindset #towards-data-science #algorithms

Algorithmic Trading 101
1.70 GEEK