Backtesting question

Discussion in 'Strategy Development' started by chanelops, Sep 17, 2009.

  1. I do mostly swing trading, and have been backtesting strategies without any problems, but now I've reached a point where I'm not sure how to proceed. The strategy I currently want to test exits upon hitting a profit target, which my previous strategies have not. In addition, as is often the case, there is a stop loss exit.

    My question is how do you go about doing a backtest of something like that? The problem I have is that if I use daily bars, I could easily have a situation where both the PT and the stop loss are hit, within the same bar. How do I figure out which one gets hit first?

    The only solution I can think of is to use shorter bars, like hourly. Since this is a futures strategy, that means 24 bars/trading day, which is a lot of bars if you want to go back a bunch of years.

    I assume that is the standard way to proceed, or is there some obvious alternative that I'm missing here?
  2. this problem is an isue for everybody having tp's and sl's
    not far from the entry as most software is not able to look
    "inside" of the bar, you are only able to test scripts which
    have exit orders at least the next bar after the entry if you
    are using limit orders. you allready gave the anser yourself;
    you will have to re-program your script using a smaller timeframe
    and from there collect the eod data.
    this sometime is not an easy task depending on how complex
    the strategy is and how much eod data will be can be
    done but will most likely slow your cpu down.what platform
    are you using?
  3. lindq


    No, you're not missing anything.

    If you feel it's critical to test both limits and stops intraday, your only option is to use intraday bars. So you'll need to shorten your timeframe or pay for additional data.

    Or, stay with the daily bars and use another exit strategy that doesn't involve the same day. Look at exits EOD, or next day target, or whatever.

    Usually, I don't have a problem backtesting with a year's worth of data. But your challenge right now is that of course we've had volatility through the roof this year. So as that backs off, what's happened over the past 6 months may not be at all indicative of what you're going to see going forward. It likely won't be.

    IMHO, you're better off trying to stick with daily data and looking back farther so that you can test in a variety of market conditions. But you'll need to be able to stand the heat of working in only daily bars when things move against you in actual trading.

    Alas, there is no perfect solution.
  4. The easy way for you is to do two things.

    Each will show you something you have failed to consider.

    1. Divide you stocks into 10 groups by Beta.

    2. Divide your stocks into 10 groups by quality.

    Apply your ATS to the 20 groups. Notice some groups work quite well others are not so hot. Working quite well means there is no problem with this or that getting hit or whether it gets hit first of last.

    as you adjust the two variables you chose you will soom find out high quality stocks have high target possibilities and also lower quality stocks make money less often.

    the beta groups will be correlating to the quality groups as well. You will notice high betas do not get stopped out and high betas have better and higher traget potential.

    Lastly, we are resuming this depressio soon. A that time, there will be a requirement to stay focused and be selective about not making mistakes. My view is that by doing very high quality, you do not need stops. To elimnate stops you take a smaller proportiion of the profits. The side effect is you make more money per unit time.

    Entr a little later and use a different exit plan. Later means that the profit segment is underway after getting up some steam. you compare possible steam levels of entries with the steam levels of holds. If whayt you are holding is moving at less velocity than what you are buying a little later, then swap the hold for the new entry.

    Trading cycles per year is the key adjustment for making money. At a fixed rate (10% per trade), consider compounding 30 40 50 60 70 80 and 100 round trips per year. To do this shift from fewr cycles to more cycles, it is done as explained above. Enter a little late and crossover when a hold is not exceeding a potentiqal buy.

    Oh, data is cheap. Use 30 minute bars to find out how swing trading works.
  5. You don't have and you shouldn't have with daily bars. If both are hit within the same bar it is prudent to assume that the stop was hit first. This is the conservative approach. Other wise, you really need intraday data.

    Also, if you are backtesting using you own code, make sure you do not fall victim of the flaws discussed in this paper.
  6. Thanks to all for the helpful responses. While I was afraid that was going to be the answer, it's good to know I'm not missing anything.

    I'll digest all of this (and look at the referenced paper) and post back if there's more to pursue.

    This is a good example of how ET can be helpful, even in a small matter like this. It kinda makes up for some of those other threads! :)
  7. Backtesting is a waste of time.
  8. minmike


    Back testing a stop or a profit target is fine on daily bars. The problem comes in when you want to test both. I would test them one at a time before seeing if I needed to test
  9. vikana

    vikana Moderator

    For testing exits where e.g. both a profit target (PT) and stop loss (SL) could be hit, I've done the following

    Pick a number, say 40% and randomly choose the PT 40% of the time and the SL 60% of the time for the bars where both PT and SL could be hit.

    Try changing the 40% from 20% to 60% and see how that works out.

    In my experience ( my strategies) using 40% gives slightly worse stats (i.e. is more pessimistic) that testing on intraday data, but allows me to test a lot more data quickly.

    Ultimately, you'll need intraday data, but you can get much closer with the simple approach above.
  10. Vikana,

    Just saw your post, above. Very interesting idea -- I'll check it out!

    #10     Sep 21, 2009