The Claude Quant PlaybookDownload ebookDownload ebook

Lasso regression

Like ridge, but the penalty is on absolute size. That sharp corner at zero makes the lasso switch weak signals off completely, so it picks a short list of signals for you.

Build a trading system with Claude.Download ebook

01The formula

the penalty: how much you charge per unit of coefficient size
the sum of the absolute sizes of the coefficients
the signals and the outcomes
the fitted coefficients, some of which come out exactly zero

02See it move

03Where it is used

04Why traders use it

Fewer signals means a model you can understand, trade and monitor. The lasso does the selection and the fitting in one step.

05Worked example

With the same problem as ridge (OLS 1.5 and 0.5, correlation 0.60) and λ = 2.00, the lasso gives 0.800 and 0.000: 1 signal kept. Ridge at the same λ would still keep the second at 0.361.

06How it is built

  1. Fix every coefficient but one, . The problem in alone is a parabola plus .
  2. Its minimum is the least-squares answer for moved towards zero by , and set to exactly zero if it was closer than that: the soft threshold .
  3. Cycle through the coefficients and repeat until nothing changes. This is coordinate descent.
  4. Because of the threshold, any signal whose contribution is smaller than is dropped.

07The common mistake

Trusting which signal the lasso picked when two are highly correlated. It tends to keep one and drop the other almost at random; a new sample can swap them.

08In Python and LaTeX

import numpy as np
rho, lam = 0.6, 2.0
c = np.array([1.5 + rho * 0.5, rho * 1.5 + 0.5])  # X'y / n
soft = lambda z, t: np.sign(z) * max(abs(z) - t, 0)
b1, b2 = 1.5, 0.5
for _ in range(200):
    b1 = soft(c[0] - rho * b2, lam / 2)
    b2 = soft(c[1] - rho * b1, lam / 2)
print(round(b1, 3), round(b2, 3))  # 0.8 0.0
\hat{\boldsymbol\beta}_{\text{lasso}} = \arg\min_{\boldsymbol\beta} \|\mathbf y - X\boldsymbol\beta\|^2 + \lambda\sum_j |\beta_j|

09Where it fits

Rather not code the maths yourself? Describe your trading idea and let AI build the bot.

Build a bot with AgenKit

The worked example and the model run the same code, so every number matches. Models simplify markets on purpose. This is education, not financial advice.