Problem · Database

Hedges Outperforming Their Trades

EasyWolverine Trading logoWolverine TradingINTERNNEW GRADOA

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

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.

wolve_trades

One row per option trade.

ColumnTypeNullableDescription
trade_idPKIntegerNoUnique trade identifier.
symbolTextNoTicker symbol.
trade_qtyIntegerNoTrade quantity.
trade_pnlIntegerNoTrade profit and loss.
option_typeTextNoOption type.

wolve_hedges

At most one optional hedge row per option trade.

ColumnTypeNullableDescription
trade_idPKIntegerNoIdentifier of the hedged trade.
hedge_pnlIntegerYesHedge profit and loss.

Foreign key: trade_id wolve_trades(trade_id)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
Trade_idIntegerNo

Row order: any order is accepted. Numeric tolerance: 0.

Constraints

  • wolve_trades.trade_id is unique.
  • For this exercise, assume each trade has at most one matching row in wolve_hedges, identified by the same trade_id.
  • Every hedge row references an existing trade.
  • For this exercise, assume trade_pnl is never NULL, while hedge_pnl may be NULL.

More Wolverine Trading problems