Posts Tagged ‘loss’

BackTesting Moving Averages

March 9th, 2009 by jackieannpatterson | 4 Comments | Filed in Backtesting Set Up, Moving Average, Reports, Technical Strategies

Why Moving Averages

As a trader or investor, the only reason to investigate moving averages is to gain knowledge to increase profits. Like many other technical indicators, moving averages are meant to help us objectively tell the market status at any given time. This helps us see through the emotions of the day and make rational decisions, which we’re told will lead to greater profits and/or fewer losses over the long run. Moving averages (MAs) smooth the series of prices for a stock. MAs are most often used to identify the trend of market direction, and are classed as a trend-following indicator. This doesn’t mean that MAs are only for long-term investors – short term traders use them also. Moving averages can be used to screen stocks for good candidates, signal buying opportunities, and offer sell signals.

Why Backtest – A Story

The goal of backtesting is to find out if moving averages really do lead to better results and what are the most promising ways to apply MAs. Let me tell you a short story. While I was putting together the results for one of the moving average BackTesting Report issues, I happened to visit a friend. At her house, I came across some reading material from a well-advertised discount stock broker. In it was an article that advising its customers to use a particular moving average length applied in a certain way to get the best results. I had my comprehensive tests right in front of me and I can tell you that broker’s method did not get the best results although they did mention a MA length that is useful in other ways. I had in my hand test results that showed that the way that broker applied the moving average had a win rate worse than the baseline when tested on 7147 stocks over 14 years of stock market data. Clearly the broker wasn’t running that kind of testing. It’s up to the customers – us! – to fend for ourselves and find out what works versus what doesn’t.

How to Calculate MAs

When backtesting moving averages, the first decision is how to calculate the moving average. Do you want a simple moving average (SMA)? Or something designed to track price better such as an exponential moving average (EMA)? You might consider an experiment to compare the win rates of the two different averages. I did just that a couple years ago, and while I don’t have the results to publish, I came away with the notion that it didn’t make a big difference whether I chose SMA or EMA — just pick one and use it consistently. So for this project, I choose to use simple moving averages because I see them mentioned in commentary most often. To actually do the calculation, I relied on the built-in function which came with TradeStation. (The choice of backtesting engine is another decision which is general enough to write about in another post.)

How to Use MAs

Next you need to pin down how exactly you want to apply moving averages. How will you interpret the relationship between price and moving average? What rules will you use to decide when to buy and sell? You don’t have to read long about stocks before coming across a bullish reference to a stock trading above its 200-day moving average or its 50-day moving average, or even the 10- or 20-day MA. Or advice about buying stocks as they cross their 50-day or 200-day moving average. These are important rules to test in the backtesting engine. And then there’s the moving average crossover – a classic method of technical analysis. That makes three distinct ways of using moving averages to test.

Going more in-depth, some trading texts talk about the slope of a moving average. If you hark back to algebra and consider the MA as a line, to find its slope you would pick two points on the line and apply the usual formula ((x2-x1)/(y2-y1)). This brings up the question of how far apart to pick the two points which can make a difference to results. Really, since the MA is being used to identify the trend, we just want to know if it is sloping up or down. Then we can simplify the whole calculation by noticing that if the price is above the moving average, it must be pulling the average up, and a price below the MA pulls it down. Thus another reason to test the efficacy of price above the moving average.

Parameter settings

Once you decide on how to use the MAs, you need to pick a selection of various lengths to test. Beware of over-optimizing. Somewhere out there is a guy with backtesting results showing 3895% gain or whatever using just the right moving average. Too bad he doesn’t know what MA will produce those results in the future. That said, you need to try more than one length to make sure that your results aren’t a fluke. Stick with defaults settings or the ones you hear about most in the media. Finding the one perfect parameter setting is not going to make you rich. Finding a cluster of good, robust settings just might do you a great deal of good though.

