chris@schmid:~$
← ./blog

article

I Tried to Predict Apple's Stock Price With Linear Regression. Here's Why You Shouldn't.

PythonMachine LearningFinance

Ever looked at a stock chart and thought: “how hard can it be, it’s just numbers going up and down”? It was, in fact, very hard.

The setup

I built what looked, on paper, like a proper model:

The backtest looked great

Metric Value
R² 0.78
RMSE $2.17
Direction Accuracy 77.5%

I was mentally planning my yacht.

Then I tested on the future

Not a held-out slice of the past — actual future data the model had never seen, from January–February 2026:

Metric Value Change
R² 0.59 −19%
RMSE $4.83 +122%
Direction Accuracy 59.1% −24%

59.1% direction accuracy — a coin flip gets you 50%. My “proper” model turned out to be slightly better than a coin.

What went wrong

  1. Overfitting — the model had memorized the past instead of learning something that generalizes.
  2. Durbin-Watson = 1.40 — the residuals were autocorrelated, a classic sign linear regression’s independence assumption doesn’t hold for time series.
  3. Adjusted R² was actually 0.51 — a good chunk of that shiny 0.78 backtest number was just noise absorbed by 22 features.

The lesson

Linear regression assumes markets are, well, linear. They’re not — they’re chaos wearing a suit. If you actually want to predict stock prices, the honest next steps are an LSTM (it at least handles time dependencies), XGBoost (it captures non-linear patterns Lasso can’t), or — more realistically — an index fund.

Source: github.com/chris017/OLS-PricePrediction