Strategy Backtesting

Learn about the importance of backtesting your trading strategy

Introduction

If you plan to stay in the market for a long time, then you have to have a sound trading strategy in place! But how can you find out if your trading strategy is sound or not? Hopefully, you are not planning on testing it in real time, that is, wait for how it fares in the real market and then decide whether you should adopt it or not. You can actually find yourself out of the market in no time in this case! Luckily, there is, at least, one systematic way by which you can test your trading strategy before you hit the ground. However, it is not without its flaws. In this tutorial, we will discuss how to backtest a trading strategy, potential drawbacks and more! We will also introduce you to the fully-automated tools that we offer you on this website and which help you apply what you have learnt, namely the platform and the spreadsheet.

A Brief Overview

  • A trading strategy is a trading plan that summarises your risk/return reward expectations and your trading rules.
  • A trading strategy's main components are initial position, entry and exit signals, filters and money management rules.
  • Always backtest your strategy using historical data.
  • Decide beforehand on which input goes into backtesting, what is being optimised and which output is expected.
  • This tutorial provides you with theory notes as well as spreadsheet and platform notes that you can use to experiment with the platform and spreadsheet.

What to Watch out for

  • Be wary of creating an overly complicated trading strategy that is dependent on one market scenario.
  • Make you sure you do not build a trading strategy with too many rules that would become hard to track and backtest.
  • Make sure you do not overfit your strategy to the dataset.
  • Keep your strategy backtesting system simple; it will be easier for you to run, analyse its performance and tweak it.
  • Bear in mind that the tools we offer implement a very simple backtesting strategy system that is meant to illustrate this concept and should never be used to make trading decisions.

Lessons

In the following sections, we will be looking into strategy backtesting in depth. The lessons on this page are just a taster of what is covered in the below course notes. The tutorial will be divided into two main parts: a theory part and an application part. 

The theory part is covered in four lessons and it explores the theoretical foundation and implementation of strategy backtesting. The application part is divided into two further lessons explaining the web-based platform application  and the downloadable spreadsheet application separately. You will be able to download these two lessons as two separate pdf documents for free.

I - Lesson 1: Defining a Trading Strategy

Before jumping into strategy backtesting, you need to ensure you have a sound trading strategy in place, which will hopefully include more than "I have a good feeling about this stock!" In slides 5-6 of this lesson, we explore a basic definition of what a trading strategy is and give a simple example.

II - Lesson 2: Building a Trading Strategy

One of the most effective ways of approaching your trading strategy is by treating trading (or investment) as a business. You do not start a business without having a proper business plan in place. The added advantage of planning a trading strategy is that you can benefit from the wealth of available literature on the topic and from the experience of other traders. Luckily, we now have a basic skeleton that we can use to build on. Slides 7-16 explore the main steps in, and components of, a trading strategy.

II.1 - Main Steps in a Trading Strategy

You do not need to come up with a fancy trading strategy before you start your trading or investment. In fact, it is advisable that you keep it simple, at least initially, and then develop it as your trading advances. However, there are three main steps that you need to follow. Slide 7 explains these steps.

II.2 - Components of a Trading Strategy

This sub-lesson takes the previous one further by delving further into the main components of a trading strategy. A sounds trading strategy would ideally include an initial position, entry and exit signals, some sort of filter and money management rules. Slides 8-16 explain these components in details.

III – Lesson 3: Strategy BackTesting Theory

Now that you have understood the basics of building a strategy, it is time to get your hands dirty with strategy backtesting, which is the meat of this tutorial and one of the main offerings of the platform and the spreadsheet. Why is strategy backtesting so important? It is important because, without it, your strategy is arguably as good as none! You could have built the most sophisticated trading strategy in this world but, if you do not test it properly and thoroughly, you may not end up faring as well as you would have hoped. Slides 17-23 of this tutorial take you through the basics and the elements of a rigorous strategy backtesting plan.

III.1 - Definition

This brief sub-lesson answers the simple question, "What is strategy backtesting?" and what that entails. It defines strategy backtesting and discusses its aim in slide 17.  Particularly important is the word of caution on this concept's reliance on past performance and how this should not be taken lightly. It implicitly assumes that history repeats itself, which is not necessarily always the case.

III.2 – Strategy BackTesting Elements

Before you embark on backtesting your strategy, you need to have a proper plan for that too. There are few essential elements that need to be part of every strategy backtesting plan. The first element you need to consider is the input: you need to decide on what will go into strategy backtesting. You also need to determine which output you will be getting out of the backtesting run. Finally, you need to decide on a set of rules. Slides 18-21 discuss these elements in more details.

