跳到正文
DEV Community· Jaroslav Šmarda·· 2 小時前AI 評分45

如何從原始價格、拆股及股息重建 Apple 調整後收市價

Rebuild It Yourself: Adjusted Prices from Raw Prices, Splits and Dividends

AI 導讀

作者用 Apple 原始收市價、拆股及股息重建調整後收市價,1,959 個交易日的結果均與 EODHD 相差不超過 0.0001%。調整後收市價計入股息再投資後升 817.4%,僅計拆股則升 770.0%。重建須配對原始價格與實際派息額 unadjustedValue;誤用 value 會令總回報變成 802.6%。

正文

Python for programmers, prompts for data analysts.


Part 35 checked the split records against raw prices and found that every split leaves a fingerprint. But it kept one thing as a black box: the adjusted close itself. We trusted that
column and never asked how it was made.

Alexander Hübbert, a reader whose comments have shaped several parts of this series, suggested a different habit. Don't store adjusted prices at all. Store what actually happened: the raw
prices, the splits and the dividends. Then rebuild the adjusted series yourself, whenever you need it.

So that's what this part does, for Apple, over almost eight years. Along the way we'll meet a dividend that comes in two sizes, and a price from 2019 that has been rewritten 32 times.

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.


Three ingredients

The recipe needs three things: the prices as they actually traded, every split, and every dividend. So I asked for all three at once.

🟧 PROMPT

Use the eodhd MCP to get Apple's raw daily closing
prices from January 2019 to today, plus every
stock split and every dividend in that period.

From January 2, 2019 to October 16, 2026 there are 1,959 trading days. In that time Apple split its stock once, 4-for-1 on August 31, 2020, and paid 31 quarterly dividends. The first,
in February 2019, was $0.73 per share; the latest, in August 2026, was $0.27.

A dividend that fell from $0.73 to $0.27 looks like bad news. It isn't. The early payments were made on old shares, before the split. One old share became four new ones, so $0.73 on one
old share is about $0.18 on each new one. Apple has actually raised its dividend almost every year.

That's the first lesson of the recipe: every number has to be in the same units as the prices it sits next to. Hold that thought; it comes back later.

Before cooking anything, I checked the main ingredient. In the last part a reader found that some "raw" prices were really rebuilt from adjusted ones, betrayed by too many decimal places.
Here, all 1,959 closes have at most two decimals, just as a real exchange quotes them. These are prices people actually paid.


Cooking it

Now the recipe itself. The rule is short. Start today and walk backwards through time. Each time you pass a dividend, scale every earlier price down by the share of the price that the
dividend paid out. Each time you pass a split, divide every earlier price by the split ratio.

🟧 PROMPT

