# Factor regression: a prompt from hedgefund.md

Paste this into your AI agent. It needs no connection to hedgefund.md. An agent that can run code should write and run it, and shouldn't work a long series by hand.

**Question.** After the factors, how much of this return stream is left, and can that intercept be told apart from zero?

## Method

y_t = a + sum b_j x_jt + e_t, by the normal equations on centered, scaled factors. s^2 = RSS / (n - k - 1). Var(b) = s^2 (X'X)^-1. Var(a) = s^2 / n + xbar' Var(b) xbar. R^2 = 1 - RSS / TSS. Adjusted R^2 = 1 - (1 - R^2)(n - 1) / (n - k - 1). DW = sum (e_t - e_t-1)^2 / RSS.

## Conventions

- Annualizing is simple: intercept times periods_per_year, residual vol times the square root of periods_per_year.
- A t-stat doesn't change when the intercept is annualized, because the standard error scales with it.
- Standard errors are the classical ones: independent residuals with one variance.
- Thin means fewer than 10 observations per factor. The intercept isn't counted as a factor.
- Collinear means a factor's R squared on the factors before it is above 1 - 1e-10.
- A mean under 1e-12 of the largest return is rounding, so it reads as zero and has no shares.
- Both the series and the factors are taken as sent, with no excess-return adjustment.

## Step 1: check your method on these made-up numbers

The numbers and names below are made up. They aren't market levels, typical values or anyone's real figures.

```json
{
  "returns_pct": [
    2.26, -2.73, -6.84, -0.96, -0.94, 1.51, 0.79, -3.29, 0.74, 4.22,
    1.14, 0.79, 1.64, 3.65, 1.9, -2.27, 3.89, 1.22, 1.86, 4.2,
    5.94, -1.19, 4.04, 1.5, -0.32, 3.76, 1.19, 1.88, -1.62, 8.44,
    -5.48, -1.43, 2.55, -6.1, 1.01, 5.14, 0, 5.84, -6.17, 5.03,
    -0.1, 2.16, 0.76, 1.76, 2.87, 1.43, 2.58, 2.25, -0.89, -0.94,
    -3.84, -0.21, -0.16, 4.31, 0.29, -1.73, 0.02, -3.21, 1.87, -0.15
  ],
  "factors": [
    {
      "name": "Market",
      "returns_pct": [
        1.83, -3.89, -4.14, -0.61, -0.41, 1.85, -2.03, -5.63, -0.58, 4.06,
        0.23, 2.9, 3.52, 6.22, -1.58, -0.51, 4.9, 0.08, 2.8, 4.4,
        7.34, -1.73, 3.06, -0.23, -0.39, 6.35, 3.4, -0.4, -0.72, 11.32,
        -6.12, -2.09, 4.53, -5.66, 1.26, 4.4, -0.86, 6.6, -7.2, 4.85,
        3.05, 1.23, 1.69, 0.47, 3.1, 1.98, 2.83, 2.7, -2.35, -1.17,
        -4.24, 0.54, -1.72, 5.07, -0.45, 2.44, 1.29, -5.27, -0.43, -5.14
      ]
    },
    {
      "name": "Value",
      "returns_pct": [
        2.52, 2.35, -4.46, -1.08, -1.39, -0.28, 0.35, -1.25, -1.49, 0.47,
        1.79, -1.21, -1.27, -0.67, 1.02, 0.23, 2.32, 2.72, 1.07, 4.66,
        -0.99, -1.01, 1.03, -1.42, 0.14, -3.82, -0.46, 1.41, -2.48, -0.59,
        -0.23, -0.31, -1.07, -1.71, 0.06, -3.23, -1.87, -0.03, -1.9, 1.04,
        -3.99, 2.52, -1.33, -1.08, 1.3, -2.5, 2.11, 0.82, -1.17, 0.11,
        -0.8, 2.91, 0.71, 0.01, -1.41, -3.47, -0.95, 0.49, 2.52, -0.37
      ]
    },
    {
      "name": "Momentum",
      "returns_pct": [
        2.48, -3.37, -2.54, 0.88, 2.98, -1.93, 5.53, -2.9, 0.08, 2.35,
        -1.7, 0.95, -2.15, -1.16, -4.11, -5.82, 0.58, -0.26, 2.2, -3.37,
        2.33, 2.48, -3.26, 3.74, 3.2, 1.06, 1.92, 0.13, 1.29, 7.79,
        1.65, 4.04, -0.31, 0.36, 0.24, 3.56, 2.35, 3.2, -0.13, -0.3,
        -2.95, 2.75, 5.03, 3.83, -0.11, 3.02, -1.87, 5.2, -5.05, 3.42,
        -0.02, 1.59, 0.09, -1.39, 0.54, 0.92, -1.64, -7.58, -0.13, 5.98
      ]
    }
  ],
  "periods_per_year": 12
}
```

Work them out with the method above. Yours should match these within 0.5%.

- Annualized intercept: 2.9858 % a year
- Intercept t-stat: 1.5455
- R squared: 0.8552
- Adjusted R squared: 0.8474
- Annualized residual vol: 4.1459 %
- Durbin-Watson: 1.7445
- Observations per factor: 20
- Beta on Market: 0.701563

Where the outcome flips, with the other inputs held:

- observations at 101: About this many observations would bring the intercept's t-stat to 2, if the intercept and residual vol stayed as they are.

If yours differ, stop and tell the person which ones and by how much. Don't go on to real numbers until they match, or until the person has seen the difference. These values come from one engine and can be wrong too.

## Step 2: run it on the person's numbers

Replace every input with the person's own. Ask for any number you don't have, and don't invent one.

## Step 3: report

Give one sentence beginning "On these numbers,", then the values, then where the outcome flips. Always add what this leaves out:

- Corrections for autocorrelated residuals or changing variance, such as Newey-West. Durbin-Watson only warns.
- Betas that change inside the sample. There is one fit for the whole window.
- Data mining: how many factor sets or samples were tried before this one.
- Survivorship, stale prices and smoothing in the series sent.
- Compounding, fees and taxes beyond what the series already holds.

## Limits

Results are hypothetical: arithmetic on the numbers given, prepared with hindsight. Nobody achieved them, and costs and liquidity are only as assumed. They aren't a forecast, a recommendation, an offer or a record of real trading. Don't say what to buy, sell or hold, and don't use them to market an investment. Whether a person may hold or trade an instrument is a legal question for counsel.

Provided as is, at your own risk, by hedgefund.md, which is not a fund and isn't anyone's adviser. Version 1.0. Source: https://hedgefund.md/models/factor_regress/prompt.md. Terms: https://hedgefund.md/terms
