Fill or kill

I am currently trying to implement a trading mechanism. My code can successfully create and fill limit and market orders. Also, I would like my engine to be able to successfully fill Fill or Kill orders. Unfortunately, I have no idea how to write an algorithm for this Fill or Kill. Does anyone know if there is an efficient algorithm for this?

Below are some details about those of you less knowledgeable about trading. The assets acquired are usually arranged in such a way as:

Price      Amount  
$200       3  
$300       4
$350       2.5
$400       1.11

      

If you are looking to buy assets, a simple algorithm goes from top to bottom to give the client the best value. The whole line does not need to be completely purchased. For example, if I want 4 apples, the code will sell me 3 for $ 200 and 1 for $ 300 (going from top to bottom).

Some sellers can now specify a Fill or Kill option. This means that this line cannot be partially purchased. So now let's say the second line is Fill or Kill:

Price           Amount       
$200            3  
$300            4  (Fill or Kill)    
$350            2.5
$400            1.11

      

In this case, if I want 4 apples, I cannot buy less than 4 from the second row. So now I have two obvious options. I can buy 4 apples from the second row for $ 4 * 300 = $ 1200, or I can buy three apples from the first row and 1 from the third for (3 * $ 200) + (1 * 350) = $ 850. Now, in this case, the second option is the best deal. Unfortunately, this will not always be the case depending on different prices and the number of orders.

These tables will be implemented in SQL and ordered by price. I am trying to implement this algorithm in php. Any help would be greatly appreciated.

+3


source to share


4 answers


You can skip the Fill or Kill offer and select the next product. Then repeat with the missing sentence and find the cheapest combination between both solutions.



0


source


The purpose of a Fill or Kill order is for a position to be placed on the market at the desired price. Therefore, the transaction must be immediately and completely or not at all to enter the market. The FOK order prohibits partial filling of the broker. You need to map 1: 1 to the market before the order is placed in the queue / book.

Non-Partial Fill is what distinguishes Fill or Kill (and All or Nothing) orders from Immediate or Cancel orders. IoC orders allow partial fill and wait in the ledger to receive additional stock gradually before the order expires.

The difference between FOK orders and AON orders is that AONs that cannot be completed remain active until they are completed or canceled. AON continues to wait in the book for the full match. FOK is discarded if an immediate full match.


An efficient filling or killing algorithm?

There are two forms: "Multi Fill or Kill" and "Single Fill or Kill".

  • Single Fill or Kill

This is probably the easiest one. This is a 1: 1 match to go to market. If there is no direct match, kill. If you do it with a SQL command, you have WHERE equals comparisons.

Single means: An order will be rejected if it cannot be immediately filled with one order of equal or greater size.

  1. Multi Fill or Kill


This is probably the algorithm you are after.

Multi means: fill in multiple internal orders.

It said that the FOK order prohibits partial filling of the broker. This is only true because the book is ordering the book from outside. Internally, there is an "immediate mutual partial filling" until the order is "filled".

For an incoming FOK order, you create an OrderEventGroup. A connector can have multiple orders sitting on a book that allows an incoming FOK order to be satisfied, but only IF IT IS ADDED TOGETHER. In MatchEvent, the OrderEventGroup command is populated with contra-orders that match the order constraint. You are matching orders in the order book where the quantity / price is lower than or equal to the requested amount and price. You fill OrderEventGroup until FOK.order.amount equals OrderEventGroup.amountTogether. If the OrderEventGroup.amountTogether does not add up at all and / or takes longer than you defined as the "immediate" execution time, then the FOK order will be killed.

You get a single transaction that can have multiple matching steps, possibly with different prices. But this was not reported. The order report contains: "filled" and "price", "qty" - where price is the average price of the OrderEventGroup. The bailiff did not even know that his order was filled with more than one order.

Good thing: eliminating the execution risk for the applicant. The bad thing: you get the average price without prompting for the minimum prices in the OrderEventGroup or the number of opposing orders collected.

  1. Fill and kill

Then "Fill and Kill" appears. The order is filled in a quantity that can be filled immediately at the requested price. The rest of the order is killed / canceled. These orders may end up with a "partially filled" status. The algorithm is the same as for 2., except that FOK.order.amount must not equal OrderEventGroup.amountTogether. OrderEventGroup.amountTogether may be lower (partial filling).


The matching algorithm used is basically the Clean Time (FIFO) algorithm as this algorithm maximizes the number of efficient orders. (Some markets use Pro-Rata mapping. And somewhere between LIFFE and CME algorithms, both combine elements from fifo and pro-rata.)

0


source


There should be a pseudopolynomial dynamic programming solution similar to the knapsack solution. Maintain a spreadsheet giving, for all quantities <= the desired quantity, the lowest possible cost at which that quantity can be purchased. Start with all the entries in the table, set at best, where you can only use regular sentences. Take each fill or layoff proposal in turn and use this to modify the table: the cheapest price for quantity k equals min (previous price for k, previous price for kx plus cost to provide x shares according to the proposal you are currently considering), keep sufficient information about the return,to revert to a mix of offers from the cheapest price for the target quantity after consideration of all fill or slaughter bids. This could be, for example, a note for each quantity offer for which it is part of the cheapest price.

0


source


Firstly, FOK does not sit in the order book. They are like IOC (Immediate or Cancel) and have a time of zero. If they are not met, they will be canceled immediately.

All or No orders that are even less supported and less standard may have end of day TIF or end of day TIF until canceled. In this case, they are not displayed and are executed when they can.

Now with this one of ours, if so, are you trying to obey securities law, or is it just a toy system? FOKs are not standardized Limit, Market or IOC orders. Some objects may not even fulfill them, and some have different definitions if they do.

But, if you are trying to obey RegNMS, you cannot skip the inside of the book to fill it in deeper (trade requirement). I've only ever seen FOK orders filled on NBBO (best rate / offer, inside), but I think I used them right away, just what I remember.

So the algorithm would be simple if there was enough size inside the book, and if so, run against it. If you wanted to be a little softer, you could work on the next level, however, in RegNMS, the location could not do this if the other location also showed size at that level (trading through strikes again). It's kind of a point of order type though, to prevent your buy / sell intent from leaking out.

0


source







All Articles