III.3 – Notable Factors

There are other elements that affect strategy backtesting and the output it produces. Slide 22 explores these elements and other considerations that you need to keep in mind.

III.4 - Drawbacks

Recall that we have earlier given a word of caution on strategy backtesting's reliance on historical prices. Well, that is not the only issue you need to be cautious about. There are other considerations that you need to take into account. Slide 23 gives a brief overview of such matters.

IV - Lesson 4: Strategy BackTesting Model Implementation

In this last lesson of the tutorial, we elaborate on the implementation of strategy backtesting in the platform and the spreadsheet. We discuss the theoretical aspect of the implementation and give an example. We then move on to explain the intricacies of the strategy execution. We use a rather simplified implementation with the output confined to optimising model parameters such that strategy return or P&L is optimised. We touch briefly on this, in addition to all of the above, in slides 24-31.

IV.1 - Strategy Return

In slides 24-29, we give special attention to the strategy return and we explain, with clear examples, how it is calculated in the code. We also note further important matters that are relevant to this discussion.

IV.2 – Strategy Execution

In slides 30-31, we discuss which quantities are being optimised in the code and the intuition behind that. We conclude by making final comments on the code and some of the important elements that we have not discussed so far.

Theory Notes

In this section, you may explore the below slides to study lessons 1 to 4 material in more depth. This part covers the theory behind the strategy backtesting implementation There will be two application parts incorporating study material or guides to the free web-based platform and the downloadable spreadsheet in the next two sections. (Authored by Dr Jolnar Assi)

V - Lesson 5: Platform

We offer you a free web-based platform to explore the concepts you have learned above and their applications using real-world data. The platform is fully automated including data retrieval. You can experiment with strategy building and strategy backtesting. You can also examine and analyse the outcome of Strategy I under different scenarios. The below platform notes explain how you can use the platform to apply what you have learned so far.

Platform Notes

This section presents the material for lesson 5 in a slide format, which can be explored for free as well. You will also be able to download them in a pdf format. In brief, these slides form a mini-guide to the web-based platform, helping you to apply what you have learnt in the theory part for free.

VI - Lesson 6: Spreadsheet

We also offer you a fee-based downloadable spreadsheet that has additional functionality to the platform’s and can be explored offline from your own desktop or laptop. It is also automated and allows you to explore the concepts that you have learned above. . You can experiment with strategy building and strategy backtesting. You can also test the code by changing specific parameters. Moreover, you can study and analyse the outcome of Strategy I under different scenarios. The below spreadsheet notes explain how you can use the spreadsheet to apply what you have learned so far.

Spreadsheet Notes

This section presents the material for lesson 6 in a slide format, which can be explored for free as well. You will also be able to download them in a pdf format. In brief, these slides form a mini-guide to the downloadable spreadsheet, helping you to apply what you have learnt in the theory part on your own device.

Conclusion

In this tutorial, we have discussed how to build a trading strategy. We have elaborated on the important elements that should constitute any solid trading strategy. We have also strongly advised to backtest the strategy before deploying it in real time.  Strategy backtesting is the backbone of trading. It gives you a rough idea of what to expect. However, it relies heavily on historical data and this is not always a good predictor of future performance. The key takeaway from this tutorial is to build a simple trading strategy that suits your trading style and backtest it on several market scenarii using a simple system of whose flaws you are fully aware.

Frequently Asked Questions

Have a question on strategy backtesting? Check out answers to some popular questions below. Alternatively, write to us!

Do I need to have any prerequisites before I venture into this tutorial?

Not really. The aim behind this tutorial is introduce you to strategy backtesting from the bottom up. We hope that you will be able to build on this knowledge to attempt more advanced systems and more complex models in this realm.

Can I backtest any strategy I would like using the platform and the spreadsheet?

Not at the moment. There is currently only one strategy implemented in these tools, namely moving average Strategy I. As the implementation's aim is to acquaint you with backtesting, it should be perceived as an opportunity to learn, and experiment as much as possible with, the basics so that you develop a good grip of the fundamentals.

Before You Go...


Beginning Trader

I am all confused; I am only just getting started. Please take me back to the basics! I would like to start from the very beginning.

Moving Averages

Take me back to the Moving Average tutorial. I am a bit confused by this constant talk about "Strategy I" and I would like to brush up!

Technical Analysis

A bit rusty on Technical Analysis? Not to worry, we have dedicated many pages that explain Technical Analysis in depth.

    Traders Island provides an all-rounded educational resource that combines theory and application. The theory part is presented in the form of information on the website as well as specialised tutorials. The application part is delivered through a free web-based platform and a fee-based downloadable spreadsheet.