LearnFinance
← Statistics & Probability for Finance Lesson 5 of 6 · 16 min · +50 XP
Statistics & Probability for Finance · Lesson 05

Regression from scratch: fitting a line, R² and what a coefficient means

Regression is the workhorse of financial research: a stock's beta, a fund's alpha, how bond yields respond to inflation. How least squares fits a line, worked by hand on five data points; how beta, alpha and R² come from correlation and volatilities, with a calculator; why a beta is pinned down far better than an alpha, step by step; how one month like March 2020 can swing a line; and why analysts pull betas towards 1.

Facts reviewed Oct 2026

An analyst says a stock has a beta of 1.2. A fund factsheet shows an alpha of 2%. A report says bond yields rise 0.4 points for each 1-point rise in inflation. Each of these comes from a regression.

Indian fund factsheets usually show a fund’s beta, standard deviation and Sharpe ratio, worked out from about three years of data. This lesson builds regression from the ground up, so you can read and question any such number. (Quantitative Finance uses it to build factor models.)

Fitting a line

A simple regression explains one variable, y, as a straight-line function of another, x, plus an error:

y = α + β × x + error

For a stock’s returns against the market’s:

  • β (beta), the slope: how much the stock moves, on average, for each 1% move in the market.
  • α (alpha), the intercept: the stock’s average return when the market return is zero. It’s often read as performance the market doesn’t explain.
  • Error (or residual): everything else, the stock’s own moves.

Ordinary least squares (OLS) picks α and β to make the sum of squared errors as small as possible. Squaring stops positive and negative errors cancelling out, and punishes big misses more.

Worked example: a line by hand. Five months of returns, in %:

MonthMarket (x)Stock (y)
1−2−3
2−1−1
301
412
524
  1. Averages: the market averages 0; the stock averages (−3 − 1 + 1 + 2 + 4) ÷ 5 = 0.6.
  2. Because the market’s average is 0, the slope is simply Σ(x × y) ÷ Σ(x²).
  3. Σ(x × y): 6 + 1 + 0 + 2 + 8 = 17. Σ(x²): 4 + 1 + 0 + 1 + 4 = 10.
  4. Beta: 17 ÷ 10 = 1.7.
  5. Alpha: average y − β × average x = 0.6 − 1.7 × 0 = 0.6% a month.
  6. Fitted line: y = 0.6 + 1.7x. For month 5: 0.6 + 1.7 × 2 = 4.0, exactly the stock’s return.

R²: how much the line explains

R² is the share of the ups and downs in y that the line explains. The rest, 1 − R², is unexplained.

  1. Errors: actual minus fitted, month by month: −0.2, 0.1, 0.4, −0.3, 0. Squared and added: 0.30.
  2. Total variation in y: the squared gaps from 0.6, added up: 29.2.
  3. R²: 1 − 0.30 ÷ 29.2 = about 99%. The market explains nearly all of this stock’s moves. (Real stocks are rarely this tidy.)

The formulas behind the line

The least-squares slope and intercept come straight from familiar statistics:

  • β = correlation × (σ of y ÷ σ of x)
  • α = average of y − β × average of x
  • R² = correlation² (in a simple regression with one x)

Worked example. A stock has a volatility of 30% a year; the market, 18%. Their correlation is 0.6. The stock averaged 15% a year, and the market 12%.

  1. Beta: 0.6 × 30 ÷ 18 = 1.0.
  2. Alpha: 15% − 1.0 × 12% = 3% a year.
  3. R²: 0.6² = 36%. The market explains about a third of the stock’s ups and downs.
  4. Stock-specific volatility: 30% × √(1 − 0.36) = about 24% a year. That’s the risk left over.
Regression from summary statistics: beta, alpha and R²
Beta (slope)
1
Alpha (intercept) a year
3%
R² (share of variance explained)
36%
Residual (stock-specific) volatility
24%

The defaults: beta 1.0, alpha 3% a year, R² 36% and stock-specific volatility of about 24%. Raise the correlation to 0.9 and beta rises to 1.5, while the stock-specific risk falls to about 13%.

Quick check

A fund's regression on its benchmark gives a beta of 0.95 and an R² of 98%. What does that suggest?

Coefficients have standard errors

Like any estimate, a regression coefficient has a standard error. (This module’s estimates lesson explained why.) Regression output shows each coefficient’s standard error and t-statistic: the coefficient ÷ its standard error.

Worked example. Take the stock above (beta 1.0, alpha 3%, stock-specific volatility 24%), estimated from 5 years of monthly data.

  1. Standard error of alpha: roughly the stock-specific volatility ÷ √years = 24% ÷ √5 = about 10.7% a year.
  2. t-statistic for alpha: 3 ÷ 10.7 = about 0.3. Nowhere near significant. The “3% alpha” could easily be zero, or negative.
  3. Standard error of beta: roughly the stock-specific volatility ÷ (market volatility × √years) = 24 ÷ (18 × √5) = about 0.60 with five yearly figures. Using all 60 monthly points sharpens it to about 0.17.
  4. t-statistic for beta: 1.0 ÷ 0.17 = about 6. Clearly pinned down.

So betas are usually estimated well, and alphas rarely are. It’s the same reason average returns are hard to estimate. Frequent data helps measure how things move together. But only more years help measure the average.

Multiple regression

Most real questions involve several explanatory variables at once. Examples: the Fama–French factors in Quantitative Finance, or inflation and growth together explaining bond yields.

Each coefficient then measures that variable’s effect holding the others constant. Problems arise when the explanatory variables are closely related to each other. This is multicollinearity. The coefficients become unstable: small changes in the data swing them around, and they’re hard to read.

A real case: one month can swing a line

In March 2020, as COVID-19 hit, the Nifty 50 fell about 23% in a single month. Many stocks fell even more.

Now picture a regression of a stock’s monthly returns on the Nifty over 2018–2020: 36 points. March 2020 sits far to the left of all the others. Because least squares squares errors, that one extreme point pulls hard on the line. A stock that fell 35% that month will show a much higher beta than one that fell 25%, even if the other 35 months look alike.

Analysts check whether a result survives without such months. If dropping one point changes the beta a lot, the estimate is fragile.

Reading regressions critically

  • Correlation, not causation. A coefficient describes a link, not a cause. The next lesson covers why that matters.
  • Outliers. A few extreme points, like March 2020, can swing the line.
  • Curves. Options, borrowing and crises create curved relationships that a straight line misses.
  • Changing relationships. Betas and correlations shift over time. A regression over ten years averages very different periods.
  • Overlapping or linked data makes standard errors too small, so results look more significant than they are.

Going further: why analysts pull betas towards 1. Across thousands of stocks, high measured betas tend to fall in later years, and low ones tend to rise. Part of this is real: companies drift towards the average. Part is noise: a beta measured at 1.6 is more likely to be a true 1.3 that got lucky than a true 1.9 that got unlucky. So many data providers report an adjusted beta, a formula associated with Marshall Blume: adjusted β ≈ 0.67 × measured β + 0.33 × 1. A measured beta of 1.6 becomes 0.67 × 1.6 + 0.33 = about 1.40. A measured 0.6 becomes about 0.73. It’s a simple form of shrinkage: when an estimate is noisy, pull it towards a sensible average.

Common mistakes

  • Treating a fitted alpha as proof of skill. Check its standard error.
  • Reading beta as causation. It measures how things moved together.
  • Ignoring R². A beta from a regression with R² of 10% says little about the stock’s risk.
  • Letting one month drive the result. Test without the outliers.
  • Assuming relationships stay fixed. Re-estimate over different periods.
Practice 1: A defensive stock has a correlation of 0.5 with the market and a volatility of 20%. It averaged 13%, against the market's 12% (volatility 18%). What are its beta, alpha and R²?
  1. Beta: 0.5 × 20 ÷ 18 = about 0.56.
  2. Alpha: 13% − 0.56 × 12% = about 6.3% a year.
  3. R²: 0.5² = 25%.

A low-beta stock that kept up with the market shows a large alpha: the low-volatility pattern discussed in Investment Philosophies & Market Efficiency. Enter 0.5, 20, 18, 13 and 12 in the calculator to check.

Practice 2: Three months of returns, in %: market −1, 0, 1; stock −2, 1, 4. Fit the line by hand. What are beta, alpha and R²?
  1. Averages: market 0; stock (−2 + 1 + 4) ÷ 3 = 1.
  2. Σ(x × y): 2 + 0 + 4 = 6. Σ(x²): 1 + 0 + 1 = 2.
  3. Beta: 6 ÷ 2 = 3.
  4. Alpha: 1 − 3 × 0 = 1% a month.
  5. Fitted values: −2, 1, 4, exactly the actual returns. So R² = 100%.

With only three points, a perfect fit tells you almost nothing about the future.

Key takeaways

  • A regression fits y = α + β × x + error by least squares: the line with the smallest sum of squared errors.
  • β = correlation × (σy ÷ σx); α = mean y − β × mean x; R² = correlation² in a simple regression.
  • Coefficients have standard errors and t-statistics. Betas are pinned down well (t ≈ 6 in the example); alphas rarely are (t ≈ 0.3).
  • In multiple regression, each coefficient holds the others constant. Watch for multicollinearity, outliers like March 2020, curves and unstable relationships.
  • Adjusted betas pull noisy estimates towards 1.

Go deeper

Complete this lesson
Pass the quiz below (60% or more) to earn +50 XP and unlock the next lesson.
Quiz not passed yet
🧠

Quiz: Regression from scratch: fitting a line, R² and what a coefficient means

5 questions · pass 60% to complete