Audit the adjusted column against what the company did
By the end of this lesson you will have every step of the adjustment factor checked against /div and /splits, a test on Apple's 2020 dividend and split as the API gives them, the join of two pulls caught on the day it happens, and the check printed on your backtest page.
Every return, signal and curve in this course stands on adjusted_close, and nothing so far checks that column. The candles lesson warned that it is rewritten after every dividend and split. The returns lesson showed what the raw column does to a split. This lesson checks the adjusted column itself, against the record of what the company actually did.
The factor, and the only days it may move
Divide one column by the other and you get the factor that day's price was multiplied by:
factor = adjusted_close / close
EODHD adjusts backwards from today. When a dividend goes ex, every older price is scaled down by one minus the dividend over the previous close; when a stock splits, every older price is divided by the ratio. Read forwards in time, the factor is flat between events and steps on the event days by exactly:
- ex-dividend day:
1 / (1 − D / previous close), with D the cash paid per share; - split day: the ratio, 4 for a four-for-one split;
- any other day: nothing at all.
Apple around its 2020 dividend and split, as /eod gave it on 2026-11-13:
| Date | close | adjusted_close | factor | step |
|---|---|---|---|---|
| 2020-08-06 | 455.61 | 110.1049 | 0.241665 | |
| 2020-08-07 | 444.45 | 107.6016 | 0.242101 | 1.001803 |
| 2020-08-10 | 450.91 | 109.1655 | 0.242100 | 1.000000 |
| 2020-08-28 | 499.23 | 120.8638 | 0.242100 | 1.000000 |
| 2020-08-31 | 129.04 | 124.9626 | 0.968402 | 4.000001 |
The record says Apple went ex-dividend on 2020-08-07 paying 0.82 a share, and split four for one on 2020-08-31. One over one minus 0.82 / 455.61 is 1.001803. We checked the same rule over two years of SPY and Coca-Cola: every step matched its dividend to within about a millionth, and no other day moved by more than rounding.
Two numbers for one dividend
/div sends two amounts for every payment. For that Apple dividend, value is 0.205 and unadjustedValue is 0.82. The first is restated in today's shares, divided by every split since; the second is the cash that was paid, in the shares of the day. The factor compares a payment with the raw close of the same day, so it needs unadjustedValue. Read value instead and the predicted step is 1.000450, a quarter of the real one, and the check reports a dividend day that is perfectly fine.
What a mismatch means
The check cannot say which column is wrong. It says the prices and the record do not tell the same story, and in practice that has three causes.
A cached history extended instead of pulled again. This one is yours to cause. Your agent will sooner or later propose fetching only the bars after the last cached date and appending them, because it saves a call. The old bars are on the scale of the day they were pulled, the new ones on today's, and the join carries every dividend paid in between as a step nobody paid. The returns lesson quotes 2020-08-27 at 121.1519; pulled again on 2026-11-13 it is 121.0599, because Apple paid another dividend on 2026-11-12. Join that older pull to today's 2020-08-31 and the split reads 3.99696 instead of 4.
Two sources glued together, or one that adjusts for splits but not dividends. Each looks right alone.
The two closes swapped somewhere between the response and your Bar.
Where the check runs
Wherever the history is pulled. /div and /splits cost one call each whatever the range, and both are on the free plan with a year of history. Fetch them with the history, cache them beside it, and fetch them again whenever the history is pulled again: a record older than the bars would miss the newest dividend and blame the prices for it. A fresh pull is then three calls, and the page spends nothing until you delete the cache.
The tolerance is one part in ten thousand, plus the rounding of two adjusted closes in their fourth decimal. Real data needs the floor: GE's history before its 2021 reverse split wobbles by two parts in a hundred thousand. A quarter's dividend on an index fund is about twenty-five times the floor, so a missing one still shows. Some spin-offs come through /splits as a ratio (GE's in 2023 is 1281/1000), and those pass like any split. An event the record does not carry shows up as a mismatch, which is the check doing its job: read the day before you trust the curve.
Try it now
Write the audit on literals first, then put it on the page.
The prompt
Mock mode on, plan mode on. Paste this, and under it the Apple rows from this lesson and the two record rows below:
Plan first. Add src/lib/backtest/adjustment.ts with
auditAdjustments(bars, dividends, splits): the days on which
adjusted_close / close steps by something other than the record says,
which is 1 / (1 - D / previous close) on an ex-dividend day with D
the unadjustedValue, the ratio on a split day, and 1 on any other
day. An event dated on a day with no bar is checked on the next bar,
and a bar with a zero close is a problem. Allow 1e-4 plus 1e-4
divided by each of the two adjusted closes. Add toDividends and
toSplits for the two endpoints' bodies, using parseSplit. Tests
first in tests/adjustment.test.ts on the rows below, as literals:
nothing reported as given, the split day reported when the split is
left out, the dividend day reported when D is read from value, and
2020-08-31 reported when 2020-08-27 and 08-28 come from the older
pull. Run npm test, then show me the diff.
{"date":"2020-08-07","value":0.205,"unadjustedValue":0.82,"currency":"USD"}
{"date":"2020-08-31","split":"4.000000/1.000000"}
The older pull is the returns lesson's: 2020-08-27 at 500.04 and 121.1519, 2020-08-28 at 499.23 and 120.9557.
The second puts it on the page:
Plan first. Add src/lib/backtest/actions.ts: loadActions(symbol,
pulledAt) fetches div/{symbol} and splits/{symbol} through
marketGet, caches both in .cache/actions with the pulledAt of the
history they were fetched with, and fetches again when the history
was pulled again. Add fixtures/div/SPY.US.json with the four
dividends below and fixtures/splits/SPY.US.json as []. On the
backtest page, print the audit under the results, and put a mismatch
at the top. Before writing the fetch, tell me what the page costs
per load.
The four mock dividends, as dates and cash per share: 2025-12-19 1.95008, 2026-03-20 1.74006, 2026-06-18 1.82, 2026-09-18 1.88.
A good answer to the first adds two files and is red before the code and green after. A good answer to the second states three calls for a fresh pull and none after it before writing anything, adds the two fixtures, and changes the page.
Check it yourself
- Every expected date in the test is a literal from this lesson, and the dividend is read from
unadjustedValue. - In mock mode the page says the adjusted column was checked against 4 dividends and 0 splits.
- Delete
.cache/eodand reload twice with mock mode off. The first load spends three calls on the meter and the second spends none. With the shareddemokey, point the page at Apple first:demoanswers the history, dividends and splits for AAPL and refuses SPY, both with the .US suffix. - Read the line under the results on your own history. If it reports a mismatch, open the first date it names before doing anything else with that history.
Break it on purpose
Delete one dividend from the SPY fixture in fixtures/div/ and reload in mock mode: the box at the top names its date and shows a step the record no longer explains. Put it back. Then ask your agent, on a scratch branch, to swap close and adjusted_close in toBars: npm test stays green, because no test feeds the page, and the page's box lights up on every dividend day. Discard the branch, and note which of the two caught it.
Compare with ours
Our audit
// src/lib/backtest/adjustment.ts, the comparison
const factor = (b: Bar) => b.adjusted_close / b.close;
for (let i = 1; i < bars.length; i++) {
const found = factor(bars[i]) / factor(bars[i - 1]);
const allowed = tolerance(bars[i].adjusted_close, bars[i - 1].adjusted_close);
if (Math.abs(found / expected[i] - 1) > allowed) {
problems.push({ date: bars[i].date, expected: expected[i], found });
}
}
expected[i] starts at 1 on every bar; each split multiplies the bar it lands on by its ratio, and each dividend by 1 / (1 − D / previous close). The full state at the end of this unit is on the starter's branch ref/backtest-strategies/u3.
Checkpoint
npm test && npm run typecheck
git status # only the files this step touched, no .env*
git add -A
git commit -m "The adjusted column audited against the dividends and splits"
Then answer this lesson's questions.