Optimization is the process of testing a hypothesis (in this case, a stock market indicator) on historical data to discover which indicator would’ve worked the best. Optimization is a necessary evil because when you’re starting out to trade a new security, you don’t know which indicators to use or which parameters to put into the indicators. In keeping with the empirical approach, try various indicators and different parameters in the indicators to see what works.
Constructing a backtest optimization
Backtesting (testing on historical data) is a valuable exercise that delivers a measure of how well an indicator parameter might work. The simple moving average crossover backtest has this formal hypothesis: If you buy XYZ stock every time the price crosses above the x-day moving average and sell it every time the price crosses below the x-day moving average, it’ll consistently and reliably be a profitable trading rule.
This table shows results of a search for the optimum moving average out of every moving average from 10 to 35 days over the past 1,000 days.
Number of Days in Moving Average | Average Profit/Loss | Percent Gain | Number of Trades |
---|---|---|---|
10 | $1.56 | 68.60% | 178 |
31 | $3.02 | 59.34% | 32 |
35 | $3.32 | 61.69% | 47 |
If you had been willing to trade 178 times in 1,000 days, or roughly every 2 weeks, you would have made 68.6 percent by using a 10-day moving average crossover of the price. Is that a good number? One way to judge is to compare it to buy-and-hold; in other words, buying on Day 1 and selling on Day 1,000.
Slippage is the reduction in trading profits that arises from the cost of trading. Checking the indicator’s performance after slippage can make all the difference between a profitable trading rule and an unprofitable one. This table, factoring in the cost of slippage, now makes the 31-day version of the simple moving average the better choice.
Number of Days in Moving Average | Average Profit/Loss | Percent Gain | Number of Trades |
---|---|---|---|
10 | $0.36 | 28.60% | 178 |
31 | $2.70 | 49.34% | 32 |
35 | $2.10 | 31.69% | 47 |
Refining a backtest
The optimum moving average isn’t based on only one criterion — you have more than one goal (in this example, percent gain.) You’re looking for systematic trading. So, you seek to prove this hypothesis: If you buy XYZ stock every time the shorter-term moving average price crosses above the longer-term moving average and sell it every time the shorter-term moving average crosses below the longer-term moving average, it’ll consistently and reliably be a profitable trading rule.
This table shows results from comparing every short-term moving average from 1 to 20 days against every long-term moving average from 21 to 100 days. (It also includes a $10 slippage cost of each trade.)
Short-term Moving Average/Long-Term Moving Average | Percent Gain | Total Trades | Total Winning Trades/Total Losing Trades | Average Gain/Loss |
---|---|---|---|---|
Version 1: 10/73 | 58.60 | 8 | 6/2 | 1.75 |
Version 2: 5/10 | 63.48 | 147 | 47/100 | 0.56 |
The average gain-loss column indicates that Version 1 makes less profit than Version 2, but takes only eight trades over the 1,000 days. Version 1 also has a much higher number of winning trades than losing trades and a higher gain-loss ratio. Most traders will zoom in on that win-loss ratio and pick the top combination for the lower number of trades and the higher average gain-loss ratio, even at the expense of some profit.
Fixing the indicator
Here are some of the common problems you encounter when you begin backtesting indicators:
Overtrading: Some indicator parameters call for more-frequent trading than you can spare time for. You therefore need to find adjustments to the indicator to reduce the number of trades without damaging the returns from the winning trades. One solution is to filter the buy/sell signals by specifying that you want the software to generate a buy/sell signal only if the price is x percent above or below the moving average or has been above or below the moving average by y amount of time.
Losing trades: The single best way to reduce your losing trades is to add a confirmation requirement, such as one of the momentum indicators. And because the trades being eliminated by momentum confirmation are generally losing trades, the gain-loss ratio improves, too.
Applying the indicator again
After choosing your indicator parameter, your job isn’t finished. Backtests are hypothetical. You didn’t actually make those trades. To get a more-realistic idea of how an indicator-based trading rule works, backtest the rule on historical price data, and then apply it to out-of-sample data. For example, if you backtested on 1,000 days of data, now you should backtest it on the next 500 days of data. If the results are about the same on the fresh data, consider your rule to be robust, meaning it works across a wide range of conditions.
dummies
Source:http://www.dummies.com/how-to/content/how-to-optimize-your-stock-market-indicators.html
No comments:
Post a Comment