Trading Simulator - what to do with non-fillable orders?

Quote from NetTecture:

Now guess why I came here and asked ;)

The rest is a beginner programmer training in programming, but this stupid edge case...

As I said, you could model it using some kind of randomness - based on statistical data you've previously gathered for how your orders were filled in the past (in the edge case scenarios).

Or, make your strategy more conservative - don't send orders larger than what the book is showing....except if your strategy depends on this feature.
 
Quote from NetTecture:

No an option if:

* YOu have a position in the market
* You backtest.

You have to build in triggers in your strategy that detect outlier events and deal with them as best as you can i.e getting flat/emergency hedging.

If you have a position in the market that you can't get out of - perhaps it will make you a lot of money :D

I don't think anyone will be able to give you a simple answer.
 
there are two types of orders... Marketable and non-marketable. Don't submit (or cancel) non-marketable orders.

For Example a marketable limit order could be offering out 10c BELOW the bid.


A good rule of thumb for initial testing is to wait until the stock trades through your price by a penny. This will assure you got filled and offer enough of a pecimistic approach to make it realistic.
 
To expand on this a little more - in an ATS you should never be submitting simple "Market" orders. You should be submitting marketable or non-marketable limit orders only (for example bidding cheap waiting for a big sweep down in the book {that you think will revert back to previous levels} is a non-marketable limit order).

Have your system (especially in SIM) bid or offer with limit orders at a specific size & price. If the security trades through your price by a penny (if you are offering at $35.00 and the stock trades $35.01 you know your entire lot @ $35 would have been filled because you were either willing to sell cheaper than $35 or someone would always want to buy a penny cheaper).

In real life most simulations are much more optimistic than trading actual shares/money. If you find something that works as I described above you will find it will perform about the same with money behind it (possibly better). This is when you can start to compare - run side-by-side simulation and real money once you get a strategy working and compare the numbers and fills until you know how much to adjust your simulation results.
 
Quote from NetTecture:

I am writing the backend of a back tester these days. Tick by tick etc. blablabla ;) Anyhow, my problem is:

How would you deal with non fillable orders?

Basically, when an order is triggered I an generate fills according to the book (bids, asks).

My problem comes along when the book is not available and / or too small to accommodate the values. This can be because I do not have order book (only best bid/ask) in a tight market, or in general because the market IS tight (overnight, crazy market situation). Actually - it is a lot more relevant during night trading etc.

I do not want to keep those orders all around, and for a market order that would not be valid. Those are particularly very fancy times anyway (flash crash) and I want to actually make this somehow visible in a possibly run.

What would be your suggest way of handling those orders? Cancel them after filling what can be filled (and sending a cancel to the strategy, obviously), plus a logging message that can go into the backtest results?

I also consider a log message / info attachment to an execution to state how much of the order book was used to create the data. This normally should not be more than single digit percetnage, but a number higher than 100 would indicate the order was larger than the book, prompting an error in the backtest?

Asking for opinions here ;)

Also, how would you handle limit order queueing? My idea is that I track the queue location for every order, and decrease that
* On every trade at the price, by trade volume.
* When the book moves away in my favour, I assume I got all fills there.

The main problem is tracking queue position when out of the book - so I assume I just end up at the end always ;)?

Example -

Order book's: bid 1000 lots @ $10.00 / $10.01 @ 500 lots ask

That's the whole book. Nothing else above/below.

Your order is to BUY 2000 lots @ $10.03.

Result is a partial fill: 500 lots @ $10.01

Your unfilled 1500 lots is the new bid. Ask is empty.

Book looks like: 1500 lots @ $10.03 / $0.00 @ 0 lots.

The original bid is below you.

---

If you want to make the simulation more complex, add all the price layers.

Edit: WinstonTJ, +1.
 
Quote from WinstonTJ:

...
Have your system (especially in SIM) bid or offer with limit orders at a specific size & price. If the security trades through your price by a penny (if you are offering at $35.00 and the stock trades $35.01 you know your entire lot @ $35 would have been filled because you were either willing to sell cheaper than $35 or someone would always want to buy a penny cheaper).
...
* Unless they are smaller than you. :D
 
There is no way to predict market reaction to simulated orders when back test tick data has no volume change. Try:

#1. Market Price must go through your order price and trade volume must support order size to simulate a fill.

#2. Use volume as your fill trigger for sizing. ie. price must go through and traded volume > simulated order size x 2. If volume is < order size record a partial fill of 1/2 volume traded. rinse and repeat...

#3. For limit orders depending on your order staging rules you may be able to use a combination of price touch and % of traded volume to simulate fills.

#4. Add your processing and execution latency into your sim calculations if your using message accurate tick data. ie. if your system takes 50ms to receive and process ticks. Adjust your back test data to 50ms samples discarding all messages in between as in-actionable.

#5: Use the leading tick for calculating results on simulated resting orders (stops, limits etc). Post results and process action triggers in the following message/tick to simulate lag. ie. cancels, new orders.

#6. Key Fields are Bid, Ask BidSize, AskSize, last price and total traded volume. Cut new records on any change to bid/ask/last and calculate the volume differential. This way you can gauge what side is being hit and calculate accordingly.

#7. Thin markets... illiquid options... Heavily quoted without volume. The above should filter these automatically. Fast markets and spikes may be handled by order staging rules. ie. Price must hit X in an orderly fashion before Resting order is submitted.
 
Quote from Rationalize:

* Unless they are smaller than you. :D

Not really - it won't trade through you unless there is size to fill your order. It can't***


***It can technically however with price improvement and inter-exchange arbs someone will usually pick you up before it prints higher elsewhere.

Let's say I'm looking to buy GOOG at $600.00 so I place a GTC bid to buy 1,000,000 shares (yeah one million) at $600.00.

Why would GOOG trade $599 before my lot is filled?

Conversely, if I'm offering 1,000,000 shares of GOOG at $625 (offering out to sell short) why would it trade through to $626 before my lot is filled?

In both cases anyone buying would want the lower price and anyone selling would be above the NBO and outside the market.
 
Quote from WinstonTJ:

Not really - it won't trade through you unless there is size to fill your order. It can't***


***It can technically however with price improvement and inter-exchange arbs someone will usually pick you up before it prints higher elsewhere.

Let's say I'm looking to buy GOOG at $600.00 so I place a GTC bid to buy 1,000,000 shares (yeah one million) at $600.00.

Why would GOOG trade $599 before my lot is filled?

Conversely, if I'm offering 1,000,000 shares of GOOG at $625 (offering out to sell short) why would it trade through to $626 before my lot is filled?

In both cases anyone buying would want the lower price and anyone selling would be above the NBO and outside the market.

Just saying the order that crossed the spread and consumed whatever's in front of you may not be big enough to fill you entirely. So seeing price trade through your price in historical data may not imply you would have been filled entirely.

"Let's say I'm looking to buy GOOG at $600.00 so I place a GTC bid to buy 1,000,000 shares (yeah one million) at $600.00.

Why would GOOG trade $599 before my lot is filled?"

It wouldn't. But your big-ass bid size might stop price from getting down to 599.

I'm sure you know this .. but, it's hard to accurately test multi-lot liquidity providing strategies.

1 lots crossing the spread .. easy.
 
Using 1M shares for size was a bit over the top.

Is OP trading futures? I didn't pick up on that and I don't know the first thing about futures markets.

The message I was trying to relay to the OP is that if he assumes a fill at his target price when the price trades through his order by a penny, two pennies, etc. then he'll be able to assume a reasonable fill rate.

I think we are saying the same thing except I don't know anything about how futures trade.
 
Back
Top