# Smart Order Routing & Execution Algorithms

### What is the Blockhouse SOR?

The Blockhouse smart order router (SOR) is a dynamic algorithm that places and routes orders to multiple venues. It considers the market environment in real-time to calculate the split of limit/market orders, and decides to which venues they should be routed.

The SOR has excellent performance in any market condition due to its cost function minimization structure. After receiving multiple features from market data, it determines the optimal split of orders by computing which split has the lowest cost relative to the mid-price. As the market naturally shifts over time, the SOR incorporates those new values as an input so that the output always maps to the current market state.

### How do I use the SOR?

The SOR relies on real-time or historical order book (MBP) data. When pushing your own data through the SDK, include the following columns for each venue:

* `timestamp` (UTC): Each event’s timestamp.
* `best_bid`, `best_ask`: The top-of-book prices.
* `bid_sz_00`, `ask_sz_00`: The size at the best bid/ask.
* `price`, `size`: The order price and quantity.
* `action` : The event action. It can be **A**dd, **C**ancel, **M**odify, clea**R** book, **T**rade, or **F**ill.
* `side` : The side that initiates the event. It can be **A**sk for the sell aggressor in a trade, **B**id for the buy aggressor in a trade, or **N**one where no side is specified by the original trade or the record was not a trade.



To run the algorithm with the data you provided:

1. Choose parameters to run the optimization:

* `target_time` (string): The time you want to submit the orders at, formatted using ISO 8601. If the time is not valid, you will receive an error message.
* `S` (integer): The total number of shares you want to trade.
* `T` (integer): The time allotted to trade all of S.

2. Run the optimization:

```
X_star, V_star = run_optimization_facade(
   target_time='2024-10-21 12:05:45 UTC',
   S=2000,
   T=1
)
```

3. Receive the optimal execution!&#x20;

* X\_star will come as a list of values, where the first value (0th-index) represents the number of market orders to place, and the following numbers (1st -> Nth index) represent the number of limit orders to place at each of the N venues.&#x20;
* V\_star is the cost of placing all orders shown in X\_star, shown in bps / $1 Million relative to the NBBO mid-quote.



### How do I evaluate the performance of my trades?

After running the SOR algorithm in the previous step, we generate metrics to benchmark your trade’s performance.

* Slippage: The difference between the expected price of a trade and the actual price at which the trade is executed.
* Fill Rate: The percentage of your total requested size (S) that executed. A low fill rate may mean your limit orders were too strict.
* Hit Rate: The percentage of orders executed at or better than the National Best Bid and Offer (NBBO).
* Latency: Time from when you placed the order to when it was filled.
* Spread & Fees: Summaries of what effective spread you paid and how much in fees or rebates you incurred.
* Markouts: How much the price moved right after your trade – a sign of potential adverse selection.
* Queue Depth Efficiency: A measure of the fill rate stratified by queue size.
* Risk-Adjusted Performance: A measure of slippage stratified by market condition.
* Naive Strategy Comparison: A comparison of Blockhouse SOR slippage to that of traditional naive strategies. This serves as a reference case for Blockhouse performance.
* Price Impact: The change in an asset's mid-price as a direct result of your trading.

To see more detail on this, reference the [Post-trade dashboard section](../visualizing-trade-insights-pre-and-post-trade-dashboards#post-trade).
