Article Contents
Print

Back-Testing The System

Before we can back-test Trend Trader, we need to set up the trading accounts that will fund the trades and define the nominal trade-size that we chose to use in the ‘Buy Rising Trend’ rule. These are already set up for you, but it won’t hurt to  review the settings.

Trading Accounts

Click on the Trading Accounts tab button in the RuleTrader Test Dashboard and you’ll see a ‘Tutorial’ trading account is already listed in the drop-down list. The buttons below that list let you manage these accounts.

The Trading Accounts tab is where you can create, edit, view and, in Live sessions, sync your Trading Accounts

Click on View/Edit to review the account’s settings. Feel free to amend the opening balance, minimum balance (the amount RuleTrader always leaves in the account to pay for e.g. account fees), trading priority and the broker charge. You can have as many Trading Accounts as you like; RuleTrader will automatically use cash from each account in order of their trading priority, with the smallest priority number being traded first and trades split across accounts, if required.

In RuleTrader Test, trading accounts are entirely self-contained and solely used for back-tests. They have no affect on your ShareScope portfolios or cash-accounts, or on the RuleTrader Live trading accounts, which are linked to your ShareScope portfolios and cash-accounts.

Trade Sizing

Now click on the Trade Sizing tab button. Again this is already set up to use RuleTrader’s unique smart % trade-sizing algorithm, which is a flexible method designed to maximise the return on the trading account’s cash. It’s explained here.

In the Trade Sizing tab you define the nominal trade size used by your Trading Spec

You can see that the algorithm is configured to nominally use 4% of capital/cash per purchase, which implies approximately 25 positions (100/4 = 25). This will do for now.

The minimum trade value prevents trades for less than the value specified (e.g. if the trade is automatically split across accounts) and should be set to a substantial multiple of your typical trading charges, to avoid unnecessary drag.

You’ll also see a ‘Trading style’ setting, which controls how RuleTrader simulates trading in the back-tests. Pick whatever matches your trading style, as described here.

Running The Back-Test

So without further ado, lets click on the Test System tab button and set the parameters for the back-test.

The Test System tab of the Dashboard is where you create and test your Trading Specification

As the Trading Spec is already defined and selected, the main areas to focus on are Test Scope and List Sampling. Test Scope specifies the start date and stop condition for the test, which securities will be tested and the frequency with which Trading Rules are evaluated. The process is explained here. For now, simply:

  1. Set the start date to 1/1/2024
  2. Set the stop condition to ‘specified date’ then click the U(pdate) button to check what date is specified (shown in parentheses next to the stop condition drop-list). It should be 31/8/2024 (which is when this tutorial was written). If not, click the Stop Parameters button to open the Back-Test Stop Condition Parameters dialog, where you’ll be able to change the date:
Use the Stop Conditions dialog to specify extra paramaters for the back-test's stop event

8 months is, of course, far too short for a meaningful back-test but for the purposes of this tutorial we want the test to run as quickly as possible, while still giving useful results. You could choose any dates you like, but if you stick with these you’ll get similar results to our own (though they won’t be exactly the same, because ShareScope’s database is in a state of constant flux, as it tracks changes in the market).

  1. ‘Evaluate rules every’ should already be set to ‘day’
  2. ‘Securities to test’ should be set to ‘All selected securities’ i.e. that are selected by the Trend Trader specification’s List Selectors
  3. The List Sampling controls should remain unchecked, as we won’t be using this feature. Sampling is used to preserve an untested cohort of shares so that, in theory, you can use those shares to test for over-optimisation, once you have finished your Spec. The controls are explained here and the process of sampling is discussed here, along with our views on its utility.
  4. Next, click the Message Settings button and in the dialog that appears check all the options. You wouldn’t do this normally, but for this first run it will be useful to see the information that can be displayed in the Console, when you run a test.
  5. When you’re ready, click Clear Console (as the test will output a lot of useful data to the console) then click Start Back-Test. On the ‘Confirm Test Start’ dialog that appears, click Ok

And you’re off! The test will take about a minute and a half to run, and you’ll be able to watch its progress with the progress bar dialog that is displayed.

Stopping A Back-Test

