Discussing AI, complexity, machine learning, and the future of the field with real-world examples. It explores the benefits and challenges of machine learning in a friendly and engaging way.

by

Intro to Algorithmic Trading

Disclaimer: This is in no way financial advice, what follows is a description of my explorations of the subject, things I wish I would have found together and a reference for my future self or anyone who deems it useful. Use it at your own risk.

Intelligent algorithmic trading is a field that relies on massive datasets. The aim is usually to try and figure out patterns that are recurring or situational and find ways of using these patterns creatively to make profitable trades.

How Markets Work

Markets are structures that allow the buying and selling of goods under some common written or intuitively understood set of rules. Trading markets such as money markets, stock exchanges and bond markets allow for these forms of investment to be traded. Markets tend to crop up when a class of object with real or perceived value needs to be transferred between different owners who would not otherwise have met.

Consider as an example a house, its primary function is to provide shelter and comfort to its residents. This function is more or less decoupled from its ticket price, in fact, many similar houses will sell at different prices. The fact that a house can be bought by someone other than its original owner means, that to an extent, the house served as a method to store value. As different people enter and operate in this market, the price for the same house will change. This change may be due to the entire market, inflation or something related more closely to the singular property such as discovering oil on the land, or it being struck by lightning.

The stock market and other digitally tradable assets operate on a similar premise of supply and demand. According to F.A. Hayek, markets are the most efficient means of gathering the fragments of information scattered among members of a society. He used this insight to popularize the idea of efficient markets. In his view, given that markets are made up of self interested individuals who would operate optimally such as to profit from their knowledge of a subject, there would be, in the market price, a perfect representation of all of the information about the subject’s present and possible futures.

Market Microstructures

Often you will hear the term market microstructure thrown around when discussing this subject, most times without any clear explanation of what it is referring to. This is quite reasonable since market microstructure is a catchall term that covers quite a lot of breath. In broad strokes, these are some of the things to consider when thinking about market microstructures.

  • Trading Platforms
  • Order Types
  • Market Data
  • Liquidity
  • Price Formation Process
  • Market Participants

Data

Although this problem has been approached in many creative ways, the general tendency is to deal directly with market based time series data, meaning data that can be represented as a plot with the x axis being time and the y being the feature you are interested in. The resolution or time-step size is a feature in itself and is greatly dependent on what you are trying to achieve. High frequency models need to have very granular time-steps measured in the minutes or less, while the same level of granularity may be detrimental if the model is trying to predict yearly fluctuations, by hiding the signal in the noise.

In general, time series models try to extrapolate a potential future for a series of data points, given the current state and some knowledge of how this series has behaved in the past. Models in this realm train mostly using historic market data. In the wild, new data is added as it is made available, used to instruct and re-train models to keep them competitive.

Data Acquisition

Data for trading comes mainly from three sources.

  • Market Data Vendors – data brokers who are in the business of selling high quality data.
  • Direct Feeds – feeds provided by brokers or other financial institutions
  • Web Scraping – gathering data from anywhere in the internet, this must be done with caution as some sources prohibit the practice and doing so may result in legal ramifications.

The Human Benchmark

Speculative trading is not something new, it is as old as markets, we would do well to learn from the wealth of knowledge gathered over generations before trying and compressing this into a trading bot.

How do humans do it? As anyone can expect, there are a multitude of techniques, some as simple and naïve as random chance (a strategy preferred by gamblers) to others heavily influenced and aided by advanced techniques and processes. The latter, leverage technology and experience in their application, and start to blur the lines between autonomous trading and the more traditional human trader.

Reading Candlesticks

Candlestick indicators are very simple to read once you understand them. They are used mostly in trading charts as a method for summarizing aggregate data visually. Put simply, candlesticks show the Open, Close, High and Low Price of the time period represented by the granularity in the chart. A red candlestick is one when the Open is higher than the Close, while a green candlestick is one where the close is higher than the open. The wicks, little lines above and below the open and close, mark how far to the extremes the value of the asset rose and fell during the time period.

Candlestick indicator patterns
https://en.wikipedia.org/wiki/Candlestick_pattern

 

Traders look at the shapes of candlesticks or groups of them together and much like reading tea leaves or the weather, they learn to attribute different meanings to each of the different shapes. For those interested in the looking into this further, many patterns can be found here.

Technical indicators

Technical indicators are tools invented primarily as rules of thumb. Many traders will have developed an understanding of many of these and will be able to check and use the tools they need on the trade they are currently interested in testing. Technical indicators offer no guarantees, however when used in aggregate, with other tools and with the right discipline can create quite a powerful aid.

There exist thousands of different technical indicators, learning about all of them is way outside of the scope but it’s useful to keep in mind that sets exist. There are, for example a few technical indicators that indicate trend, others that indicate momentum, volatility and volume.

Here are a few examples of each:

  • Trend Indicators.
    • Moving Average (MA) – The average price over a specific period
    • Average Directional Index (ADX) – A lagging indicator that counts movement directions and uses their average.
  • Momentum Indicators.
    • Relative Strength Indicator (RSI) – A momentum oscillator, that varies between 0 and 100 and measures the speed and change of price movements
    • Moving Average Convergence Divergence (MACD) – Measures the difference between two moving averages to identify trends.
  • Volatility Indicators.
    • Bollinger Bands – Bands marking the standard deviation of a market. They can be used as a visual reference of where the current price is trading.
    • Average True Range – Measures a security’s volatility compared with the opening and closing prices of the day
  • Volume Indicators.
    • On-Balance Volume (OBV) – Measures buying and selling pressures based on the volume flow
    • The Accumulation/Distribution Line (A/D Line) – Uses volume and price data to assess buying and selling pressure. The indicator is based on the premise that the more volume that accompanies a price move, the more significant the price move is.
MACD as an Example Technical Indicator
https://en.wikipedia.org/wiki/MACD

 

Continued