Trade and Hedge Totals by Symbol
Problem statement
Two tables describe option trades and their optional risk-offsetting hedges:
wolve_tradescontains each trade's identifier, symbol, quantity, profit or loss, and option type.wolve_hedgescontains the optional hedge associated with a trade.
Return one row for every distinct symbol in wolve_trades. For each symbol, calculate the sums of trade_qty, trade_pnl, hedge_qty, and hedge_pnl.
Treat a missing hedge row or any NULL quantity or PnL value as 0.
Return exactly these columns, in this order: symbol, total_trade_qty, total_trade_pnl, total_hedge_qty, and total_hedge_pnl. Result rows may appear in any order.
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 | Yes | Trade quantity. |
| trade_pnl | Integer | Yes | 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_qty | Integer | Yes | Hedge quantity. |
| 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 |
|---|---|---|---|
| symbol | Text | No | — |
| total_trade_qty | Integer | No | — |
| total_trade_pnl | Integer | No | — |
| total_hedge_qty | Integer | No | — |
| total_hedge_pnl | Integer | No | — |
Row order: any order is accepted. Numeric tolerance: 0.
Constraints
wolve_trades.trade_idis unique.- For this exercise, assume
wolve_hedges.trade_idreferenceswolve_trades.trade_id, and each trade has at most one hedge row. - For this exercise, assume the output contains every distinct non-NULL symbol in
wolve_trades, including symbols whose trades have no matching hedge rows. - For this exercise, assume result rows may be returned in any order.
- For this exercise, assume quantity and PnL fields are nullable signed 64-bit integers and every required aggregate fits a signed 64-bit integer.