While the progress bar is still updating (see below for why it might not be), you can suspend a back-test by pressing the Pause key on your keyboard, if it has one (it also might be called Break). If the progress bar shows that list selection is active (i.e. shares are being selected and/or backfilled), then this will need to complete before the test stops.

When it stops, a dialog will be displayed asking if you want to stop the test or continue. If you choose Stop, you will still be able to restart the test from where it left off, by clicking the Continue Back-Test button on the Dashboard. Why not give it a try now?

This dialog is displayed when you press the Break or Pause key

In The Meantime

While the test is running, you might like to glance at these Help topics, which we strongly recommend as essential reading:

It Hasn’t Crashed!

If you move away from the ShareScope window to look at these topics in your browser, you may notice that ShareScope appears to freeze and the progress bar stops updating. If you then click on ShareScope, its window will ‘grey out’ and its title bar display ‘(Not Responding)’. The ShareScript Console may also disappear.

You have nothing to worry about. All it means is that ShareScope and RuleTrader are working flat-out to execute the back-test as quickly as possible. ShareScope, as it thinks you’re no longer focused on it, decides to save a bit more time by no longer responding to Windows ‘events’ (mouse-clicks, updating the progress bar, redrawing its window, etc.). Once the back test is done, normal service will resume and the Console will reappear.

One downside of this quirk is that ShareScope also stops responding to the keyboard, so it will no longer be possible to use the Pause key to suspend the back-test. Because of this, before you do anything else with your computer, it’s not a bad idea to check the information displayed in the progress bar, Console and Chart Status Panel to ensure the test is running as you expected. That way you can still stop the test if you realise you’ve made a mistake in the test parameters.

Reviewing The Results

Let’s look now at three sets of data that are available to you, to see what happened in your back-test: the test output in the Console, the Usage In Test column provided with RuleTrader, and RuleTrader’s Trading Performance Reports. There’s also Chart and Indicator Panel overlays and Execution Reports, all of which we will discuss later in this tutorial.

Test Output In The Console

The Message Settings tab of the Dashboard controls the information RuleTrader displays about the test. You can view this directly in the Console or, as that’s sometimes hard to read (and the Console doesn’t have a horizontal scroll-bar), it’s usually easier to click in the Console, press Ctrl-A to select everything there, then Ctrl-C and Ctrl-V to copy and paste it to your preferred note-pad application.

For example, you could use Window’s own NotePad program or, our favourite, the more advanced  NotePad++, which is available for free from here.

This output always begins with a header describing the key settings that were in effect at the time of the test. Depending on the Message Settings, the data that follows may include information on:

  • The shares that were selected for the Trend Trader’s trading list
  • The trade signals the were raised and/or the trades that were made
  • The final valuation for all open positions at the end of the test
  • Informational and warning messages, for example if an average spread can’t be calculated for a share because there is insufficient bid/offer data. These are worth checking, just in case there’s an unexpected issue with your Trading Spec, but can usually be ignored.
  • A table showing the number of shares that the Trading Strategy’s List Selectors selected, including the number newly added, continued from the previous list selection, dropped, or dropped and then reinstated in the list because they had open positions. This last is something that RuleTrader does automatically to ensure open positions continue to be monitored by the Spec’s sales rules. The share will be dropped from the list, as soon as the position is sold. Meanwhile no further buy rules will be allowed to trigger for that reinstated share.
Usage In Test Column

The Usage In Test column is displayed in the RuleTrader Test layout’s share list window (if you can’t see it, please consult this Trouble-Shooting article here). If you’re patient and ShareScope’s intraday feed is still enabled (which RuleTrader needs for any automatic event to happen) then this column will update automatically 30 – 60 seconds after the end of the test.

Instead of waiting, to force the update simply right-click on the column header and select Refresh Script, then double-click on the header to sort it in descending order (i.e. so the little arrow head in the column header is pointed down).

You’ll then see a list of those shares that were Traded and those that were Selected for the trading list but not traded, as indicated by the label in the column. You can then work down the list of traded shares (just keep pressing your keyboard’s spacebar), to review those trades in the main Chart.

RuleTrader overlays data on the Chart to tell you what happened in your back=test

