Click here to Login




How to build and backtest a robust stock trading system

Updated on 2012-09-10





If not correctly built and backtested, mechanical trading systems could make a lot of damages to your capital. Each trading system you develop must pass through a series of tests to ensure that it is robust enough and that its results are statistically significant and not due to chance.

To create a robust stock trading system you must ensure that:

It is profitable for different markets or stocks
A robust stock trading system must be able to produce profitable results for different group of stocks (Example: Stocks whose ticker symbol starts with "a" and stocks whose ticker symbol starts with "b")

Changing the start date of the simulation does not affect its performance
Change the start date of a simulation and observe changes.

The performance of your stock trading system is not affected by simply changing the value of one of its parameters
If you are using a 50-Bar moving average in your buy rule, then try another period (60 or 40) and make sure that the performance of your system is still strong.

It is not over-optimized (curve-fit)
When optimizing the different variables of your trading system, make sure you apply the in-sample/out-of-sample technique.

The logic and trading rules behind the strategy make sense
The following rule makes sense: Close above moving average
The following rule doesn't make sense: Close above the relative strength index (RSI)

The performance of the strategy is not due to a very small number of trades
In the trading system report, select "Trades" tab then verify that the top 5 or 10 trades are no responsible for the majority of your trading system's profits.

It has a good return almost every year
In the trading system report, select "D.W.M.Y" and check the return of each year (fourth graph)




Vary the start date to test the robustness of your stock trading system

In this article, we will test the robustness of a trading system by applying a technique that consists of performing several backtests each one with a different start date (second point from the above list). This allows the backtester to pick different stocks or securities on each run then calculates the performance of your trading systems so that you can measure the average performance and thus verify whether you have a robust trading system or not.

The implementation of this technique requires a money management script. In the next paragraph, we will show you how to implement this script. Note that you can download a ready-to-use version here (Vary the Start Date of a Trading System Simulation).

First, we must catch the "OnStartSimulation" event and add an optimizable variable. This variable is going to be used to create different start periods.

Functions.SetNumericInput("Lag", 5, "Wait the specified number of bars before starting the simulation");

In the "Global" event, let us create a new variable (lag):

double lag = 10;

In the "OnEndPeriod" event, we must read this optimizable variable and associate it with the "lag" variable specified in the "Global" event. We must also decrease the "lag" variable by one on each new period.

if(Divers.IsFirstBar)
{
lag = (double)Variables.GetVariable("Lag");
}

lag--;


Finally, in the "OnNewPosition" event, we simply need to reject any new position if the "lag" variable is still positive.

if(lag >= 0)
{
Functions.RejectAllPositionsForThisPeriod();
}



Note: To create a new money management script, select "Analysis -> Advanced Money Management Script", type the different scripts (for each event) then click on "Save".


How does it works?

Now, let us try this trading system robustness technique on one strategy. Either you must download the money management script from here (Vary the Start Date of a Trading System Simulation), or you can create it by following the above steps.

- Select a trading system you want to test
- Click on "Update" to update your trading system
- Select "Money Management" tab (top)
- Click on "Add an existing money management script"
- Select your MM script then click on "Load Selected Item"
- Click on "Update Trading System" (bottom) to save changes

Now, you will see a new tab in the right panel. There, you can specify the "Lag" period or the number of bars to wait before starting entering trades.

To optimize this variable:
- Click on the icon next to "Optimize" (Under "Money Management Variables")
- Select, for example, "From 0 to 20, increment by 5"
- Click on "Optimize" button to start the robustness test of your trading system (optimization process)

In the simulation report, you will see five different backtests, each one corresponding to a different "lag" period (check the "Lag MM" column). If the performance (return, maximum drawdown, Sharpe...) measures are stable then your stock trading system passed this robustness test and it is time to make further verifications (See the list above). Otherwise, the trading system you have developed is not strong enough and you probably should not trade it with real money.













8 comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1449 days ago

Profile Graphs
Posted 1554 days ago

QuantShare
Previous Posts

More Posts

Back







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.