FastPrepRegression Hedge
Problem · Math

Regression Hedge

HardMillennium logoMillenniumNEW GRADOA

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

  1. Sort returns by period.
  2. Convert the three return columns to IEEE-754 float64.
  3. De-mean each return series independently.
  4. Solve the ordinary least-squares system X beta = y, where y is the de-meaned target return and the two columns of X are the de-meaned hedge returns.
  5. Return hedge quantities -target_quantity * beta in 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

ColumnTypeNullableDescription
periodPKIntegerNo
target_returnDecimalNo
hedge_1_returnDecimalNo
hedge_2_returnDecimalNo

positions

ColumnTypeNullableDescription
config_idPKIntegerNo
target_quantityDecimalNo

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
hedge_1_quantityDecimalNo
hedge_2_quantityDecimalNo

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

Constraints

  • The return history contains between 3 and 2000 rows 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.
  • positions contains exactly one row with config_id = 1.
  • Numeric results are compared with absolute tolerance 0.000001.

More Millennium problems