Problem · Math
Regression Hedge
Problem statement
A portfolio holds target_quantity units of a target asset and can hedge with two other assets. Estimate a regression hedge from the supplied return history.
Calculation
- Sort
returnsbyperiod. - Convert the three return columns to IEEE-754
float64. - De-mean each return series independently.
- Solve the ordinary least-squares system
X beta = y, whereyis the de-meaned target return and the two columns ofXare the de-meaned hedge returns. - Return hedge quantities
-target_quantity * betain hedge-column order.
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.
returns
| Column | Type | Nullable | Description |
|---|---|---|---|
| periodPK | Integer | No | — |
| target_return | Decimal | No | — |
| hedge_1_return | Decimal | No | — |
| hedge_2_return | Decimal | No | — |
positions
| Column | Type | Nullable | Description |
|---|---|---|---|
| config_idPK | Integer | No | — |
| target_quantity | Decimal | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| hedge_1_quantity | Decimal | No | — |
| hedge_2_quantity | Decimal | No | — |
Row order: must match exactly. Numeric tolerance: 0.000001.
Constraints
- The return history contains between
3and2000rows with unique periods. - Every return and the target quantity is a finite exact decimal in
[-1000, 1000]. - After de-meaning, the two hedge-return columns have full column rank.
positionscontains exactly one row withconfig_id = 1.- Numeric results are compared with absolute tolerance
0.000001.