[Test] mode: Simulate both market *and* limit orders

Posted By: AndrewAMD

[Test] mode: Simulate both market *and* limit orders - 07/05/22 13:59

This much is obvious:

1) To simulate market orders, you need bid and ask. Your order fills at an unfavorable price.

2) To simulate limit orders, you need tick data. Your order may fill at a favorable price... or it won't fill at all.

But how do you realistically simulate both simultaneously? It sounds like you need both bid-ask and tick data, so there would be multiple datasets loaded per asset, correct?

Example scenario: I patiently open a limit order at 4pm. It's now 4:29pm and the order did not fill yet. I become impatient because the market closes at 4:30pm and convert the order into a market order.
Posted By: jcl

Re: [Test] mode: Simulate both market *and* limit orders - 07/05/22 14:59

The .t1 and .t2 formats support ask and bid. You need normally only a single dataset. Set Spread = marketVal() at any tick for a realistic simulation.
Posted By: AndrewAMD

Re: [Test] mode: Simulate both market *and* limit orders - 07/05/22 15:44

Sorry, I was unclear. Yes, *.t1 and *.t2 support bid and ask, but what if I want to account for trade ticks on top of that?

This way, trade ticks are specifically used for simulating limit order fills and bid/ask ticks are specifically used for simulating market order fills.
Posted By: jcl

Re: [Test] mode: Simulate both market *and* limit orders - 07/06/22 06:36

In that case you use indeed a second dataset, get the trade ticks with dataset functions, and simulate order fill by script. But why do you need trade ticks at all? Order filling is caused by ask and bid, not by trade ticks.
Posted By: AndrewAMD

Re: [Test] mode: Simulate both market *and* limit orders - 07/06/22 12:51

Originally Posted by jcl
But why do you need trade ticks at all? Order filling is caused by ask and bid, not by trade ticks.
Are you sure? Bid and ask price are market prices and are therefore relevant to market orders. But sometimes, when a trader has a buy limit order around bid price, another trader will sell at market, filling the limit order to the buyer's advantage. It is difficult to realistically simulate these kinds of fills without trade ticks.

This is also why IB offers Midprice, Pegged-to-Midpoint, Pegged-to-Primary, etc. orders, because there are people on the opposite end of the trade who will fill these orders.

I have a client that wants to trade better-than-market prices by placing limit orders somewhere between bid and ask.
Posted By: jcl

Re: [Test] mode: Simulate both market *and* limit orders - 07/06/22 14:27

When a trader places a market order, it is filled from the top of the order book. A limit order is filled when an order book entry matches the limit. In both cases the trades are filled at an ask or bid price from the book. In my opinion, ask and bid are sufficient for limit order simulation.
Posted By: MegaTanker

Re: [Test] mode: Simulate both market *and* limit orders - 07/06/22 14:46

Originally Posted by jcl
A limit order is filled when an order book entry matches the limit.


They're also filled when your limit order is on the top of the order book and someone places a market order, thereby taking your order from the book. These market orders never make it to the order book, no?

I think using ask/bid data is close enough for simulation but this data usually doesn't have size attached to it (but from some sources it might) whereas trades data tends to have the trade size attached, therefore you can accurately simulate how much of your order would be filled.
Posted By: AndrewAMD

Re: [Test] mode: Simulate both market *and* limit orders - 07/06/22 14:47

Question: How does Zorro simulate this order? When does it fill, and at what price?

Buy order, one lot, Entry = -1000.0 (i.e., entry limit is 1000.0). (This is to simulate a limit buy order at 1000.0.)

Scenario A) Bid = 999.0, Ask = 1001.0
Scenario B) Bid = 1000.0, Ask = 1002.0
Scenario C) Bid = 1000.1, Ask = 1002.1
Scenario D) Bid = 998.0, Ask = 1000.0
Scenario E) Bid = 997.9, Ask = 999.9
Posted By: jcl

Re: [Test] mode: Simulate both market *and* limit orders - 07/06/22 15:09

Megatanker: Yes they do. Not the market order, but the other side of the trade was in the order book.

Andrew: D at 1000
Posted By: jcl

Re: [Test] mode: Simulate both market *and* limit orders - 07/06/22 15:18

When I think about it, there is a situation where a trade does indeed not appear in the order book: When the book is completely empty and a market buy and sell order appear at the same time. But I think this is a very unlikely scenario.
Posted By: MegaTanker

Re: [Test] mode: Simulate both market *and* limit orders - 07/06/22 16:11

What about the following:

The tick data shows current best bid at 1000 and best ask at 1001. Someone places a market buy, thereby buying for 1001 at ask but the 1001 ask has size remaining, this event doesn't get recorded in tick bid/ask data at all (unless size is included). But if you want to simulate whether your limit sell order at 1000.5 would have been filled, the tick data would say no, because it's above the best bid and remained there, but the market buy order would have indeed filled your order because at 1000.5 it would have been the best price for the buyer, better than 1001. The trades data would reflect this by showing there was a trade that you could have received instead. Am I missing something?
Posted By: jcl

Re: [Test] mode: Simulate both market *and* limit orders - 07/06/22 18:55

You need t2 ask/bid data for simulating partial fills at different sizes. Trade ticks won't do.
© 2024 lite-C Forums