Hedge Inventory with Return Covariance
Updated
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
- Sort
pricesbyperiod. Convert the price columns to IEEE-754float64, then compute consecutive simple returnscurrent_price / previous_price - 1. - Build the sample covariance matrix
Sigmaof those return rows, using denominatorreturn_count - 1. - Sort
portfoliobyasset_order; rows must align withasset_1,asset_2, andasset_3. Convert the quantities tofloat64. - Let
qbe the inventory vector andLthe indices markedis_liquid. Solve(Sigma_LL + ridge * I) * h_L = -Sigma_LA * qinfloat64. Set hedge quantities outsideLto0. - Let
r = q + h. Compute residual variance asr^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
| Column | Type | Nullable | Description |
|---|---|---|---|
| periodPK | Integer | No | — |
| asset_1 | Decimal | No | — |
| asset_2 | Decimal | No | — |
| asset_3 | Decimal | No | — |
portfolio
| Column | Type | Nullable | Description |
|---|---|---|---|
| asset_orderPK | Integer | No | — |
| asset | Text | No | — |
| quantity | Decimal | No | — |
| is_liquid | Boolean | No | — |
parameters
| Column | Type | Nullable | Description |
|---|---|---|---|
| config_idPK | Integer | No | — |
| ridge | Decimal | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| asset_1_hedge | Decimal | No | — |
| asset_2_hedge | Decimal | No | — |
| asset_3_hedge | Decimal | No | — |
| residual_variance | Decimal | No | — |
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 most6fractional digits. After sorting by period, every consecutive price ratio for the same asset lies in[0.9, 1.1]. portfoliocontains exactly three rows with unique orders1,2, and3and matching asset namesasset_1,asset_2, andasset_3.- Every portfolio quantity is in
[-1000, 1000]with at most6fractional digits, and at least one portfolio row hasis_liquid = true. parameterscontains exactly one row with0.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 most601. - The return covariance and every reported value are finite.
- Numeric results are compared with absolute tolerance
0.000001.
More Millennium Online Assessment questions
- Calculate the Half SpreadOA · Seen Sep 2026
- Debug the Impact ModelOA · Seen Sep 2026
- Debug the Risk-Limit QuoterOA · Seen Sep 2026
- Quote One RequestOA · Seen Sep 2026
- Risk Limits and Inventory SkewOA · Seen Sep 2026
- Track the Book and Mark Final PnLOA · Seen Sep 2026
- Clean the TapeOA · Seen Sep 2026
- Client Markout AnalysisOA · Seen Sep 2026
- Debug Fair-Value LookupOA · Seen Sep 2026
- Debug the Tape CleanerOA · Seen Sep 2026
Similar questions at other companies
- Balance a Chemical EquationMicrosoft · OAMicrosoft interview questions
- Daily Temperature By TownTwo Sigma · OATwo Sigma interview questions
- Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
- Solve a Two-Variable Linear ODEAdobe · OAAdobe interview questions
- The Three Knights 🎠TikTok · OATikTok interview questions
- Survey Table: Group Given an AnswerSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Summarize Taxi Drivers and RidesBoston Consulting Group · OABoston Consulting Group interview questions
- Gaussian Naive Bayes Classifier (Machine Learning OA)Pinterest · OAPinterest interview questions
- Squared Frobenius Norm of a Reflect-and-Stretch MapWalleye Capital · OA
- Scaled Dot-Product AttentionMeshy · OA