As a practical matter when backtesting allow enough data lag before measuring. All tests must begin measuring at the same place for apples-to-apples comparison among different MA lengths. For example, if you’re testing a 200-day moving average, it will take the first 200-days of data to calculate the first point of that moving average. That means that the first day you could possibly have a signal is 200-days into the data set. To make a fair comparison with, say, the 10-day moving average, you need to make sure not to count any signals from the 10-day moving average before the 200-day is ready to go. Fortunately TradeStation has a way to set the “Maximum number of bars study will reference” in “Properties for All” strategies which forces the backtesting engine to wait that long before tabulating data.

More Profit from Buying or Selling?

Moving average rules, and in particular moving average crossover rules, are often discussed as a reversal system. This means that one signal, say the MAs crossing upwards is a buy signal and then its opposite, say MA lines crossing down, is not only a sell signal but also the trigger to go short. Theoretically, that’s just fine but many people are not interested in shorting the market. They are looking for techniques to help them buy and maybe sell. Even a person who regularly sells and sells short might use different techniques for buying and selling. For these reasons, it’s wise to test the buy signals separately from the sell signals.

This poses a dilemma because it’s hard to evaluate a buy signal in isolation. One way to do this is to use timed exits – that is, exit the trade or sell the stock after a certain amount of time elapses. I chose to run each backtest three times with three different times exits because different people have different styles and different needs. To produce backtesting results useful to swing traders, I exit after 2 days. To model position traders, 20 days. To meet the needs of active investors, backtesting holds each position for 200 days. This gives a way to isolate the buy signals and find out just how useful the moving average is to stock buyers of various temperaments.

Need to Define Goodness

One more very important thing to consider if you are backtesting moving averages to find out how well they do in the stock market: How will you know what is good? You need objective criteria for success. That means identifying the key statistics such as win rate, expectancy, hypothetical equity gains, etc. It also means setting standards for acceptable performance in each of these areas.

An example illustrates why this is important and why it’s not as easy as it first appears. Say your tests show a win rate of 55% for a particular indicator. That may might not be so good if, say, 62% of all stocks went up during the same period of time. Or if only 25% of stocks rose during that time period, your 55% win rate would be spectacular. What is good depends on how it compares to baseline market performance under the same conditions.

You can download a free copy of the BackTesting Report Baseline issue by clicking here.

Test Set

For a meaningful backtest, you need to have enough data to make a statistically valid comparison. At the minimum, that means 30 trades. Even if you are trading just one instrument – just one stock or just one currency pair – I think it’s important to test your trading strategy on many different instruments to prove its robustness. I went over the top with an extremely large test set — 7147 stocks over 14 years — to make sure my results would apply in a wide variety of market conditions.

You can get your copy of my backtesting reports on moving average buy signals by clicking here.

Tags: , , , , , , , , , , , , , , , , , , , , ,

Dollar Trailing Stop Definition

October 29th, 2008 by jackieannpatterson | No Comments | Filed in Glossary

The Dollar Trailing Stop is one way to limit losses and protect profits. A stop loss order is set a given dollar amount away from the current stock price per share. As the price moves in the trade’s favor, the stop rachets along with, never giving ground once its protected by the stop. For example, after buying long, a trader may set a trailing stop $1 below the current price. As the price moves up, the trader moves up the stop but never moves it down when the price goes down. Eventually the price does retrace the $1, the stop is hit, and the trade exits.

Extra Insight:

In backtesting, the same dollar stop value is applied to all stocks. This is not ideal because each stock has a different daily price range.  For example, setting the stop $1 away from the price of a $10 stock makes a fairly wide stop but the same $1 stop on a $100 stock is very tight.

As with all trailing stops, the dollar trail never exits at the extreme of a movement. Hence it always gives back some of the profits.

Click here for BackTesting Reports on Trailing Stops

(Backtesting Blog is an Amazon Associate.)

Last updated 11/11/08.

Tags: , , , , ,

Drawdown Definition

October 29th, 2008 by jackieannpatterson | No Comments | Filed in Glossary

A Drawdown is a dip in account value from its highest point.

Wikipedia has a very rigorous definition here.

Extra Insight:

An open drawdown is calculated by taking the current market value of both open and closed positions.

Two tricky things about drawdowns:  knowing how much you can handle, and estimating how much you might be in for.  That’s the key to pick a trading system (strategy and sizing) that doesn’t risk more than you can afford to lose.