As illustrated above, Gain/Loss symbols provide a convenient way to see the start, end and return from a trade, while the Chart’s Status Panel shows information about the test and the share and, if you click on the bar at the start or end of the trade, it also shows information about the trade. If you can’t see these on your chart, then please click on the previous links for information on how to enable them. Similarly, if you can’t see the long and/or short price-channels, or wish to change their display style, please refer to Chart Settings.

We suggest you try it now and familiarise yourself with these very useful features. You may spot, like we did, a few double digit losses, that suggest a stop-loss rule might be in order (the worst was a company called Bango, which certainly lived up to its name with a 47% plunge)

Trading Performance Reports

RuleTrader’s very powerful reports offer over 120 reportable parameters, to give you a comprehensive understanding of your system’s performance. Here we’ll look at two reports: the Account report and the Periods report:

  1. Click the Reports button on the Chart Panel (it’s immediately below the Dashboard button)
  2. In the Reports dialog that is displayed, check the Performance by Account report at the top of the middle section of the dialog, and the Performance by Period (rows) report below it. In the drop-down list next to each of those reports, ensure the Summary Performance parameter set is selected. Each report can have multiple parameter sets defined using the Edit Set button next to the list (give it a try). These parameter sets specify which parameters are displayed in the report and their sort order. All available parameters are explained here.
Choose the reports you want to run in the Reports dialog
  1. As the test was only over 8 months, we’ll need to change the period length for the Period report from its usual default of 1 year. So click on the Report Settings button on the right-hand side of the Reports dialog and in the dialog that appears, change the ‘Period reports have a’ setting to 1 month, then press Ok.

You’ll notice in this dialog that this is also where you can export the report output to a .csv file, for importing into Excel, and you can also change the way the report is formatted, whether ex-div dividends are included in the results, and the benchmark share whose results the reports are compared with.

Fine tune your reports with the settings in the Report Settings dialog
  1. Back in the main Report dialog, click on the Run Reports button and the reports will be displayed in the Console, where you should see something like this (it’s unlikely your results will be exactly the same, due to the ongoing changes in the ShareScope database, as companies enter and leave the LSE market)
The report for the Tutorial v1.00 back-test shows an impressive CAGR of 23.7%

Due to the width of the Period report output and the lack of a horizontal scroll-bar, you may find it easier to copy and paste the results into a note-pad application, as discussed earlier. As well as using Ctrl-A to select all data in the Console to copy, you can also click on the bottom below the last report, then if you drag the mouse up off the top of the console, while holding the left mouse button down, everything in the console upwards will be selected. The same technique works if you’re dragging down.

Analysing Trading Performance Reports

If you’re already familiar with the analysis of trading performance data, then please skip this section. For those who aren’t, some of the report parameters we’ve found most useful over the years, which you may find helpful, are described next. You may need to run, e.g. the Account report, with the Trade Performance parameter set selected to see these parameters. Or why not create your own parameter set, using the Edit Set button.

Firstly, don’t focus on Compound Annual Growth Rate (CAGR), at least while you’re evolving your system. It’s tempting to do so, as profit is ultimately what we’re after, but CAGR, which is a time-normalised measure of the growth in total capital, is very dependent on how well your trading account’s cash is utilised. It also takes no account of how well the market is doing anyway and in the 8 months we used, the market was on a rally. This is great for momentum strategies like Trend Trader, but isn’t something that happens every year. Obviously a CAGR that is lower than the return you’d get from tracking an index, is nothing to write home about.

If you have cash sitting around doing nothing, then CAGR suffers. This in turn depends on how well the trade-size, and so the target number of positions, matches the number of good opportunities your Trading Spec is likely to find in any period. If you’re sampling the trading-list, then the number of shares and opportunities will obviously be reduced, which makes matters worse. Until you get this dialled in by back-testing your system, you’re better off focusing on those parameters that focus on the quality of your trading system and how risky it is.

