Order matching engines

Discussion in 'Automated Trading' started by tere, Aug 3, 2020.

  1. tere

    tere

    Hi,

    I would be interested in knowing more about designing order simulation systems.

    I am in the process of building historical market simulator, based on "historical quotes" tick data.
    Also considered using "historical trade" data to sync quotes and orders.
    But at this stage i cant see easy implement use for that feature, will just leave integration option for later times to focus on more critical functionality.
    Overall would it be worth the work and extra computing cost if integrating both trade and quote data for simulation?

    If you have designed something similar, id be thankful on insight.

    I found info on basics of order matching engines types like of FIFO and pro-rata. But it does not help much, as its just peak of the iceberg.

    Lets say first premarket quote of the day is far off from last or next intraday prices....What would happen , will limit orders trigger?

    Where to find info on how do stock market order matching engines work and what data is considered as valid input from quote data?
     
    Last edited: Aug 3, 2020
  2. 2rosy

    2rosy

    simple is to have a list/tree of levels and at each level have list of orders. one of those for buys one for sells. when best buy>= best sell they match
     
    DaveV likes this.
  3. guru

    guru

  4. tere

    tere


    Atm i have API implementation for only NBBO quotes, not full order book history.

    I might understand something wrong here but am i correct to assume in this scenario would need both historical quote book and historical trade data?

    And how could it be determined if remaining quotes would be considered as valid fills in order to simulate more accurately?

    Not that it matter in my case but would filled orders affect price slightly if so how does that work?

    If using only quote data without trade data , how big portion of bid/ask volumes could be considered as valid fills for simulation?
     
    Last edited: Aug 3, 2020
  5. tere

    tere

    Last edited: Aug 3, 2020
  6. 2rosy

    2rosy

    if you only have NBBO then when bid == offer you have a match. not sure if that is ever the case. by definition for NBBO isn't bid always less than offer? I don't think nbbo alone is enough; you need depth of market
     
  7. tere

    tere

    Goal is to do limit order simulation.

    So far i have used NBBO{bid , ask , bid size , ask size} data in simulation.

    Utilizing historical spread and offer sizes at all stages...stop loss , take proft , order entry etc.
    Also for quote sizes offered i can set percentage of fills for simulation.
    For example bid at some price offering 5 shares...
    I put market order for 20 shares.
    And get 2% of 5 lots filled on that tick for example, so it takes many ticks to get fills...

    Price can slip a lot if simulating large market orders.
    Or not getting filled on limit order if price goes against.

    Not sure if this is correct way of doing things or even if my fundamental knowledge is correct.

    Not sure if all used quotes are valid either or can get pulled away before fills by predatory HFT or other forces...
    Or if short price spikes in premarket would trigger SL/TP on trading account.

    Most likely no TP , otherwise it would be high win rate strategy.
    But SL idk...
     
    Last edited: Aug 3, 2020
  8. I don't have time for a proper answer, just wanted to say that you are underestimating how immensely complex it is to simulate everything properly. Think of it, multiple order types, multiple venues, various sources of hidden liquidity etc. Even in the context of a single-listed product like a futures contract, you it's very hard to simulate the queue properly especially if you assume that your own orders/trades influence the structure of the order book.
     
    qlai likes this.
  9. tere

    tere

    Yes , better one would probably require historic order book etc.

    By using quote sizes i mean limiting fills for limit orders, using bid and ask offer size data.
    In short , Do you think using quote sizes gives bit more accuracy to the test?
     
  10. Depends on your order, queue and fill assumptions. For example, if you assume aggressive execution (buying at ask, selling for bid), you can semi-safely assume that you will get some fraction of the size at the touch and can vary that fraction based on how conservative you want to be. Alternatively, if you assume passive orders but only simulate fill on trade-through (equivalent to always starting at the back of the queue; e.g if you are selling, you assume that you are filled only when ask becomes bid), you can assume that you are getting your full size.
     
    #10     Aug 5, 2020
    eternaldelight likes this.