During backtesting, keeping track of adverse excursions, or how far winning trades go in the wrong direction can give some insight into potential drawdowns of a trading strategy.  

To be absolutely sure to avoid devastating drawdowns its necessary to limit the amount of money in play.

Each person must define what level is devastating for themselves however 50% loss is often called “blowing up”.

Last updated 11/11/08.

Tags: , , , , , ,

Exit Strategy Definition

October 29th, 2008 by jackieannpatterson | No Comments | Filed in Glossary

 The Exit Strategy is a well-defined plan specifying the conditions to get out of a trade.  

 For a long trade, exiting means selling the stock. For a short trade, exiting means buying a stock.

Extra Insight:

Having a strategy for exit allows a trader to plan with a cool head rather than getting caught up in the heat of the moment.   Backtesting the exit strategy gives a trader insight and confidence in the plan.

Most traders have two purposes for exiting:  taking profits and cutting losses. 

Sometimes both ends are served by one exit order, such as a trailing stop.    Other times, they are two distinct orders, such as a fixed stop loss and a target limit order.

A third goal of an exit strategy may be the efficient use of capital.    In that case, the exit strategy may have rules to exit a trade that isn’t going anywhere in order to redeploy the resources elsewhere.

Click here for BackTesting Reports on Exit Strategies

(Backtesting Blog is an Amazon Associate.)

Updated 11/12/08.

Tags: , , , , , ,

Monte Carlo Simulation Definition

October 22nd, 2008 by jackieannpatterson | 1 Comment | Filed in Glossary

Monte Carlo Simulation is a method of stress-testing a trading strategy.   The general idea is to use random data to construct a larger sample space built according to the same results distribution as the original sample.   This more clearly shows the effects of chance on potential outcomes and gives a broader set of data to make decisions.

Monte Carlo methods may be applied at different places in the trading strategy development progress.

One way to apply Monte Carlo methods to backtesting results is to randomly re-sample trades.  Start with the distribution of results for a backtest.  Rather than go  trade to see what happens next, we can run simulated trades.  Tens of thousands of simulated trades.  The result of each simulated trade is generated randomly according to the actual distribution found in the backtesting run.  Then plot the results distribution of all the Monte Carlo simulations to see the broad range of possible outcomes for the trading strategy.

Monte Carlo simulation may also be used to assess the statistical significance of backtesting results.  The process is advocated in Evidence-Based Technical Analysis: Applying the Scientific Method and Statistical Inference to Trading Signalsand described in detail in this paper by Dr. Timothy Masters.  

Extra Insight:

Rather than try to digest the raw results of 100,000+ trades, set boundaries on potential outcomes and use the Monte Carlo method to assess the likelihood of a trading strategy producing those results.   For example, if we define a catastrophic loss as 50% of account value, we can keep track of the number times that happens in 10,000 runs of 1,000 trades each, for example.    That’s one estimate of the probability that the trading strategy will “blow up” in the future.

Of course, the market in the future may not follow the same probability distribution as our initial sample!   Also, we backtest stocks one at the time but a portfolio holds multiple stocks which may move together so the method described above doesn’t exactly model real life.    It is a useful approximation, however.  

For a more comprehensive definition see Wikipedia for Monte Carlo Method and Monte Carlo applied to finance.    For motivation in very accessible terms see Fooled by Randomness: The Hidden Role of Chance in Life and in the Markets

(Backtesting Blog is an Amazon Associate.)

Updated 11/12/08.

Tags: , , , , , , , ,

Percentage Trailing Stop Definition

October 22nd, 2008 by jackieannpatterson | 1 Comment | Filed in Glossary

The Percentage Trailing Stop is one way to limit losses and protect profits.  A stop loss order is set a given percentage away from the current price.    As the price moves in the trader’s favor, the stop rachets along with, never giving ground once its protected by the stop.   For example, after buying long, a trader may set a trailing stop 7% below the current price.   As the price moves up, the trader moves up the stop but never moves it down when the price goes down.   Eventually the price does retrace the 7%, the stop is hit, and the trade exits.

