Hedges Outperforming Their Trades
Problem statement
Two tables describe option trades and their optional hedges. Each row in wolve_trades contains a trade's profit and loss, and a matching row in wolve_hedges contains the hedge profit and loss.
Return the trade_id values for trades whose hedge PnL is strictly greater than the trade PnL. If a trade has no hedge row or its hedge_pnl is NULL, use 0 as its hedge PnL.
The result must contain one column named Trade_id. Row order does not matter.
Table schema
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.
wolve_trades
One row per option trade.
| Column | Type | Nullable | Description |
|---|---|---|---|
| trade_idPK | Integer | No | Unique trade identifier. |
| symbol | Text | No | Ticker symbol. |
| trade_qty | Integer | No | Trade quantity. |
| trade_pnl | Integer | No | Trade profit and loss. |
| option_type | Text | No | Option type. |
wolve_hedges
At most one optional hedge row per option trade.
| Column | Type | Nullable | Description |
|---|---|---|---|
| trade_idPK | Integer | No | Identifier of the hedged trade. |
| hedge_pnl | Integer | Yes | Hedge profit and loss. |
Foreign key: trade_id → wolve_trades(trade_id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| Trade_id | Integer | No | — |
Row order: any order is accepted. Numeric tolerance: 0.
Constraints
wolve_trades.trade_idis unique.- For this exercise, assume each trade has at most one matching row in
wolve_hedges, identified by the sametrade_id. - Every hedge row references an existing trade.
- For this exercise, assume
trade_pnlis neverNULL, whilehedge_pnlmay beNULL.