Question: Slippage is the difference in price between the execution price of an order and the price it was meant to execute at, which is normally the order arrival price (the price at the time the order is received). An example of this would be a broker sending out a client order to buy a security at the current market price, and it being filled at a higher price due to the price movement in that time. This can occur when there is high volatility or rapid movement in the market, or when large orders acquire all the liquidity available at the best price and penetrate through different price levels. We will be looking at the first case. Let's say for our given system, whenever an order is received it is sent out immediately to the market as a Market Order, and this process + order execution takes 1 second. In other words, the order executes 1 second after being received. The order received time is represented by the 'time' column. Using the order table, quote table, and lag below, create two new columns in the order table: 'slippage_bps' and 'slippage_abs'. The 'slippage_bps' column is slippage in terms of basis points difference of the expected price with the following formula: 10000 * (actual execution price - expected execution price) % expected execution price. The 'slippage_abs' column is slippage in terms of dollar amount with the following formula: (actual execution price - expected execution price) * quantity. The slippage should be positive if slippage is favorable (buy at a lower ask, sell at a higher bid), otherwise negative (buy at a higher ask, sell at a lower bid). Assume there is enough market volume at the bid/ask to accomodate these orders (that's why bid/ask size are excluded).

More Information:


order:([]time:10:00 10:00:00.001n;sym:`AAPL;side:`buy`sell;quantity:300 600)
quote:([]time:10:00 10:00:00.1n;sym:2#`AAPL;bid_price:351.73 351.65;ask_price:352.43 352.01)

/ construct your table

time                 sym  side quantity slippage_bps slippage_abs
0D10:00:00.000000000 AAPL buy  300      11.91726     126
0D10:00:00.001000000 AAPL sell 600      -2.274472    -48


finance math tables
Searchable Tags
algorithms api architecture asynchronous c csv data structures dictionaries disk feedhandler finance functions ingestion ipc iterators machine learning math multithreading optimizations realtime shared library sql statistics streaming strings tables temporal utility websockets