What is it?
Transaction costs 'are expenses incurred when buying or selling a good or service, outside the cost of the good or service itself.' Knowing when to buy and sell is only part of the problem for traders - transaction costs can nullify the profit made on a trade. In many institutions there are teams of quants whose job it is to ensure each trade gets filled at the best possible price, and Transaction Cost Analysis allows them to evaluate their performance. Additionally, recent financial regulations have forced companies to document this information, so they can prove that they have given their clients the best possible price (Best Execution).
Generally when talking about transaction cost analysis on trades at an institutional level we are less concerned with the literal 'cost' of the trade i.e. the fees on the transaction or the cost to employ the people involved in making the transaction. Instead we are concerned with the 'what-ifs' - What if I had placed this trade 1 minute later? What if my order had been fully filled immediately? What if I had split this order up into smaller chunks? How you place the order can affect what price you get - the change in price as a result of your order is called market impact.
Orders and executions on an item will have an impact on the price of that item. Imagine a fruit market with four stalls selling 10 apples each. The respective per apple price at each stall is 10c, 11c, 13c and 14c. A buyer walks into the market and approaches the 10c stall and purchases all of the apples available at the price advertised. He then moves to the 11c stall and does the same. He then moves to the 13c stall and does the same. Seeing this, what is the owner of the 14c stall likely to do? Of course they will put their prices up. Let's say they increase the price per apple to 16c. As expected, the buyer comes along and buys all of the apples at the advertised price. The buyer's final average price per apple is 12.5c, whereas had the price increase not occurred it would be 12c.
The buyer's actions have resulted in market impact and his final price was higher than the average market price when he arrived with the intention of buying 40 apples. So what could he have done? He could have sent four separate buyers to each stall to buy 10 apples (split the order), he could have bought 20 apples at the market and 20 at the supermarket (smart order routing), he could have bought a portion of the apples online (dark pools) or he could have waited until the end of the day when, on average, prices are lower.
To measure the impact on the price we can compare the price the buyer received to the price at the time of his arrival - an 'ideal' price (in this case a kind of arrival price). This 'ideal' price is usually referred to as the 'benchmark' and deviation from it referred to as 'slippage'. Once we have these values we can use them to rate the performance of the trade, in other words we can use them as a benchmark to compare the trade against.
How would we do this in kdb+/q? Let's try it out.
For the below we are going to need three tables: orders, trades and executions. The executions should be linked to the orders by OrderID.
Th
Basic TCA - Arrival Price
Reversion
Reversion TCA analysis gives us an indication of where the price of the stock went after our trade was placed.
Let's pick 4 time intervals and calculate the difference between the trade price and the market mid price at that time: -1m, 1m, 3m, 5m
Assume 'trade' and 'quote' tables already exist in the HDB.
VWAP
TWAP
PWP
Considerations:
Which benchmarks will be used and how should we calculate them?
TWAP, VWAP, Arrival, PWP, etc
How do we determine the performance of an order that has multiple executions?
How will we handle open auctions, close auctions, etc.
How to actually do it: start with your fills and join any necessary cols from other tables