The problem with stock trading systems is that they are usually based on an ideal, a single simulation that has been either consciously or subconsciously optimized. System perturbation to the rescue. It won't solve all optimization issues but it can generate more realistic profit/loss statistics than you be might able to obtain by other means.
The Random function can be used to inject either noise or randomness in a ranking system node or Buy/Sell rule. The randomness will cause differing results every time the simulation is run. After multiple runs, the results can be averaged, providing figures that are less optimized, less ideal, and more realistic than the "one-off" simulation.
Stock market analysis tools provided by Portfolio123.
The Random function could be used in a ranking system node to inject white noise, or in a Buy/Sell rule for margin testing. In this tutorial, the Random function will be added to a Buy rule in order to randomly reject some of the top-ranked stocks that would otherwise be purchased. The Optimizer will be used to generate multiple simulations, and for summarizing the statistics for off-line processing.
The simulation is very simple. There is one Buy rule and one Sell rule. The simulation holds approximately ten stocks, and rebalances weekly. The simulation uses a ranking system that ranks each stock based on Short Interest Ratio (SiRatio). The ten top-ranked stocks are selected for purchase and held for one week. They are sold and the process is repeated.
An overview of the trading system is shown below.
This tutorial starts by running the simulation (after it has been copied to your account) . Click Re-Run as shown below.
You will see the GENERAL setup tab. Migrate over to the BUY tab and disable the Buy rule by clicking on the small button to the left of "Buy1". The color of the button will turn from green to red, indicating that the Buy rule is disabled. Then click on RUN SIMULATION.
After a short period of time, the simulation backtest results will be displayed and should look similar to the screenshot below.
Sometimes the date range isn't properly set up. If the date range is incorrect then:
- Click on Re-run
- Go to PERIOD & RESTRICTIONS and set the time period from 2000 to present, or from the earliest date that your membership level will allow.
- Then click on RUN SIMULATION.
Once the results look similar to those shown above, then make note of the Annualized Return. In the example provided, the Annualized Return is 15.30%, and Max Drawdown is -68.90%. These are the ideal statistics, based on a single run of the simulator, which chooses the top ten stocks (only) on a weekly basis. But what about the eleventh-ranked stock, twelve, and so forth? They should give good results too, right? Well, we aren't really sure. They could be terrible picks, meaning the system is based more on luck than good design. But we don't know, at least not at this point in time.
To find out, the simulation is going to be "perturbed", with the addition of a randomness factor that will cause stocks further down the rankings to be picked on occasion.
To kick this exercise off, start by re-running the simulation. Go to the Buy tab and click on the small button to the left of "Buy1". The button will turn from red to green, indicating that the Buy rule is turned ON.
The Buy rule is Random < 0.5. Random is a function that generates a pseudo-random number between 0 and 1. The Buy rule suggests that 50% of the time, top-ranked stocks will be discarded at random, causing lower-ranked stocks to be chosen instead. Keep in mind that the picks are still highly ranked stocks. This logic applies every rebalance period (weekly) so it is anticipated that each backtest will produce a different set of results. Each simulation backtest will buy highly ranked stocks, but not THE highest 10 ranked stocks.
Once the Buy rule has been enabled then click on RE-RUN SIMULATION as shown below.
The backtest results will be different than before. And the user will get different results than what is shown below, simply because the simulation has randomness embedded in it.
Now the Optimizer will be used to generate multiple backtests. The Optimizer is used more of a convenience than anything. The first step is to select "Copy To the Optimizer" from the pull-down "Simulated Portfolio" menu.
Save the Optimizer study as shown below.
Now the simulation permutations are going to be created. Click as shown below.
Click on [copy] nineteen times, causing Random <= 0.5 to be copied nineteen times in the box below. Then click on UPDATE when you are finished.
The optimizer overview screen should look like the screenshot below, with the Buy Rule Random <= 0.5 listed a total of twenty times.
Now click on Generate Permutations from the Study pull-down menu.
The simulation runs are listed. The Optimizer is now primed and ready to go.
Click on Run from the Study pull-down menu.
The status is displayed while the Optimizer is running.
When the simulation backtests are complete then download the results to EXCEL. This is done by clicking on Download from the Study pull-down menu.
The rest of this exercise are done off-line using EXCEL. Start by calculating the average Maximum Drawdown from the 20 backtests as shown below.
Copy the formula for Max Drawdown Average over to the column for Annualized profit.
Based on system perturbation, the average annualized return is 11.3% and maximum drawdown is -67.0%. This compares to the 15.3% annualized return and -68.9% maximum drawdown determined from a single run. It appears that the single simulation backtest scores about 4% more annualized return than an average of multiple backtests with minor variations in the holdings.
Note: Although this type of test can shed light on the design, it does not prove that the design is good or fail-safe. The technique can finger a bad design however.