To focus on the quality of your system you can use measures such as:

  • Profit Factor: Is the ratio of profits to losses and is, in our opinion, one of the most important measures. It really doesn’t matter how many losing trades you incur, so long as you make more profit on your wins. Thus a value greater than 1 is essential and, ideally, a value much greater than 2 is nice to have.
  • Win/Lose Length Ratio: This important measure typically drives the Profit Factor. It is the ratio of the average length of time a winning position was held to the average length of a losing position. It is the numerical equivalent of the adage “let your profits run and sell your losses early”
  • Excess Return vs Benchmark: This removes the effect of ‘natural’ market growth to tell you how much better (or worse) your trading system has performed relative to the market. With the above results from our Trend Trader system, the capital growth of 15.1% over 8 months looks impressive … until you realise that the All-Share (Total Return) index, which is our preferred benchmark, did 11.3% in the same period. So the excess return was only 3.8%. We say ‘only’ but for such a simple trading system to beat the index, actually isn’t bad at all.
  • ROI: unlike CAGR, which is based on capital values, this is simply the ratio of the total value of all sales to the total value of all buys, so it’s a direct measure of the average return from each position. It’s disadvantage is that it doesn’t take time into account, so you don’t know how long it took to achieve that return. However, you can get this from the Average Position Length parameter available in the Periods tab of the Report Parameter Set dialog.
  • Drag: measures the proportion of your profits that you’re losing to trading charges. A high value can indicate you’re suffering too much ‘churn’ i.e. there are too many buys and sells, which may indicate the time that positions are held is too short.
  • Profitable Positions: this is the simply the percentage of positions that yield a profit. Unless you have a crystal ball, a value too far above 50% may indicate you’ve over-optimised your trading strategy, which means it’s unlikely to work well in the future. Conversely, a value too low suggests there may be room for improvement in the way your system picks shares to trade.
  • Trade Efficiency (wins): This is a proprietary parameter of RuleTrader that compares the profit that was achieved, to the greatest profit that could have been achieved, if you’d bought at the lowest low and sold at the highest high, within the trade period. A value of 100% means you maximised your profits in every trade.
  • Dividend/Trading Profit: This the proportion of your trading profits that were due to dividends. You might expect this to be higher if you’re going for an income strategy designed to preserve capital, and less high if you’re after a growth strategy.

It’s also important to look at how risky your system is, using parameters like:

  • % of Positions => 80% of Gains: Another proprietary RuleTrader parameter, this is based on the Pareto principle, otherwise known as the 80/20 rule. It tells you what percentage of positions delivered at least 80% of your gains. So it’s a measure of how broad-based your returns are. Obviously, if you made most of your profits from one or two positions, you might wonder if it was a fluke that’s unlikely to be repeated. If Vilfredo Pareto’s rule holds, then a number around 20% of positions (or shares) is not unreasonable, so anything around or above this suggests your system’s wins are sufficiently broad-based that they may be repeatable in the future.
  • Max Loss % On Any Positions (from a position that closed at a loss), Max In-Position Loss % (on positions that were ultimately profitable), Draw-down % and Max Number of Consecutive Losses are all measures of the pain you may have to bear if you use your system for live trading. You need to know that you can bear this pain, especially if you rely on your investment capital for life’s expenses.

On the upside, being forewarned of such numbers in the context of the sort of returns you might ultimately expect from your system, if you stick with it, can be a useful tonic to help you cope with the inevitable dark days, before you reemerge into the light.

Improving Trend Trader

We mentioned earlier that a stop-loss rule might be a good idea, but what level should we set it at? Reviewing the Account report (using the more comprehensive Trade Performance parameter set), we note that the Max Loss % On Any Positions was ~47%, while the Max In-Position Loss % (on positions that were ultimately profitable) was ~9%. Taken together these suggest a level somewhere between 10% – 50%. 

Before we add a stop-loss rule, click Save Back-Test to save the results of the back-test, then click Reset Back-Test to reset the system ready for the changes we’re about to make. In the future we’ll then be able to reload that test, view the results in the Chart and Usage In Test columns, as well as the settings that were in force at the time of the test, and we’ll also be able to run any additional reports we like on the test data.

The End Of Part One

You’ve now reached the end of the 1st part of this Tutorial, which is the hardest, longest part, so thank you for sticking with it. Hopefully, you’re now feeling fairly comfortable with creating a Trading Specification. In the final part 2 of the Tutorial, we’ll learn how to systematically improve your Spec and turn it into a live trading system.

Scroll to Top