More accurate spread for back testing.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #90424 quote
    Vonasi
    Moderator
    Master

    We have all seen how important the value of spread is in our back testing. Forget to back test with it and a strategy looks like the holy grail but then deduct several pips for every trade and it doesn’t look quite so good. One of the limitations of PRT back testing is the fixed spread value as I’m pretty sure the spread in 1985 was not the same size as it is today. So I was wondering if there was a better way to apply spread to our back testing.

    I’ve been analysing the DJI daily chart today and I wrote an indicator to compare what happened if you went long after every break of a previous days high or break of a previous days low. There was also a simple only trade if bull market filter. In the indicator there is a simple deduction of a spread amount with every simulated trade.

    Here’s the holy grail baseline with zero spread:

    [attachment file=90428]

     

    Green line is going long after a high break and red is going long after a low break.

    With a fixed spread of 3.8 the results looked like this:

    [attachment file=90425]

    We can see what a big effect the fixed spread is having in the non computer trading era right up to the mid 90’s. After then it all starts to turn more positive.

    So I then thought I’d see what happens if we calculated our spread in the test for each trade as a percentage of the opening price as this might more closely simulate what value spread has actually been over the years. I’m guessing that spread has increased with price and with volatility. This simple calculation simulates the former at least.

    spread = 0.01517 // % of price
    
    myspread = (spread / 10000) * open

    Currently the DJI spread at the end of day is 3.8 so that is 0.01517% of the current price of 25044.

    Here is the results with an ever modifying spread:

    [attachment file=90426]

    That is a much nicer set of equity curves! Maybe we have been throwing away good strategies just because a fixed spread makes them look horrible. Maybe we would do better to leave the PRT fixed spread value at zero and calculate our own spreads in our strategies to use in our back testing?

    A rising index is possibly going to be easier to calculate varying spread on than an up and down forex pair where the spread is most likely more volatility based.

    Does anyone have any other thoughts or ideas on this subject – maybe a way to incorporate volatility in the spread calculation? Maybe one day PRT could even incorporate a spread based on a calculation as an option for back testing alongside the fixed spread option.

    Your thoughts?

    GraHal, Mike, Paul and OscJoh thanked this post
    #189907 quote
    Newbie
    Participant
    Average

    I too am looking for this information as I build a system. The ability to “call” spread as a function, or “look-up” this value would be a game-changer for sure. I’ll keep thinking of options. One option would be to look up from a list, however, as the spread varies constantly throughout the day, the list would need to be adjusted each time. Also as you mentioned, the spreads are not consistent over time. They change as the broker reacts to volatility.

    I’ll keep working!

    #189913 quote
    nonetheless
    Participant
    Master

    thanks for reviving this old post from Vonasi, I hadn’t seen it before. It is an issue I have raised many times: using today’s fixed spread on a 10 year backtest = nonsensical.

    I wrote to PRT about it and they suggested using Spread = 0 and Order fee, % per transaction instead … except that it has a minimum of 0.01 per side which is too high. On major indices in open hours, spread is typically around o.oo8 %

    So how and where would I add Vonasi’s calculation to my algo?

    #189998 quote
    nonetheless
    Participant
    Master

    Hello? Roberto? Anyone?

    I can’t get my head around what to do with this formula, where to apply it 🤔🤔🤔

    Would greatly appreciate some advice on how to code a custom % spread for backtest, thanks!

    #190011 quote
    robertogozzi
    Moderator
    Master

    I never used it, but I think you could use it this way:

    spread = 0.01517 // % of price
    myspread = (spread / 10000) * open
    
    ONCE MyCapital = 0
    ONCE MyEquity  = MyCapital + StrategyProfit
    Gain           = StrategyProfit - StrategyProfit[1]
    IF Gain <> 0 THEN
       MyEquity = MyEquity + Gain - myspread
    ENDIF
    graph MyEquity

    MyEquity is the STRATEGYPROFIT + initial Capital – spread.

    nonetheless and Midlanddave thanked this post
    #190013 quote
    nonetheless
    Participant
    Master

    thanks Roberto, i knew you’d come through 😁

    one more thing though: why (spread /10000) * open ?

    if spread is %, shouldn’t it be /100 ?

    with positionsize = €1 and (fixed spread = 3.8) then the spread would cost you €3.80 (25044 * 0.01517% … using Vonasi’s index value)

    but (0.01517 / 10000) * 25044 = €0.038 (to be subtracted from the gain)  ???

    GraHal thanked this post
    #190020 quote
    robertogozzi
    Moderator
    Master

    I don’t know the reason for 10000. Maybe it’s just a typo for 100.

    nonetheless thanked this post
    #190021 quote
    nonetheless
    Participant
    Master

    thanks Roberto – yeah, I think it must be a typo.

    But today I see that the spread on the DAX got bumped up to 1.8, a 50% move that has nothing to do with any % of its value. So maybe that correlation is no more reliable than ticking the box for fixed spread.

    I’ll write to IG and ask if they happen to know what the spreads were 10 years ago and when they changed … someone must know these things.

    #190025 quote
    robertogozzi
    Moderator
    Master

    Anyway, my opinion is that the PAST spread is of no help.

    Backtesting will tell you how the price moves affected your strategy in the past. It’s Pips or Money that count, SPREAD won’t affect it. If 5 years ago spread was 8 points and now it’s 2 points, you should use 2 points, as the backtest will report what would have happened if it were 2 since the beginning. In the future it can be higher or lower, at anytime spread changes significantly you should batcktest again your strategy to cope with it for the future. And it will calculate performance using the future SPREAD even on today’s trades. It’s a simulation for the time ahead, you should only care for correct/incorrect trades.

    It may happen that some past trades did not even occur at that time, while the do now, due to spread or volatility or slippage, I think you shoudn’t care. It’s important that your strategy is tested to report performance from the past using TODAY’s settings. Pips/Money earned or lost IS all that you have to care about.

    nonetheless thanked this post
    #243488 quote
    Padrock
    Participant
    New

    I tried to use this code to make better modelling of spread and it doesn’t make a trade.

    this is the initial code that sets the betsize (BS) for the trades based on how much money the account has. it was working find until I added the code to deduct spread . Any suggestions where it is going wrong? it seems to not longer be producing the value BS so the system cannot place a trade.  Original working code below that made the BS value

    ONCE MyEquity = 10000 + StrategyProfit
    Gain = StrategyProfit - StrategyProfit[1]
    IF Gain <> 0 THEN
    MyEquity = MyEquity + Gain - myspread
    ENDIF
    
    //IG SPREAD QUOTES
    sp1 = 0.6 //BS <=2000
    sp2 = 0.7 //BS <=4000
    sp3 = 0.8 //BS <=6000
    SP4 = 1.0 //BS <=8000
    SP5 = 1.2 //BS >8000
    if BS<=2000 then
    spread = sp1
    endif
    if BS>2000 and BS<=4000 then
    spread = sp2
    endif
    if BS>4000 and BS<=6000 then
    spread = sp3
    endif
    if BS>6000 and BS<=8000 then
    spread = sp4
    endif
    if BS>8000 then
    spread = sp5
    endif
    
    myspread = spread*BS
    
    tippingpoint=10840*(close*0.05) //AMOUNT OF EQUITY THAT WILL CREATE BETSIZE OVER 10840 £PER POINT
    equity = MyEquity*BSP //BSP PROPORTION OF ACCOUNT WILLING TO PUT AS MARGIN MAX 1
    if equity<tippingpoint then
    BS = (equity)/(Close *0.05) //IF MARGIN BELOW TIPPING POINT ONLY 5% REQUIRED
    else
    bs= 10840 + ((equity -(10840*close*0.05)))/(Close *0.15) ) //IF MARGIN OVER TIPPING POINT ONLY 15% REQUIRED
    endif

    this was the previous functioning code

    tippingpoint=10840*(close*0.05)
    capital = 10000
    equity = (STRATEGYPROFIT + capital)*BSP
    if equity<tippingpoint then
    BS = (equity)/(Close *0.05)
    else
    bs= 10840 + ((equity -(10840*close*0.05)))/(Close *0.15)
    endif
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

More accurate spread for back testing.


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 9 replies,
has 4 voices, and was last updated by Padrock
1 year ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/04/2019
Status: Active
Attachments: 3 files
Logo Logo
Loading...