LessonThis is a lesson restated in new words. Any figure in it is an example from the source, not this desk's record.
A unit root makes a price series look easy to predict. Regressing Apple's next closing price on today's close, with data from 2018 onward, produces an R-squared of 0.998 in the lesson. The same regression on daily returns produces an R-squared of 0.015 and an adjusted R-squared of 0.014. The price result is a false sense of fit. The return result is the one that matches how a portfolio actually earns.
Why it matters
A high R-squared on prices invites a bad decision: tomorrow's close looks almost known, so a manager, or any other buyer of forecasts, looks unnecessary. The lesson jokes about retiring on that 99.8 percent and then withdraws the joke. Prices hug yesterday's level. A portfolio worth about $10,000 will usually still be near $10,000 tomorrow, so a regression of the level on the lagged level fits tightly and says little about the gain. Returns change sign, bunch into volatile stretches, and are the series a gain calculation cares about. Fitting the level and announcing a forecast is the failure mode unit roots create. The lesson also says linear regression is not the only model that breaks in this way.
The idea in plain words
The data come from the yfinance package, ticker AAPL, history starting in 2018, which brings open, high, low, and close. A return column is the percent change of the close. The first row is empty because there is no prior close. The lesson drops that row. It mentions 2 January as the date left blank when the pull starts at the beginning of the year.
Tomorrow's close is today's close shifted by minus one, so each row looks one day ahead. Tomorrow's return is the return column shifted the same way. The last row becomes empty and is dropped. An ordinary least-squares fit from statsmodels then takes tomorrow's close as the target and today's close, plus a constant, as the input. The constant is added with the library's add-constant helper so the line is not forced through the origin. The summary shows R-squared 0.998 and a similarly high adjusted figure.
Copy the fit onto returns: tomorrow's return on today's return, again with a constant. R-squared falls to 0.015. The lesson's explanation is the unit root in the price. It deliberately skips the formal definition of stationarity and the hypothesis tests, and points at the two summaries instead. Differencing into returns is the transform that, in this example, leaves a series they are willing to treat as closer to a steady statistical object.
Two market facts are named for later, not fitted here. Volatility clusters, so a wild day tends to be followed by more wild days. Higher volatility tends to arrive with negative returns. Neither fact is estimated in the notebook. Both are reasons a return series still has structure after the unit root is removed, and reasons a 0.015 R-squared is not a claim that returns are featureless.
How to use it
Pull the history, add the percent change, and drop empty rows. Build the lead of the close and the lead of the return with a shift of minus one, and drop the trailing empty row. Fit the price regression with a constant and read the R-squared. Fit the return regression the same way and read that R-squared. The pair 0.998 and 0.015 is the lesson's exhibit. If a level regression looks spectacular, repeat it on the difference or the return before you treat the level fit as evidence.
The lesson's research habit sits beside the fit. A bad summary is a reason to revisit the hypothesis, not a reason to edit the test until the summary looks kind. They refuse to tune this regression after seeing it. The same habit applies when the return R-squared is the small one. The small number is the finding.
What usually goes wrong
Quoting 0.998 as forecast accuracy is the error the lesson stages. Most of that fit is the price level persisting, not a hit rate for tomorrow's gain. Leaving out the constant changes the line. The lesson adds it on purpose. Skipping the empty-row drops leaves a missing return or a missing lead.
Other estimators do not escape a unit-root input. The remedy demonstrated here is the percent-change series. A formal stationarity test is out of scope, so this page cites the collapse in R-squared and not a test statistic. Volatility clustering is a fact about the returns that remain.
Questions people ask
What R-squared does the price regression report?
0.998, with a very high adjusted R-squared as well, for Apple closes starting in 2018.
What does the return regression report?
An R-squared of 0.015 and an adjusted R-squared of 0.014.
What change removes the unit root in the example?
Replacing the close with its percent change, then regressing the next return on the current return.