Extra Insight:

In backtesting, the same percentage value is applied to all stocks.   This is not ideal because each stock has a different daily price range — some will routinely move 3% in a day while others barely budge.    The percentage trailing stop adapts to the individual stock better than the dollar trailing stop but not as well as the ATR trailing stop.  

As with all trailing stops, the percentage trail never exits at the extreme of a movement.   Hence it always gives back some of the profits.

Click here for BackTesting Reports on Trailing Stops

(Backtesting Blog is an Amazon Associate.)

Updated 11/12/08.

Tags: , , , , ,

Profit-Taking Exit

October 18th, 2008 by jackieannpatterson | No Comments | Filed in Glossary

A trading strategy might have several different types of exits, among them the Profit-Taking Exit.  As the name suggests, the idea is to bag some profits.  Cha-ching!

 

Extra Insight:

The profit-taking exit won’t necessarily mean selling at the top.  That’s difficult, maybe impossible, to do consistently and its often called a fool’s errand to try.

Some examples of profit-taking exits are price hitting the upper channel boundary or a pre-defined target percentage gain.

Another profit-taking exit is a trailing stop.   A stop (loss) order is put in place below the current price (or above it for a short).   As the stock price moves up, the stop price moves up too.   Different methods of trailing a stop: ATR (average true range), percentage, and fixed dollar to name a few.

I’m just listing a few possibilities here, not suggesting which one to use.

Click here for BackTesting Reports on Exit Strategies

(Backtesting Blog is an Amazon Associate.)

Updated 11/12/08.

Tags: , , , , , , , ,

Results Distribution Definition

October 18th, 2008 by jackieannpatterson | No Comments | Filed in Glossary

The Results Distribution is a graphical way to show the performance of a trading strategy.   The graph above shows the results of backtesting a trading strategy across several thousand stocks over a 3-year period.

Extra Insight:

Let’s take apart a simpler example:

Each trade is assigned to a bin depending on its profit/loss results.   Different people use different measure of results: dollar gain, percent gain, etc.  I use Van Tharp’s R-Multiple which is the gain divided by the amount risked.   I label the bins with the mid-point of the range.  

For example, a trade that gains twice what was risked goes into the “1.5″ bin along with all the other trades that returned between 1 and 2 times the risk amount (R-Multiple).    

The horizontal axis shows each bin and the vertical shows the number of trades in the bin.   The red line is the zero point which separates winning and losing trades.  In some graphs, profitable bins are green and losers red.  

In our example above, we see that 196 trades returned a profit that was less than the amount risked (less than 1 R-Mult) because the bar for the “0.5″ bin is 196 trades high.   Unfortunately for this strategy, even more trades lost money, which we can tell at a glance from this graph.

In general, better strategies have more action to the right of zero on the chart – more profitable trades either in quantity or quality or both!

The Puppetmaster’s article on Redistribution is an excellent illustration comparing the results distributions for two different trading strategies.

Updated 11/12/08.

Tags: , , , , , , , ,

R-Multiple Definition

October 17th, 2008 by jackieannpatterson | No Comments | Filed in Glossary

Van Tharp created the concept of R-Multiples which I find useful in evaluating the performance of trading strategies.  Very briefly, an R-Multiple of a trade is the gain divided by the amount risked.  Losses are negative number, profits are positive numbers.

Updated 11/12/08.

Tags: , , , ,

Signal Definition

October 16th, 2008 by jackieannpatterson | No Comments | Filed in Glossary

A Signal is the specific event that says when to get in or out of a stock. 

Extra Insight:

Some signals are objective, for example price hitting a 52-week high.   Others are more subjective, for example magazine covers depicting emotional extremes can signal the end of a trend.

For backtesting, we need objective signals that can be evaluated by a computer program.

During backtesting, the computer will take every signal promptly. 

A human trader may ignore a signal or delay taking action — particularly if it is painful!  A human trader may also act even in the absence of a signal, buying when they feel like shopping or selling when they feel fearful, regardless of the signals from their trading strategy.   In this case, the profit/loss performance will differ from the backtesting result.

Updated 11/22/08.

Tags: , , , ,