Buy and Hold comparison for automated trading strategies

Do my new automated strategy worth to be traded? Is it better than an old “buy and hold” strategy? Let’s see how we can make comparison in this blog article.

Buy and Hold strategy, what is it?

Buy and hold strategy is nothing more than buy an instrument and hold it without doing anything than watch it grows your initial balance. It’s pure passive investment and it’s still something largely “traded” for retirement plans for example.

It’s sometimes more profitable than doing more than one order operation on the same share and that’s the reason it is often used as a comparison to fully automated trading strategies.

How to compare result with buy and hold?

Let’s say that we have a simple strategy made of breakout of the recent highest high with a 200 period moving average acting as a trend filter. Orders are closed with price crossing under more recent lowest low.

Of course this kind of compare is only possible with long only strategies, because we are comparing with passive investment, no short positions could be used.

This simple strategy produce gain because trend is bullish since a while. To compare with buy and hold, we must use the exact same conditions than the strategy itself:

  • same initial capital
  • same start date for investment
  • same price entry as the first trade

What we want here is to set a new indicator that can draw a curve of the buy and hold equity directly over the gain/loss equity produce by the backtest. This way, comparison should be easier.

Let’s define the same parameters in a new indicator called “buyandhold”:

Once these parameters are defined, we could do some calculation:

Here is what we got on the equity curve chart, when the indicator is applied on it (use the wrench on the upper left side of the window):

As you can see in this example, buy and hold is better investment until a sudden gap crash was observed in mid 2007 (orange curve).

Done. This code snippet is a great tool for automated trading development, hope you’ll find it useful!

Of course, comparison should also be made on many others criteria such as drawdown, fees, risk/reward ratio, etc. but it were not the purpose of this approach.

 

Share this

  1. AngelPujalt • 01/16/2017 #

     Lo podrías poner todo en un archivo  itf para testearlo. Gracias 

    • Nicolas • 01/16/2017 #

      Sólo copie / pegue todos los códigos y ya está hecho 🙂

  2. Wilko • 01/16/2017 #

    Great code again!! Thanks!

  3. victormork • 01/16/2017 #

    This is awesome, thanks!

  4. Bard • 01/16/2017 #

    Brilliant idea, and here’s an interesting video presentation by Matlabs/Mathworks on Commodity Strategies compared to Buy and Hold using Momentum Indicators such as SMA Slope and SMA Difference and then looking at lagging momentum commodities and buying them to profit as they catch up with the other commodities in their sector (Energies, Grains, Softs and Metals) :
    https://uk.mathworks.com/videos/commodities-trading-with-matlab-81986.html

  5. Kris75 • 01/16/2017 #

    Hi Nicolas,
    This code did not work for me;
    this one worked:

    balance = 10000
    mylot = 1
    startdate = 20100930

    if date=startdate then
    ////save the current close once when the comparison start
    firstclose = close
    elsif date>startdate then
    ////calculate buy and hold with pointvalue and pointsize of the current share
    buyandhold =balance *(close/firstclose)*pointvalue*mylot/pointsize
    else
    ////if the displayed date is previous from the startdate, let’s draw the buy and hold curve as the balance
    buyandhold = balance
    endif

    RETURN buyandhold coloured(255,128,0)

  6. ggolfet • 01/16/2017 #

    @Nicolas
    Really useful tool, thanks!
    Is there a way of plotting the ratio gain/loss on the chart of the automated strategy in order to see it at first glance (without opening the detailed report of the strategy) ?

    • Nicolas • 01/16/2017 #

      Yes.

    • ggolfet • 01/16/2017 #

      @Nicolas
      Sorry, I didn’t see your reply. Could you tell me how to plot the ratio gain/loss directly on the chart of an automated strategy ? Is there a specific command that I can insert in the trading system or is there any parameter in the configuration of the sofware that I need to modify?
      Thanks in advance
      Gabriele

  7. vindioux • 01/16/2017 #

    Bonjour Nicolas (et les autres),

    Y a t’il la possibilité de le coder en backtest plutôt qu’en indicateur de manière à voir le drawdown.
    J’ai fait ce code en entrant manuellement la date de sortie (ici le 30/10/2019), mais y aurait il moyen de l’améliorer pour qu’il s’adapte tout seul à la date de sortie (fonction du jour ou j’ouvre le backtest)?
    Merci par avance de votre aide

  8. vindioux • 01/16/2017 #

    Le code :

    Defparam cumulateorders = false

    Capital=10000
    n=Capital/close
    n=round(n)

    IF Not OnMarket THEN
    BUY n shares AT MARKET
    ENDIF

    IF date=20191030 THEN
    SELL AT MARKET
    ENDIF

  9. Swingueur • 01/16/2017 #

    Hi
    Looks like RETURN doesn’t work and needs to be replaced by GRAPH.
    I use this code
    once firstclose = 0
    once firstn = 0
    if firstclose = 0 and firstn = 0 then
    buyandhold = CAPITALInit
    else
    buyandhold = CAPITALInit+(close-firstclose)*firstn
    endif
    GRAPH buyandhold coloured(255,128,0)
    And I initiate firstclose and firstn just after the BUY statement if both variable equals to 0

avatar
Register or

Top