Problem · Database
Client Markout Analysis
Problem statement
The trades table contains completed client trades and the corresponding mid-price at a fixed future measurement horizon. Calculate each client's average markout and identify clients whose flow lost money for the desk on average.
Markout convention
BUYmeans the client bought and the desk sold, so desk markout isfill_price - future_mid_price.SELLmeans the client sold and the desk bought, so desk markout isfuture_mid_price - fill_price.
For each client, return the trade count, the unweighted arithmetic mean of per-trade markout, and is_invalid = true exactly when that mean is negative.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
trades
| Column | Type | Nullable | Description |
|---|---|---|---|
| trade_idPK | Integer | No | — |
| client_id | Text | No | — |
| side | Text | No | — |
| fill_price | Decimal | No | — |
| future_mid_price | Decimal | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| client_id | Text | No | — |
| trade_count | Integer | No | — |
| mean_markout | Decimal | No | — |
| is_invalid | Boolean | No | — |
Row order: must match exactly. Numeric tolerance: 0.000001.
Constraints
- The table contains between
1and2000trades. trade_idvalues are unique, andsideis exactlyBUYorSELL.- The future mid-price is prejoined at the desk's fixed evaluation horizon; both prices are non-null positive exact decimals.
- Use an unweighted mean: every trade contributes once regardless of client, asset, or notional.
- A zero mean is valid and must not be flagged.
- Return one row per client in ascending
client_idorder. Numeric results are compared with absolute tolerance0.000001.