Python for programmers, prompts for data analysts.
On November 16, 2018, Coca-Cola closed at $50.17. That's the price people paid that day. Open today's adjusted close for the same day, and you'll see $39.37. Nobody ever paid $39.37 for a
Coca-Cola share in November 2018. The number exists only because of dividends paid in the years after it.
In the last two parts we used the adjusted close as the honest measure of total return, and for that job it is. But after Part 36, a reader, Arhan Canli, pointed out a trap: a backtest
that runs on today's adjusted prices sees numbers no one could have seen at the time. For some rules that doesn't matter at all. For others it moves a signal by years.
In this part we find out which is which, using Coca-Cola's last ten years. And we look at the three dates EODHD gives for every dividend, to see when each one was actually known.
Want to try this yourself? The EODHD MCP Server is what pulled the data in this article — connect it to Claude and ask your own questions
(affiliate link).New here? The Setup covers everything you need before your first prompt.
Two prices for the same day
The data is the same as in Part 37: Coca-Cola's raw closes and dividends from October 2016 to October 2026, and EODHD's adjusted close for the same days. The question is how far apart the
two columns are.
🟧 PROMPT
For the first trading day of each year since 2017,
show Coca-Cola's raw close next to today's
adjusted close, and how much lower the adjusted
one is.
The further back you go, the bigger the gap:
| Date | Raw close | Today's adjusted close | Adjusted is lower by |
|---|---|---|---|
| Jan 3, 2017 | $41.80 | $30.92 | 26.0% |
| Jan 2, 2019 | $46.93 | $37.12 | 20.9% |
| Jan 4, 2021 | $52.76 | $44.53 | 15.6% |
| Jan 3, 2023 | $62.95 | $56.42 | 10.4% |
| Jan 2, 2025 | $61.84 | $58.92 | 4.7% |
| Jan 2, 2026 | $69.12 | $67.80 | 1.9% |
Each later dividend lowers every earlier adjusted price a little. A price from 2017 has had almost 40 dividends taken off it; a price from 2026 only three.
So which column is "right"? Both, for different questions. The adjusted close answers: how much has an investment made since that day, dividends included? The raw close answers: what did a
share cost that day?
A person in January 2017 could only see the raw column. The adjusted column for 2017 didn't exist yet. It was written later, one dividend at a time. That's what "as known then" means: on
any day, the adjusted close as it stood that day was simply that day's raw price. The adjusted column in the table is that price, rewritten by every dividend since.
The $50 rule
Now a rule that looks at the price level. It's deliberately simple: buy Coca-Cola the first day it closes above $50.
🟧 PROMPT
On which day did Coca-Cola first close above $50?
Answer twice: once using the raw close, once using
today's adjusted close.
Using the raw close: November 16, 2018, at $50.17. Using today's adjusted close: December 13, 2021, when the adjusted value reached $50.28. The raw close that day was $57.76.
Across all 2,513 trading days, the two series disagree about whether Coca-Cola was above $50 on 491 of them, about one day in five.
The same rule, run on two versions of the same price history. Snapshot as of October 28, 2026.
A backtest on today's adjusted close would report that the rule bought in December 2021, three years late, on a day when the real price was $57.76. No trader following that rule in real
time would ever have done that. In November 2018 the screen showed $50.17, and the rule would have fired.
That's the lookahead Arhan described. The backtest uses a number that was only created later, by dividends that hadn't been paid yet. It doesn't need a mistake in the code. It only needs
the wrong column.
Any rule built on the price level has this problem: a "price above $5" filter, a minimum dollar volume, a stop-loss at a fixed price, a target price. On a dividend payer like Coca-Cola,
the further back the backtest goes, the bigger the error.
Why returns are safe
So is today's adjusted close useless for backtests? No. Arhan's comment had a second half, and it's the reassuring one: anything that only uses the ratio between two days is safe.
🟧 PROMPT
What was Coca-Cola's return from November 16, 2018
to December 13, 2021, dividends included?
Calculate it two ways: from today's adjusted
close, and day by day from the raw closes, adding
each dividend on its ex-date.
From today's adjusted close: 27.72%. Day by day from the raw closes plus dividends: 27.74%. The tiny gap is rounding, because EODHD's adjusted close has four decimals. For the record,
the raw price alone rose only 15.13%.The same holds for every single day: the daily return from today's adjusted close matches the raw close plus that day's dividend on all 2,513 days, within 0.04 percentage points.
The reason is simple arithmetic. A dividend paid in 2024 lowers both the 2018 price and the 2021 price by the same factor. When you divide one by the other, that factor cancels out. Every
later dividend cancels the same way. Only the dividends paid between the two days are left in the ratio, and those are exactly the ones an investor holding the stock in that period would
have received.
So the rule of thumb is short. Returns, percentage changes, and anything built only from them are safe on today's adjusted close: a 12-month momentum, a correlation, a volatility measured
in percent. Price levels are not: thresholds, stops and filters in dollars. Neither is anything built from price differences in dollars, like an average daily range measured in dollars,
because a difference of two scaled prices is scaled too.
Three dates for one dividend
The price is only half of it. A backtest can also look ahead through the dividends themselves, if it uses a dividend before anyone knew about it. EODHD gives three dates for every
Coca-Cola dividend, and each answers a different question.
🟧 PROMPT
For Coca-Cola's dividends over the last ten years,
how many days usually pass between the declaration
date, the ex-dividend date and the payment date?
When were the yearly raises announced?
The declaration date is when Coca-Cola announced the dividend. The ex-dividend date is the first day the stock trades without it; that's the day the price drops and the day the adjusted
close uses. The payment date is when the cash arrives.Over the 40 dividends, the declaration came a median of 44 days before the ex-date, anywhere from 21 to 62 days. The payment followed a median of 18 days after the ex-date.
All ten raises were announced in February, 21 to 28 days before the March ex-date. The latest one, from $0.51 to $0.53, was declared on February 19, 2026, with an ex-date of March 13.
So between February 19 and March 13, 2026, the new dividend was public, but the price hadn't moved for it yet.
That decides which date a backtest should use, and it depends on the question:
- Adjusting prices: the ex-date. That's when the price actually drops.
- Anything that uses the dividend as information, such as a dividend yield or a rule that reacts to a raise: the declaration date. Before it, nobody knew the number.
- Cash in the account: the payment date.
The trap is subtle. Say a backtest computes Coca-Cola's dividend yield on February 10, 2026, from a dividend list downloaded today. If it takes the latest dividend in the list, it gets $0.
53, a number that wasn't public for another nine days. If it takes the latest dividend by ex-date, it's safe on February 10, but after February 19 it keeps using $0.51 for three more
weeks, although the raise was already public. Only the declaration date gives the number that was actually known. That's what Arhan meant by storing the announcement date: rebuild
everything "as of D" from what was announced by D.
A word of honesty
The declaration dates come from today's dividend records, not from an archive of what a database showed back then. If a date or an amount was corrected later, the record shows only the
corrected version. A truly point-in-time backtest needs snapshots of the data as it was published, and that's a bigger project than one article.
The dates also have no time of day. Dividend announcements come as press releases, and whether one came before the market opened or after it closed changes which day's price could have
reacted. Counting from the next trading day is the safe choice.
This is one stock and one deliberately simple rule. The size of the effect depends on how much a company pays out and how far back the backtest goes. For a stock with a small dividend it's
smaller. For a stock with a split, it's much larger: as Part 33 showed, a split rescales every earlier price by the full split ratio, not by a fraction of a percent.
And the fix has a cost. Running a level-based rule correctly means using, on each day, the prices as they stood that day, which in practice means the raw close for price levels and the
adjusted close only for returns. That's more work than loading one column. Not investment advice.
Final Thoughts
This is the thirty-eighth article in the series Unlock Real-Time Market Intelligence with EODHD and Claude, and the fifth about the adjusted close, after Parts 33, 35, 36 and 37. Part 36 rebuilt it, Part 37 showed what it
adds. This one showed where it misleads, an idea that came from a reader, Arhan Canli.
Here's what came out: today's adjusted close is the right column for returns and the wrong one for price levels. A rule that waits for Coca-Cola to pass $50 fires in November 2018 on
the prices people actually paid, and in December 2021 on today's adjusted prices. Three years apart, from the same data. The return over the same period comes out the same on both, 27.7%.
The dividends follow the same logic. Use the ex-date to adjust prices, and the declaration date for anything that depends on knowing the dividend. Ask of every number in a backtest: could
anyone have seen this on that day?
Next time I want to look at the other way a company can return cash to its shareholders. Apple pays a small dividend, but it spends far more buying back its own shares. Buybacks never show
up in the adjusted close at all. So how much did they matter?
If this made you curious, the MCP Server is free to try — The Setup walks you through it.
← Part 37: The Other 40%: How Much of Coca-Cola's Return Came from Dividends
Top comments (1)
Lookahead leakage is dangerous because a backtest can still look internally consistent. A strong defense is to attach an “available at” timestamp to every feature and assert in tests that no training or decision row can read a value whose publication time is later than that row.