Upbotscom
Published in

Upbotscom

An Introduction to Back Testing Trading Algos

Imagine if there was a way in which you could see into the future by looking into the past! Did you know there is a way you can give a Trading Bot a test to see if it would pass or fail, BEFORE you give it your capital to manage?

If you are considering using a trading bot then you will also want to backtest. And no Brian, I don’t mean your spine. I’m speaking about a way to figure out how good, bad or ugly your bot is going to be before you authorize it to trade your hard earned capital on your behalf.

This applies to all trading bots…well not the ugly part if we’re talking about UpBots bots, because those are shiny and new…

Continuing our series of educational articles about botting and algo trading, we are publishing this blog post about back testing — a vital development step for every algorithm or trading strategy.

Backtesting can be difficult to conduct and has a multitude of pitfalls that will make an inexperienced trader feel that they are running through a military obstacle course.

This article is aimed at the beginner audience and intends to explain what back testing is and how to perform it.

What is backtesting?

Back testing is a technique that allows traders to see how well their strategy would perform in the market before executing it. Getting rekt, otherwise known as losing money, stinks like a kamikaze skunk crapped itself to death while squirting skunk stank all over a big pile of socks in the corner of a teenage boys room.

Backtesting is a technique that allows a trader to see how their strategy would perform on the market. For this the trader runs the algorithm on the historical data of the market and then evaluates whether the strategy made profit, what was the maximum drawdown, etc.

Backtesting is a vital step in optimizing the strategy, since it allows the trader to see whether the strategy is losing him money or not.

Good backtesting should be careful to take note of any important assumptions. One of the main assumptions is that the market conditions and market fundamentals are still the same. This is very logical — if something fundamentally changed in the market, then the strategy won’t be applicable for the current conditions.

Correct backtesting should be ideally made on a dataset that is not directionally biased. For example, if you test your strategy only in the bull market, chances are that it would not be applicable to ranging or falling markets.

How do I backtest my strategies?

To properly backtest your strategies you’re going to need a set of rules. Yes, we know in life rules suck, but in this case you’ll be the one making them (which is more fun trust me).

Here is an example of how to set rules in algo trading back testing:

Let’s say Brian has a strategy that buys an asset when the 12-day daily moving average crosses the 90-day daily moving average from below, and sells the asset when it crosses from above.

The key idea here is that in this strategy the 12-day moving average more closely attracts the momentum of the asset. Therefore it crosses the 90-day moving average and shows the current short term trend.

To test this strategy, Brian will conduct the following steps:
1) Download the historical prices of the asset
2) Calculate the moving averages (Add asset prices over a period of time then divide them by the total number of periods)
3) Receive the amount of moving average crosses, which are the long/short entry or exit points
4) Get the sum of these trades which reveals if the strategy is profitable or not

And there you go Brian, it seems your strategy is profitable. However, it should be noted that focusing only on returns isn’t the best idea.

First of all, positive returns might show that the strategy is only winning on this subset of the data, and it might not work in the future. Besides that, it is also important to know how the strategy performs during the losing period, or in other words, how big is the drawdown.

Volatile strategies can blow up your account and therefore be unable to capture any further upside. A very useful statistic is a Sharpe ratio — returns divided by volatility. A strategy that returns less but has less risks is usually better than a strategy that returns slightly more but has significantly more risk.

What are the pitfalls in backtesting?

So you just completed backtesting a strategy and everything looks good, then it fails IRL and you are now wondering what the hell happened?

Backtesting isn’t a full proof method by any means. Many times traders discovered their strategies were not as profitable as they thought they were because they fell deep into a backtesting pitfall.

Sometimes a strategy looks great on paper but isn’t profitable once it enters the real world.

For example, a trader could design a strategy that does 100 trades a day for minimal gains that eventually add up to a sizable profit. However, if this strategy ignores trading costs, it means that the small trades might be break-even at best and losing at worst, draining the trader’s account.

Slippage can also lead to the losses, as during the backtest the algorithm would assume that it always gets the best entry price, whereas in reality the trades were done with a small deviation in cost, which diminished the profitability.

Another pitfall that a trader could fall into would be the “omniscience” of the model being backtested, or, in other words, “look-ahead” bias. This means that a model uses the data that should not be available to it, which leads to (usually) positively biased results, with the model performing better during the backtest than in reality.

Can I backtest on UpBots?

Yes you most certainly can and actually in two different ways. Firstly in our Algo Lab where you can design and build your own custom algorithm and then plug it into a bot, there will be full back testing capabilities.

Algo lab is a feature that is due in the first part of 2021.

However what about the rental Algo Bots? Well this is the other way you can sort of back test. I say sort of back test because those bots have already been online and have an actual trade history (rather than a simulated one based on historical data).

In the case of the Algo Bot Rental section of UpBots, you can see each bot’s historical performance data.

🎉🎉 So congrats you just completed our intro to backtesting.🎉🎉

This article is only just an introduction to back testing, a mere scratch on the surface, but hopefully it has provided you with an introduction to the main concepts and dangers.

We will be posting articles that go more in-depth for the readers that are interested in getting to know actual methods and techniques used in algo trading.

How important is it to you that you have a solid picture of how your algo or your trading bot has performed in the past?

Let us know this or any other thoughts or questions you have about backtesting in the comments below, OR swing by our Telegram group or our Discord for a virtual Christmas, or even just a Tuesday beer.

We’re not fussy about when we celebrate with beer. In fact with a Belgian CEO there’s a fair chance beer is the mandatory beverage of celebration*, so come say hi.

And in the mean time Happy Christmas to you and your family. From all here at UpBots HQ, we hope you have a happy, healthy and safe Christmas holiday.

* this may not be true.

Until next time, here’s a festive community meme:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Neil Sisson

Neil Sisson

Former CMO of UpBots.com. Crypto Advocate. Coffee Addict. Carpe’ing my diem on the daily.