Backtesting with Spreads

Viewing 9 posts - 16 through 24 (of 24 total)
  • #24807

    Hi Derek thanks for the advice – in-and-out-of-sample testing I think means to run the same backtest over different periods of time yeh? (last 3 months – 1 month middle of last year etc.) – if so I agree and backtesting is helpful here to build a picture of the general trading style being executed by the autostrategy being tested but I think monetary gains/losses are only indicative at best which is useful to some extent if the shortcomings are known about

    I do not necessarily think there are issues with the PRT backtesting engine or anything like that but rather that there are many variables over time greatly affecting trades that simply are not incorporated into the backtesting (of which we are discussing here!)

    Re: raising spread for all spreads – yes I did try this but soon realised it simply isn’t going to be in anyway accurate as trades that would otherwise have triggered (buy or sell/any timeframe/regardless of manually increased spread to try and compensate etc.) will be ‘missed’ and the knock on affects for subsequent trades being entered earlier/later than they otherwise would have been only increases this ‘unreality’ over time (that said the current way I am using backtesting is like this and am setting the spread manually slightly ‘higher than average’ of the spreads stated by IG – which as they state – vary!)

    Re: adding different spreads for different times of day into the code – I had thought about this too and came across this forum post – https://www.prorealcode.com/topic/overnight-spread-increase-backtest/ – looks like it has stalled but I also gave up pursuing this after discussing with IG support once I discovered just how much spreads vary throughout a day/over time and also how much they can randomly spike (!) as I have witnessed and read from this forum post over at IG – https://community.ig.com/t5/Suggestions/Getting-stopped-by-the-spread/m-p/11252 (I don’t follow with the OP comment that IG should fix the spreads once a position is opened – that simply ain’t gonna happen! but basically it demonstrates how spikes can mess things up)

    Re: minimum order size see here – https://www.prorealcode.com/topic/trading-fractions-of-a-contract/– I started an autostrategy over on my live account that I had been running in demo for a while on the US500 for no other reason than to test it did not error out – it errored on first attempted entry stating the minimum order size for this market is 5…

    Further to what I have mentioned in that other post/taken Nicolas’s advice and put in the request etc. one of the things the IG support guy was telling me about has just ‘hit home’ – he told me the demo IG system lags behind the live system in that minimum order sizes are not always updated regularly – I have just now looked at the US500 and it is showing minimum order size as 0.5 in the demo and 5 in the live!

    Re: the minimum stop – no doubt you have already seen that auto strategies can continue through attempting to place a stop order that is less than the current minimum distance if they manage to place the trade within a bar or two (seconds timeframe at least anyway) as shown by the yellow warning triangle in the order list but error out and stop after too many unsuccessful attempts – so sometimes you’re lucky and price moves in your favour and the stop order entered other times not (one demo strategy I was running stopped stating min distance was 20 – from what had otherwise been about 5 max!) – and as far as I am aware this is another variable not incorporated into the backtesting…

    Again – my slant on all this whether I be right or wrong about any of it is that the more you know the better set you are to take the backtesting with a very large pinch of salt and skew accordingly in your head more than anywhere else but if anyone has other opinions/can tell me I am wrong about any of these points please do! 🙂

    1 user thanked author for this post.
    #24808

    @Max I agree with you above … I’ve had all above happen while I’ve been manual scalping at periods of high volatility. Spreads can widen and stops increase and be back to normal all in 1 – 3 seconds and it leaves you thinking wtf happened there! 🙂

    GraHal

    1 user thanked author for this post.
    #24810

    the more you know the better set you are

    That sounds about right. 🙂

     

    #25061

    Thanks Derek, yes, I’ve found it better on longer term timeframes. Think I’ll stick to those for now.

    MaxT, I found that one too. I put in this line of code to avoid it:

    MyPosSizeCalc = //enter calculation for your pos size

    MinPosSizeAllowable = 1

    MyEntrySize = Max(MinPosSizeAllowable, MyPosSizeCalc)

    BUY MyEntrySize LOTS AT MARKET

    You can set the min size to whatever it is on the IG market, and that way you’ll never miss an entry in a live run of the system

     

    A

     

    #25165

    Hi Andy

    Yeh that looks similar to this – https://www.prorealcode.com/blog/learning/money-management-prorealtime-code/

    (I don’t really ‘like’ the use of ROUND in that code though as it rounds up or down – not possible to always round down – so to my mind it doesn’t really work as intended but seems to be the ‘goto’ post for money management/position sizing on here – you don’t say what calculation you are using for position size so don’t know if suffers the same issue…)

    but with either code – if IG increase the minimum size part way through a strategy running – it will fail to place the order and stop…

     

    #187274

    Hi,

    With respect to backtesting, my tests lead me to think that:

    If we input a spread of 16 pips, all market orders are offset by 16/2 = 8 pips. This is consistent with a quoted price halfway between bid and ask prices.

    For limit orders, I think that the logic of the backtesting engine is the following:
    Let’s input again a spread of 16 pips and insert in the strategy a hard-coded limit entry like “buy at 1.12574 limit”
    If the low of the entry candle is <= 1.12574 – 16pips/2, the trade is entered at 1.12574
    If the low of the entry candle is > 1.12574 – 16pips/2, the trade is not entered at all

    Nicolas

    Note : if an EUR/USD strategy uses market orders for entry and exit, a spread of 16 pips could be replaced by a cost of $8/trade (from backtesting engine standpoint).

    #187297

    Hello @Nicolas56,

    Nah … it does not work like that;
    The order is just filled at the price you asked for**.  However, you can regard the position to be in a loss of 16 pips right away, hence you must virtually make 16 pips of profit for this position in order to break even. When exactly these pips are “eaten” is generally not important, although this depends on how you determine the means for making profit and exit (StopLoss the same). It takes a page to give examples, but most important is that you observe this for your situation. And regarding that : use PositionPerf to watch how

    • half of the spread is eaten right when you Entered;
    • the other half is eaten at (after !) the Exit.

    Knowing this, you can work your way to it, at comparing Backtest with Live. Thus, the Backtest (also Forward Test) will show you what I just told, BUT give the system the opportunity to show it (see next sentence), while Live can only be observing what spread the broker claimed for your order (I’d say both on Entry and Exit differently, depending on the rules per volatility – IG has tables for that like for Fx 0.6 or 0.9 or real spread when worse – can be over 2.0).
    If you would work with Set Target %Profit 0.5, you would not notice a thing of anything, because the (broker !) system will take care that you will have 0.5% profit exactly before the position is closed, or the position is not closed at all when this was “just not” reached. However, would you work with Sell nn Shares at Market and you would do that when a certain price is reached, you will see in PositionPerf afterwards that you have less profit than the price(math) told you.

    **) But for a Market order may move because the price moves, so you may receive several prices for partial fillings. See attachment where 3 pieces are split into 2 for 14413.50 and 1 for 14413.25. But this is not related to the subject so count this out please. Still in practice you may run into it, and then it is important knowledge at judging what actually happened.

    Peter

    #187299

    Note : if an EUR/USD strategy uses market orders for entry and exit, a spread of 16 pips could be replaced by a cost of $8/trade (from backtesting engine standpoint).

    Literally I would say that this is not correct;

    In a system / situation as a whole where 16 pips are charged for spread, the commission would be $16 per full trade (in and out). Thus, your said “per trade” is very correct, knowing that $8 is charged at the entry and another $8 is charged at the exit.
    The $16 for the total now compares with your 16 pips spread, knowing that this will be the total claim for in and out together. This relates to my remark in my previous post, “that you don’t care when it is charged”. But in the end you will have to deal with it.

    IMPORTANT :
    I made my usual error of mixing up PositionPerf with StrategyProfit. Thus :

    And regarding that : use PositionPerf to watch how […]

    was blatantly wrong and also shows how it is so easy to make the mistake (for me). PositionPerf does not incorporate the spread, and most certainly also not the commission when in order (like for IB). However, StrategyProfit does incorporate the spread (still not the commission), which is useless when in the middle of a trade for that trade. So it takes a lot of hoopla to show all this to yourself (with Graph) and only the other day I felt understanding it all (which may not be the case for 100% – haha).

    One last kind of side note if not known already : For the time I work with PRT it does not incorporate the commission (for IB) in Demo-“Live”. So your results are way off because your $16 per full trade does not show. Thus your result of 1000 for 100 trades in reality is 16 x 100 = 1600 less and thus the strategy loses.

    And then lastly this, Nicolas : because you mention Forex *and* the example figures, I feel that you doubled all already because of not able to see through correctly (not your fault at all). Thus, general commission with IB for  EUR/USD would be $40+$40 (in + out) while the spread for IG would be 0.6 or 0.9 pips generally for in + out together. At least I calculate with 0.8. For IB it depends on the amount you trade and if you trade more than “average” the commission can easily drop to $30 for a single trade. This is what PRT charges you (and the broker charges PRT).

    #187304

    @random45689

    >> Please update your country flag in your profile. Thank you 🙂 <<

     

Viewing 9 posts - 16 through 24 (of 24 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login