Using only those raw closes, splits and dividends,
rebuild Apple's adjusted closing price yourself.
Walk backwards from today: at each dividend,
multiply all earlier prices by
(1 − dividend ÷ previous day's close);
at each split, divide all earlier prices
by the split ratio. Then compare
your result with EODHD's own adjusted close for
every day.

Done. The rebuilt series matches EODHD's adjusted close on all 1,959 days, within 0.0001%. A few examples:

Date Raw close Rebuilt EODHD adjusted
Aug 28, 2020 (last day before the split) $499.23 $120.9557 $120.9557
Aug 31, 2020 (split day) $129.04 $125.0575 $125.0575
Jun 1, 2022 $148.71 $145.6579 $145.6579
Jan 2, 2025 $243.85 $242.0931 $242.0931

Every digit matches. The adjusted close is no black box. It's 32 multiplications, and anyone with the raw prices and the event list can repeat them.

That's exactly what Alexander meant: store what actually happened, and rebuild the rest whenever you need it.

The rebuild shows something else too. The adjusted close isn't just a price. It quietly includes the dividends.

From January 2, 2019 to October 16, 2026, Apple's adjusted close rose 817.4%. If you correct only for the split and ignore dividends, the price rose 770.0%. The difference, 47.5
percentage points, is the dividends, as if each one had been reinvested in the stock on the day it was paid.

So the two numbers answer different questions. 770% is how much the price of a share grew. 817% is how much an investor grew who held the share and reinvested every dividend. Neither is
wrong. Mixing them up is.


A dividend in two sizes

Remember the first lesson: every number has to be in the same units as the prices next to it. Here is where it matters.

EODHD gives every dividend two numbers. For February 2019 they are value 0.1825 and unadjustedValue 0.73. So I asked what the difference is.

🟧 PROMPT

Each Apple dividend has two amounts, value and
unadjustedValue. What's the difference, and which
one belongs in the rebuild?

unadjustedValue is what was actually paid per share on the day: $0.73 on one old share. value is the same payment divided by the later 4-for-1 split: $0.1825, expressed in today's
shares. After the split the two are equal. Before it, they differ by a factor of four.

The rebuild works with raw prices, the ones that actually traded. So it needs the amount actually paid, unadjustedValue. $0.73 against a raw close of about $170 is a payout of about 0.
43%. $0.1825 against the same close is about 0.11%. That's a quarter of the real dividend.

Nothing crashes if you pick the wrong one. Both fields are numbers, both look reasonable, and the formula happily accepts either. So I tried it:

With value instead of unadjustedValue, the seven dividends paid before the split shrink to a quarter of their real size. The total return comes out at 802.6% instead of 817.4%.
Almost 15 percentage points of dividends disappear, and the series no longer matches EODHD on any day before August 2020.

This is the quiet kind of mistake. No error, no warning, just a smaller number that looks perfectly believable. The only thing that caught it was the comparison with EODHD's own adjusted
close. Without a second source, 802.6% would have gone into the article.

The rule is the one from the first section: raw prices go with raw dividends, adjusted prices with adjusted dividends. Mixing the two is like adding crowns to euros. The arithmetic works.
The result doesn't.


The price that keeps changing

The recipe walks backwards from today. That has a consequence that surprised me more than anything else in this experiment: every new dividend changes every price before it. So the
adjusted close for a day in 2019 isn't a fixed number. It depends on when you ask.

🟧 PROMPT

Using the same recipe, what would Apple's adjusted
close for January 2, 2019 have been if I had asked
at different moments: just before the 2020 split,
at the start of 2023, at the start of 2026, just
before the August 2026 dividend, and today?

The raw close that day was $157.92. Here is how its adjusted value looked over time:

Asked on Adjusted close for Jan 2, 2019
Jan 2, 2019 (the day itself) $157.92
Aug 28, 2020 (just before the split) $154.5164
Start of 2023 $38.1051
Start of 2026 $37.5388
Aug 7, 2026 (just before the latest dividend) $37.4692
Oct 16, 2026 (today) $37.4369

The big drop is the split: everything before it was divided by four. The small steps are the dividends. Each one shaves a fraction of a percent off every earlier price. Since January
2019, that price has been rewritten 32 times: once for the split and once for each of the 31 dividends.

So if you saved Apple's adjusted close in a spreadsheet in 2023 and compare it with EODHD today, the numbers won't match. Neither is an error. They are the same recipe, cooked on different
days.

And that is the strongest argument for Alexander's habit. Raw prices never change; a close of $157.92 on January 2, 2019 stays $157.92 forever. The list of events only grows: a new
dividend is added, nothing old is rewritten. If you store those two things, you can rebuild the adjusted series for any day, as it looked on any day. If you store only the adjusted close,
yesterday's copy goes quietly out of date with the next dividend.


A word of honesty

The perfect match proves less than it seems. It shows that my recipe and EODHD's recipe are the same, not that the recipe is the only right one. Other providers use slightly different
conventions. Some adjust only for splits, some apply the dividend on a different day, some ignore small special payouts. So their adjusted close for the same day can differ from EODHD's by
a few cents, and none of them is wrong. If you mix sources, rebuild from raw data and one recipe of your own.

The 817.4% total return is a textbook number. It assumes every dividend was reinvested instantly, at the price of the day, with no taxes and no fees. A real investor in Europe would have
lost part of each dividend to withholding tax and paid something to buy the extra shares. Treat it as the upper bound of what holding Apple returned, not as anyone's actual account.

The three ingredients all came from one source. I checked the raw prices for decimals and the result against EODHD's own adjusted close, but I didn't check the dividend amounts against
Apple's own announcements. If a dividend were wrong in the data, both my rebuild and EODHD's column would carry the same mistake, and they would still match perfectly. Checking a handful
of dividends against the company's investor-relations page is the cheap next step.

And all numbers here are a snapshot as of October 16, 2026. The next Apple dividend will rewrite every adjusted price in this article once more. That's not a flaw; it's the point of the
last section. Not investment advice.


Final Thoughts

This is the thirty-sixth article in the series Unlock Real-Time Market Intelligence with EODHD and Claude, and the third in a row about the adjusted close. Part 33 said: use the adjusted column. Part 35 checked the split
records behind it. This one opened the column itself and rebuilt it from scratch, an idea that came straight from a reader.

Here's what came out: the adjusted close is 32 multiplications, and anyone can repeat them to the fourth decimal. The hard part isn't the arithmetic. It's the units: raw prices with
raw dividends, adjusted prices with adjusted dividends. Get that wrong and nothing breaks; a number just quietly shrinks.

Apple is a gentle test. Its dividend is small, around one percent of the price a year or less, so dividends added "only" 47 percentage points over almost eight years. Next time I want to
run the same recipe on a company where the dividend is the main story, and see how far the price-only chart and the total-return chart drift apart when dividends are a big part of what an
investor actually gets.


If this made you curious, the MCP Server is free to try — The Setup walks you through it.


← Part 35: Every Split Leaves a Fingerprint: Checking Corporate Actions Against Raw Prices

來源:DEV Community · dev.to