In my previous post I discussed the application of Statistical Process Control charts in monitoring trading strategy performance. Based on the SPC selection tool I have decided to use the X and Rm control charts to track the returns of a trading strategy. The X chart will track the actual returns of a trades and compare these against the mean of historical trades. The Rm chart will track the range between two sequential trades and compare this against variance of the historical trades. This is the proper way of applying control charts in cases where sample size of the live-process is one (a single trade).
Recipe X and Rm chart
The recipe that I have used to construct the X and Rm charts is:
- Select a strategy and find the backtest period. This period will be used as “in-sample” period.
- Run a backtest over the in-sample period and find the geometric mean i.e. log(return) per trade.
- Calculate Xm as the average of the log(return) for all in-sample trades and calculate Rm as the standard deviation of the log(return) for all in-sample trades.
- Calculate the upper control limit (UCL) for Xm with the formula UCLXm=Xm+2.659*Rm and the lower control limit (LCL) for Xm with the formula LCLXm=Xm-2.569*Rm.
- Calculate the UCL for Rm with the formula UCLRm=Rm*3.267 and the LCL for RM with LCLRm=Rm*0=0.
- Plot UCLXm, Xm and LCLXm as fixed lines in the X-chart. Plot the log(return) for each individual trade in out-sample period in the graph.
- Plot UCLRm, Rm and LCLRm as fixed lines in the Rm-chart. Plot the delta beteween the log(return) between two sequential out-sample period trades as individual data points.
Note: the formulas of step 4/5 are taken from the Six Sigma Blackbelt memory-jogger available at www.goalqpc.com
Here is a set of sample charts:
The tools setup that I to build these charts is as follows:
- Use amibroker strategy report to produce a report of trades over full period (in-sample and out-sample). Add a custom trade-metric to include the geometric mean for the trades.
- Import the amibroker report in MS Excel in a seperate sheet.
- Maintain a sheet for settings. On this sheet I keep the startdate, the end of in-sample date and the end-date.
- In a seperate sheet I keep the table of data that produces the charts. This table has a column for each line on the chart a column for the each data point.
- The XM and Rm lines are calculated by using a dynamic named range in Excel.
Example for Xm =AVERAGE(nmInSampleReturns) where nmInSampleReturns is a named range defined by the formula: =OFFSET(ABReport!$S$2;0;0;Settings!$B$15;1) (check excel help for the exact use of the Offset function.
- The named range can then also be used as series() data element in the graphs so that graphs are automatically adjusted to changed lengths of in-sample periods.
- The steps 1through 6 are automated with VBA code so that when I update a performance report for a strategy the SPC charts are updated as well.
As described earlier, this method is used as visual aid in monitoring strategy performance. I am not convinced it should be used to switch on/off strategies but it is should be helpful as means to trigger the trader when the strategy may be breaking up. The trader should then start to check assumptions that may have changed since strategy inception or to check market conditions (extreme news events) etc. Based on these checks one must to decide to continue or to stop the strategy.
If you would have of any further questions on the SPC charts, drop me a line.
– QD –