Getting started with Backtesting

Foreword by Joshua Ulrich:

Jacques reached out to me to discuss the Backtesting in Excel and R series on my blog, FOSS Trading. Inspired by that series, Jacques wanted to create a more detailed explanation of how to backtest a strategy in Excel and R, and then to extend the examples to an event-based backtesting framework.

Jacques is providing a great service to the community by providing a more detailed, step-by-step approach to testing trading strategies. I’m sure it will help many people who want to learn more about backtesting, but are unsure how to get started.

By Jacques Joubert

Before I write a single word on backtesting I would like to say a special thank you to Joshua Ulrich for all the help he has given me in writing this series. Your guidance saved me from publishing several mistakes and I am grateful for your patience.

For those of you who are new to quantitative trading in R, Joshua is a strong leader in the community who has helped set up the infrastructure for quants by authoring/co-authoring five R packages, running 2 industry blogs, and by being a part of the team that brings us the annual R/Finance conference for applied finance using R.

If you’re new to quantitative trading, then like me, you’re probably frustrated by trying to figure out the best way to build a backtester. Most texts will feed you interesting techniques on alpha and risk models but I’ve only found a few that will hold your hand in building a backtester.

There are 2 main types of backtesting models. The first is vectorised backtesting which is generally used for research purposes, due to its speed of implementation. The second is event driven backtesting which is considerably more complex to code but helps to simulate a more realistic environment. Additionally you can use your event driven model for executing live trades via your brokerage platform.

Usually I will use R to test a hypothesis, I’ll use Excel just to confirm that my calculations are correct, and if the idea proves note worthy I will implement it into an event driven back tester using C#.

Personally I have learnt my lesson of building complex backtests in Excel (Dont Do It!). After learning to code in C# and R there is no way I can go back to using Excel for backtesting.

The focus of the next article will be to introduce you to the methodology of vectorised backtesting, I will be using Excel initially. Backtesting a basic strategy generally follows these 5 steps:

  1. Acquire the data
  2. Create the indicators
  3. Set up the trading logic and generate signals
  4. Calculate the returns
  5. Set up a report of portfolio metrics

For those of you interested in learning more, I have provided the following links:

Click here to go to the first article

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *