TradeViora AcademyLearn. Analyze. Practice. Trade Smarter.
Menu

FREE FINANCIAL EDUCATION

Linear-regression slope and fit error

Study linear-regression slope and fit error through mechanisms, a synthetic worked case, practice, and explained assessment.

Technical Indicators

APPLIED STUDY · ORIGINAL LESSON

Learning plan and prerequisites

Before you begin: Understand averages, price changes and squared errors.

Mechanism and interpretation

A rolling linear regression fits price to time over a declared trailing window. With time values x and prices y, slope is the sum of(x−mean x)(y−mean y) divided by the sum of(x−mean x)². Intercept is mean y−slope×mean x. Fitted values describe the least-squares line through the observed window. Slope has price units per chosen time step; changing from minutes to hours changes its numerical scale without changing the underlying path.

Fit error is a separate dimension. Residuals are observed prices minus fitted values, and their squared sum measures dispersion around the line. A positive slope with large residuals describes a noisy advance; the same slope with small residuals describes a smoother one over that window. Neither guarantees future continuation. A fitted endpoint is a calculated summary, not necessarily a traded price. Extending the line into the future introduces a forecasting assumption that must be evaluated separately.

Worked case — synthetic data

Synthetic times are 0,1,2 and closes 100,102,103. Mean time is 1 and mean price 101.6667. The slope numerator is 3 and denominator 2, giving 1.5 price units per bar. Intercept is 100.1667. Fitted values are approximately 100.1667,101.6667 and 103.1667. Residuals are−0.1667,+0.3333 and−0.1667, with squared sum 1/6≈0.1667. The residuals sum to zero within rounding because an intercept is fitted.

Extrapolating to time 3 gives 104.6667, but no observation at time 3 was used and no result is guaranteed there. If the next actual close is 99, the forecast error is about−5.6667 despite the earlier small in-window residuals. Refit the rolling model only using data available at the decision time, and retain the original forecast for evaluation instead of replacing it with the later revised line.

Context and failure modes

Price-scale differences make raw slopes hard to compare across instruments. Percentage or log-price slopes answer different questions and require explicit interpretation. Very short windows can fit noise; longer windows can hide changing regimes. Missing timestamps or unequal bar intervals invalidate a simple “one unit per bar” time assumption unless handled consistently.

Practice task

Fit times 0,1,2 to prices 20,22,24. State slope, intercept, residual squared sum and the extrapolated value at 3. Explain what the perfect fit fails to establish.

Worked practice answer

Slope is 2, intercept 20 and all residuals are zero, so squared sum is 0. Linear extrapolation gives 26 at time 3. The perfect historical fit does not prove that the next observed price will be 26 or that an executable trade can capture the line's implied movement.

Topic assessment

Choose an answer before opening each explanation. These questions test the specific mechanism in this lesson.

1. What does slope measure in this construction?

  1. Price change per declared time unit in the fitted line
  2. A probability of profit
  3. Exact future return
Reveal answer and explanation

A. Its units follow from the price and time inputs.

2. What does residual squared sum measure?

  1. The guaranteed next-bar error
  2. In-window deviations from the fitted line
  3. The number of traders
Reveal answer and explanation

B. It describes historical fit, which is distinct from out-of-sample forecast error.

3. Why retain an old forecast after refitting?

  1. To prevent all future updates
  2. Because the old line must be true
  3. To evaluate what was actually predicted at that time
Reveal answer and explanation

C. Replacing it with a later fit would erase the original prediction error.

Primary references and scope

Original explanation and synthetic calculations. Chart thresholds are explicit research conventions, not exchange rules or proof of predictive ability.