Problem · Database

Hedge Inventory with Return Covariance

HardMillennium logoMillenniumNEW GRADINTERNOA

Problem statement

A desk holds inventory in three assets and may add hedge quantities only in assets marked as liquid. Estimate return risk from the time-sorted price history, solve the ridge-regularized hedge, and report the remaining portfolio variance.

Risk model

  1. Sort prices by period. Convert the price columns to IEEE-754 float64, then compute consecutive simple returns current_price / previous_price - 1.
  2. Build the sample covariance matrix Sigma of those return rows, using denominator return_count - 1.
  3. Sort portfolio by asset_order; rows must align with asset_1, asset_2, and asset_3. Convert the quantities to float64.
  4. Let q be the inventory vector and L the indices marked is_liquid. Solve (Sigma_LL + ridge * I) * h_L = -Sigma_LA * q in float64. Set hedge quantities outside L to 0.
  5. Let r = q + h. Compute residual variance as r^T * Sigma * r.

Return exactly one row containing the three hedge quantities in price-column order and the residual variance.

Table schema

Pandas

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.

prices

ColumnTypeNullableDescription
periodPKIntegerNo
asset_1DecimalNo
asset_2DecimalNo
asset_3DecimalNo

portfolio

ColumnTypeNullableDescription
asset_orderPKIntegerNo
assetTextNo
quantityDecimalNo
is_liquidBooleanNo

parameters

ColumnTypeNullableDescription
config_idPKIntegerNo
ridgeDecimalNo

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
asset_1_hedgeDecimalNo
asset_2_hedgeDecimalNo
asset_3_hedgeDecimalNo
residual_varianceDecimalNo

Row order: must match exactly. Numeric tolerance: 0.000001.

Constraints

  • 3 <= prices.row_count <= 2000, and periods are unique.
  • Every price is an exact decimal in [1, 1000000] with at most 6 fractional digits. After sorting by period, every consecutive price ratio for the same asset lies in [0.9, 1.1].
  • portfolio contains exactly three rows with unique orders 1, 2, and 3 and matching asset names asset_1, asset_2, and asset_3.
  • Every portfolio quantity is in [-1000, 1000] with at most 6 fractional digits, and at least one portfolio row has is_liquid = true.
  • parameters contains exactly one row with 0.0001 <= ridge <= 1.
  • The ratio and ridge bounds keep each return in [-0.1, 0.1] and the ridge-regularized liquid system symmetric positive definite with 2-norm condition number at most 601.
  • The return covariance and every reported value are finite.
  • Numeric results are compared with absolute tolerance 0.000001.

More Millennium problems