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 (Part 2)

If when seeing this page you feel the need for a quick introduction, I suggest you go to https://actingintelligent.com/intro-to-algorithmic-trading/.

Modelling

Here are some basic and not so basic models that are used with time series data;

ACF (Autocorrelation Function)
PACF (Partial Autocorrelation Function)
MA (Moving Average)
AR (Auto Regression)
ARIMA (Auto Regressive Integrated Moving Average)
GARCH (Generalized Auto Regressive Heteroskedasticity)
RNN (Recurrent Neural Network)
Transformers

I am only providing a list overview as there is no space on this page to go in all the detail required to cover these topics. This list should be enough to put anyone interested in learning more on the right path.

Back-testing

In time series especially, every model built is trying to predict a generally unknowable future. In other words, any predictions done are by their very nature out of sample predictions, testing hypothesis, strategies or models is usually done using a technique know in algorithmic trading as back-testing. This technique is used in multiple other fields that use time series data and is referred to in many different ways including hindcasting and post-diction dependent mainly on the field it is being used in. What it is effectively, is cross validation using multiple sample timeframes from the feature’s history.

In back testing, a model is run for a set period of time, for example 1 month. Instead of choosing that time at random from the dataset, the model is run on every 1 month bracket starting from the beginning of the dataset, and incrementing the start date by one day for the rest of the time until one month before the end date. This way the model will have been effectively tested on a large number of different situations and a distribution of performance can be plotted to understand the risk and return a little bit better.

In the world of predictive modeling, back testing can serve as a valuable tool to assess a model’s performance. However, one must be cautious not to over-rely on historical data, knowledge of past events provides only an indication, not a guarantee of future outcomes. In fact, the least probable scenarios often materialize with time. Thus, while back testing can offer valuable insights, it should be complemented by other analytical and risk management approaches to avoid costly misjudgments. To anyone interested in deeply grappling with the thoughts behind uncertainty, I highly suggest picking up Incerto by Nassim Nicholas Taleb. His writings are a delightful blend of clarity and complexity that require focused attention and a light heart.

Risk Management

For anyone wanting to take this seriously, risk management is the one highest priority. This could be the difference between survival and complete ruin. Although some describe them as the same risk and volatility are not identical. Volatility describes the fluctuations in the price action, the larger the oscillations or movements the more volatile. Risk on the other hand is a representation of how likely the portfolio or trade is to loose money.

Thinking about risk

Risk and Time

The risk associated with a trade depends on the time horizon attributed to that trade. To understand this, let us look at the extremes; If you make a trade that buys and sells a stock over a microsecond. The price fluctuation will be relatively small. the risk associated with that trade is very minimal. On the other hand if you make a trade betting that the price will go up in 1000 years, the risk of that trade, considering not many companies make it to that age is very high. One can easily imagine that the range in between can be governed with similar dynamics, making trades that happen in a more distant future more risky.

Asymmetric Risk

Asymmetric risks are risks in which the potential upside is smaller than its potential downside. In other words, the risk-reward ratio is not balanced. Asymmetric risks pose interesting challenges and opportunities but need to be managed very carefully. Asymmetric risk can come from the market itself or also the current position or combination of positions.

Tenets of Managing Risk

1. Diversification

Diversification across asset classes, markets and currencies helps diversify away risk. However this is only true if diversification is done well. For diversification to happen the chosen assets must be not only different but mutually independent. This was very well witnessed in the 2020s where, if you invest in vehicle manufacturing and online retail you may think you are well diversified, but since they were indirectly depend on a common supply chain and that got disrupted, many were in for a rude awakening.

We will not go into too much detail but at the very least, a simple check that can help is to test the entire portfolio for correlation. The highest positively correlated pairs of assets will have the highest tendency to move together, those negatively correlated will move in opposite directions. This is by no means a fool proof method, but a start. On another similar note, if you happen to be dealing with longer timelines correlation may be less effective at identifying coupled movers and analyzing cointegration may produce better results.

2. Position Sizing

Position sizing is a moving bar that can be set depending on one’s tolerance for risk. Imagine a coin flip, where you have prior knowledge that the probability of heads is 60% while the probability of tails is 40%. let us consider also that you have 100 marbles, and you have to place a bet in which if you win, you can get double what you wager but if you loose you loose all of what you wager. If you have a very high risk tolerance but want to maximize potential outcome, you would place all your marbles on one coin flip, this would give you a 60% chance of doubling your marbles, and a 40% probability of loosing everything. Compare this to taking 100 bets of 1 marble each, that will give you a miniscule chance of doubling the marbles, but also a very unlikely probability you will loose all your marbles, instead you can reasonably expect to end up with a 20 more marbles than you initially started off with. So at the end of the day, one can choose to go for a lower return with lower risk or a risky strategy but with a much larger potential return.

3. Stop-Loss Orders

Stop Loss orders are automatic instructions to sell a security if its price falls below a defined level. When the stop price is reached the stop loss order becomes a market order selling at the then current market price. These are useful in order to protect investments as they allow the limitation of risk. Its important to understand that stop loss orders do not guarantee sale at that price, and may sell at an even lower price in a fast moving market. Another thing to understand is that stop loss functions can suffer from sudden drops in price that trigger the sale but then quickly rebound. This effect is called “being wicked out” since it is usually the presence of a long bottom wick that causes the sell order to trigger and the ensuing loss of potential gains as the market bounces back the next second.

4. Monitoring

In much the same way that algorithmic trading allows traders to automate their processes due to the large number of moving parts involved, performance metrics allow traders to keep an eye out on the more important numbers. Many performance indicators exist, but some of the more common ones are:

  • Returns – Such as the distribution of returns per trade
  • Drawdowns – The largest percentage drop from peak to trough in value experienced during a trade
  • Sharpe ratio – A measure of the risk-adjusted return of a strategy

 

In the ever-changing dance of risk management, diversify wisely and bet your marbles with measured wit. Let monitoring and stop-loss orders be your compass through the twists and turns of the market.