Calculate Stock Total Return With a Dividend Reinvestment Ledger Using Claude MCP

A dividend reinvestment return depends on entitlement dates, the execution-price convention, and the share count carried into each payment. A ledger makes those assumptions explicit and reconciles the resulting position to its ending value.

This example uses Claude and the FMP MCP server to reconstruct a hypothetical $10,000 Coca-Cola (KO) holding from December 30, 2022 through December 31, 2025. Reinvestment at payment-date closing prices produces a 20.25% cumulative return, compared with 9.90% from price appreciation alone. The 10.35-percentage-point difference includes dividends and their subsequent investment performance; it does not isolate the benefit of reinvesting rather than retaining cash.

The workflow retrieves dividend records, split history, and closing prices, then calculates each entitlement and share purchase. Its output is a position of 172.008887 shares worth $12,025.14, supported by a share-count reconciliation and an ending-value bridge.

Key Takeaways

  • Twelve dividend reinvestments totaling $955.39 added 14.800901 shares to the original 157.207986-share position.
  • The calculation permits fractional shares and excludes taxes, fees, withholding, and external cash flows. Returns are cumulative, not annualized.
  • Dividends enter the ledger explicitly. Dividend-adjusted prices are excluded to avoid counting distributions twice.
  • Every payment in this window precedes the next ex-dividend date, allowing the cumulative share count to carry into the next entitlement.
  • The reconciliations test arithmetic consistency. They do not independently establish source completeness or replicate a brokerage account's execution history.

Establish the Holding and Reinvestment Basis

The purchase occurs after KO's December 2022 dividend payment. The position remains invested through December 31, 2025, with each subsequent eligible dividend reinvested at the payment-date close.

Setting

Convention

Starting investment

$10,000

Purchase

December 30, 2022 close

Ending valuation

December 31, 2025 close

Included dividends

Ex-dividend dates after purchase and on or before the ending date

Reinvestment price

Payment-date close

Fractional shares

Allowed

External deposits or withdrawals

None

Taxes, fees, and withholding

Excluded

Payment-date closes provide a consistent execution assumption. They are not documented fills from an actual dividend reinvestment plan, which may use different prices or credit shares on different dates.

This historical measurement is distinct from scheduling declared dividend receipts. A receipt schedule identifies expected cash flows and entitlement conditions; this ledger follows eligible payments into additional shares and values the resulting position.

Calculation Basis

The initial holding and each reinvestment follow four relationships:

Initial shares = Starting investment ÷ Purchase close

Cash entitlement = Eligible shares × Dividend per share

Shares added = Cash entitlement ÷ Reinvestment close

Cumulative shares = Eligible shares + Shares added

The eligible share count equals the preceding row's cumulative shares only when those reinvested shares were acquired before the next ex-dividend date. That condition holds throughout this KO window.

The summary measures are:

Ending value = Final shares × Ending close + Unpaid entitlements

Price return = (Ending close ÷ Purchase close − 1) × 100

Reinvested-dividend return = (Ending value ÷ Starting investment − 1) × 100

Calculations retain full precision. The tables display shares to six decimals, cash entitlements to four, and prices and summary dollar amounts to two. Dividend rates retain their source precision, including the $0.485 payments in 2024.

Retrieve the Inputs Through FMP MCP

Three operations supply the ledger's inputs:

Data

MCP operation

Purpose

Company dividends

calendar / dividends-company

Entitlement dates, payment dates, and dividend rates

Stock splits

calendar / splits-company

Check for changes to the share base

Daily prices

chart / historical-price-eod-full

Purchase, reinvestment, and ending closes

The calculation uses the close field from the daily price endpoint. It does not use dividend-adjusted prices because the ledger accounts for distributions separately. The distinction between adjusted and unadjusted price series matters whenever a return calculation combines prices with explicit corporate-action cash flows.

Connect Claude using the FMP MCP setup instructions. The server URL is:

https://financialmodelingprep.com/mcp?apikey=YOUR_FMP_API_KEY

Replace YOUR_FMP_API_KEY with your own key. If needed, create an FMP account and confirm plan access for the required data.

Run the following prompts in the same Claude conversation. Prompt 1 retrieves and checks the inputs. Prompt 2 performs the calculations without making new data requests.

Prompt 1: Retrieve and Validate the Inputs

The retrieval separates entitlement dates from reinvestment dates and checks the holding-window boundaries before calculating a position.

The 60-to-120-day ex-dividend spacing test is specific to this quarterly-dividend example. It flags potential omissions or duplicates; it is not an accounting standard or independent proof of completeness.

Copyable Prompt

Objective

Retrieve and validate the inputs for a dividend reinvestment ledger for The Coca-Cola Company (KO). The hypothetical holding is bought on Dec 30, 2022 and held through Dec 31, 2025. State today's date as the retrieval date. Do not calculate shares, returns or values in this prompt.

Data rules

  • Use only the FMP MCP connector. Do not use web search or any other source.
  • Dividends: call calendar / dividends-company with symbol=KO and limit=40. Keep records whose ex-dividend date (the "date" field) is after Dec 30, 2022 and on or before Dec 31, 2025. Order the kept records by ex-dividend date, oldest first, and number them from 1.
  • Splits: call calendar / splits-company with symbol=KO. Identify any split dated after Dec 30, 2022 and on or before Dec 31, 2025.
  • Prices: call chart / historical-price-eod-full with symbol=KO and use the "close" field. Make one lookup for each of these dates: the purchase date (Dec 30, 2022), the payment date of each kept dividend, and the window end (Dec 31, 2025).
    • Purchase date and window end: set from_date and to_date to the date itself. If no record is returned, report the price as Unavailable. Do not use a nearby date.
    • Payment dates: set from_date to the payment date and to_date to four calendar days later, and use the earliest date returned. If that date is later than the payment date, set the status to Next trading day.
  • Do not use dividend-adjusted prices or any other price field.
  • If a call fails, retry it once. If it fails again, record the item as Unavailable, do not substitute another source, and continue with the remaining items.
  • A missing value is Unavailable. Never treat it as zero.

Steps

  1. Retrieve the dividend records, the split history and the prices as described above.
  2. For each kept dividend, calculate the days between its ex-dividend date and the ex-dividend date of the dividend record immediately before it. For row 1, use the most recent dividend with an ex-dividend date on or before Dec 30, 2022.
  3. For each kept dividend, test whether its payment date is before the next dividend's ex-dividend date. For the last kept row, use the first dividend record dated after Dec 31, 2025 if one was returned; otherwise report Not testable.
  4. Check whether "dividend" equals "adjDividend" in every kept record.
  5. Record the ex-dividend date and payment date of the most recent dividend with an ex-dividend date on or before Dec 30, 2022.
  6. Count the kept dividends whose payment date is after Dec 31, 2025.

Review conditions

Report Review Required if any of the following is true: a price or dividend field is Unavailable; a split is dated inside the window; a payment date is not before the next ex-dividend date; "dividend" differs from "adjDividend" in any kept record; or consecutive ex-dividend dates are fewer than 60 or more than 120 days apart. The 60 and 120 day limits are a screening rule for finding missing or duplicated records, not an accounting standard.

Output

Start with one line giving the retrieval date. Then show these tables in this order, using these exact columns.

Table 1: Dividend records in the window

Columns: Row | Ex-dividend date | Record date | Payment date | Dividend per share (USD) | adjDividend (USD) | Days since previous ex-dividend date | Payment before next ex-dividend date (Yes / No / Not testable)

Table 2: Boundary and split checks

Columns: Check | Result

Rows: Dividend records in the window (count); Most recent dividend before the window (ex-dividend date and payment date); Kept dividends with payment after Dec 31, 2025 (count); Kept dividends where dividend differs from adjDividend (count); Splits dated inside the window (count); Latest split on record (date and ratio)

Table 3: Closing prices for the ledger

Columns: Use | Target date | Price date used | Close (USD) | Status (Complete / Next trading day / Unavailable)

Rows: Purchase; one row per kept dividend labelled "Reinvestment, row n"; Window end

After the tables, add one line stating Review Required: Yes or No, and list the reason for each trigger.

Interpretation limits

Do not calculate shares, returns or values. Do not comment on dividend sustainability or on whether KO is a good investment. Report values as returned.

Input Results: Dividends, Boundaries, and Prices

The example retrieval was completed on November 20, 2026 using FMP MCP. All required records returned without retries.

The tables below separate dates, amounts, and calculations while retaining the row identifiers used in the prompts.

Table 1A: Dividend Dates

Row

Ex-dividend date

Record date

Payment date

1

2023-03-16

2023-03-17

2023-04-03

2

2023-06-15

2023-06-16

2023-07-03

3

2023-09-14

2023-09-15

2023-10-02

4

2023-11-30

2023-12-01

2023-12-15

5

2024-03-14

2024-03-15

2024-04-01

6

2024-06-14

2024-06-14

2024-07-01

7

2024-09-13

2024-09-13

2024-10-01

8

2024-11-29

2024-11-29

2024-12-16

9

2025-03-14

2025-03-14

2025-04-01

10

2025-06-13

2025-06-13

2025-07-01

11

2025-09-15

2025-09-15

2025-10-01

12

2025-12-01

2025-12-01

2025-12-15

Table 1B: Dividend Amounts and Timing Checks

Amounts are USD per share. “Gap” measures days since the preceding ex-dividend date. The final column tests whether payment precedes the next ex-dividend date.

Row

Dividend

adjDividend

Gap, days

Paid before next ex-date?

1

0.46

0.46

106

Yes

2

0.46

0.46

91

Yes

3

0.46

0.46

91

Yes

4

0.46

0.46

77

Yes

5

0.485

0.485

105

Yes

6

0.485

0.485

92

Yes

7

0.485

0.485

91

Yes

8

0.485

0.485

77

Yes

9

0.51

0.51

105

Yes

10

0.51

0.51

91

Yes

11

0.51

0.51

94

Yes

12

0.51

0.51

77

Yes

The first gap uses the preceding ex-dividend date of November 30, 2022. The final payment-order check uses March 13, 2026, the first post-window ex-dividend date returned. These timing checks are calculated from FMP dates, rather than supplied as source fields.

Table 2: Boundary and Split Checks

Check

Result

In-window dividends

12

Pre-window ex-dividend date

2022-11-30

Pre-window payment date

2022-12-15

In-window dividends paid after 2025-12-31

0

Dividend and adjDividend mismatches

0

Splits inside the holding window

0

Latest returned split

2012-08-13, 2-for-1

The November 2022 ex-date precedes the purchase, so that dividend is excluded. All included dividends were paid within the window, and no split requires a share-base adjustment.

Table 3A: Purchase and Ending Prices

Use

Target date

Price date used

Close, USD

Purchase

2022-12-30

2022-12-30

63.61

Window end

2025-12-31

2025-12-31

69.91

Table 3B: Reinvestment Prices

Row

Payment date

Price date used

Close, USD

1

2023-04-03

2023-04-03

62.40

2

2023-07-03

2023-07-03

60.58

3

2023-10-02

2023-10-02

55.48

4

2023-12-15

2023-12-15

58.60

5

2024-04-01

2024-04-01

60.68

6

2024-07-01

2024-07-01

63.28

7

2024-10-01

2024-10-01

71.71

8

2024-12-16

2024-12-16

62.55

9

2025-04-01

2025-04-01

71.87

10

2025-07-01

2025-07-01

71.67

11

2025-10-01

2025-10-01

66.78

12

2025-12-15

2025-12-15

70.97

All 14 price rows have Complete status. No payment required a later trading-day close.

Prompt 1 returned Review Required: No. Inputs were available, all payment-order checks passed, dividend and adjDividend matched, and ex-dividend gaps remained within the screening range.

Prompt 2: Calculate the Position and Reconcile the Return

The second prompt carries the position through each payment using the records already retrieved. It also sums the purchased shares separately and constructs an ending-value bridge.

The payment-order check matters here: using the preceding row's cumulative shares assumes that its reinvestment occurred before the next entitlement date. The supplied records support that sequence for all 12 payments.

Copyable Prompt

Objective

Using only the records retrieved in Prompt 1 in this conversation, build the dividend reinvestment ledger for KO and calculate price return and reinvested-dividend return for a 10,000 USD purchase on Dec 30, 2022 held through Dec 31, 2025. Do not retrieve new data and do not use web search.

Convention

  • Starting investment: 10,000 USD, all invested at the Dec 30, 2022 close in Table 3.
  • Dividends: the rows in Table 1, in row order. Use the "dividend" field as the dividend per share.
  • Eligible shares: the initial shares for row 1, and the cumulative shares after the previous row for every later row.
  • Cash entitlement: eligible shares x dividend per share.
  • Reinvestment price: the close in Table 3 for that row's price date.
  • Fractional shares are allowed.
  • Keep full precision in every calculation and round only for display: shares to 6 decimals, cash entitlement to 4 decimals, prices and all other dollar amounts to 2 decimals, returns to 2 decimals in percent.
  • Unpaid entitlements: a dividend in Table 1 with a payment date after Dec 31, 2025 is not reinvested. Add its cash entitlement to ending value as a separate line. If Table 2 shows none, report 0.00 and write "None in window".
  • Ignore taxes, fees, withholding and any other deposits or withdrawals.
  • If Prompt 1 reported Review Required, or any price or dividend input is Unavailable, do not build the ledger. List the affected items and stop.

Steps

  1. Calculate initial shares as 10,000 divided by the Dec 30, 2022 close.
  2. For each row in order, calculate eligible shares, cash entitlement, shares added (cash entitlement divided by reinvestment price) and cumulative shares (eligible shares plus shares added).
  3. Recalculate final shares independently as initial shares plus the sum of shares added, and report the difference from the last row's cumulative shares.
  4. Calculate ending value as final shares x the Dec 31, 2025 close, plus unpaid entitlements.
  5. Calculate price return as the Dec 31, 2025 close divided by the Dec 30, 2022 close, minus 1. Calculate reinvested-dividend return as ending value divided by 10,000, minus 1. Calculate the difference in percentage points.
  6. Calculate the ending-value bridge: starting investment, plus the price change on the initial shares (initial shares x (window-end close minus purchase close)), plus the value of all shares added through reinvestment at the window-end close, plus unpaid entitlements. Report the bridge total and its difference from ending value. Do not adjust any figure to make the bridge reconcile.
  7. Set each ledger row's status to Complete, or to Next trading day if Table 3 shows that status for that row.

Output

Show these tables in this order, using these exact columns.

Table 4: Dividend reinvestment ledger

Columns: Row | Ex-dividend date | Payment date | Eligible shares | Dividend per share (USD) | Cash entitlement (USD) | Reinvestment price (USD) | Shares added | Cumulative shares | Status

Table 5: Position summary

Columns: Item | Value

Rows: Starting investment (USD); Purchase close (USD); Initial shares; Total dividends reinvested (USD); Total shares added; Final shares; Window-end close (USD); Unpaid entitlements (USD); Ending value (USD)

Table 6: Return comparison

Columns: Measure | Value

Rows: Price return; Reinvested-dividend return; Difference (percentage points); Ending value with no reinvestment, using initial shares only (USD)

Table 7: Ending-value bridge

Columns: Component | Amount (USD)

Rows: Starting investment; Price change on initial shares; Value of shares added through reinvestment at the window-end close; Unpaid entitlements; Bridge total; Ending value from Table 5; Difference

After Table 7, add one line reporting the share-count difference from Step 3.

Interpretation limits

Report the measured results only. Do not attribute them to causes, compare them with other investments, or comment on whether KO is a good investment.

Ledger Results: Cash Entitlements and Share Purchases

The initial purchase establishes 157.207986 shares at the displayed precision. The first $0.46 dividend generates $72.3157, which purchases 1.158905 additional shares at $62.40. Subsequent entitlements use the growing position.

The run calculated the ledger using 40-digit decimal precision. The following tables display rounded results, so calculations repeated from the displayed share counts may differ slightly from the underlying values.

Table 4A: Dividend Cash Entitlements

Row

Eligible shares

Dividend per share, USD

Cash entitlement, USD

1

157.207986

0.46

72.3157

2

158.366891

0.46

72.8488

3

159.569413

0.46

73.4019

4

160.892447

0.46

74.0105

5

162.155425

0.485

78.6454

6

163.451493

0.485

79.2740

7

164.704242

0.485

79.8816

8

165.818195

0.485

80.4218

9

167.103916

0.51

85.2230

10

168.289709

0.51

85.8278

11

169.487250

0.51

86.4385

12

170.781627

0.51

87.0986

Table 4B: Reinvestment and Share Count

Row

Reinvestment close, USD

Shares added

Cumulative shares

1

62.40

1.158905

158.366891

2

60.58

1.202522

159.569413

3

55.48

1.323034

160.892447

4

58.60

1.262978

162.155425

5

60.68

1.296068

163.451493

6

63.28

1.252749

164.704242

7

71.71

1.113953

165.818195

8

62.55

1.285721

167.103916

9

71.87

1.185794

168.289709

10

71.67

1.197541

169.487250

11

66.78

1.294377

170.781627

12

70.97

1.227260

172.008887

All 12 ledger rows have Complete status. Their ex-dividend and payment dates appear in Table 1A.

The cash entitlement increases as both the dividend rate and the share count rise, but the shares purchased do not increase uniformly. Each purchase depends on the prevailing reinvestment close. Row 7, for example, has a larger entitlement than row 3 but purchases fewer shares because its execution assumption uses a higher price.

Table 5: Position Summary

Item

Value

Starting investment

$10,000.00

Purchase close

$63.61

Initial shares

157.207986

Total dividends reinvested

$955.39

Total shares added

14.800901

Final shares

172.008887

Ending close

$69.91

Unpaid entitlements

$0.00; none in window

Ending value

$12,025.14

Total dividends reinvested includes payments earned on shares acquired through earlier reinvestments. It is the sum of portfolio cash entitlements, not a source dividend field or the cash a constant initial-share position would have collected.

Interpret the Return Comparison Correctly

The price-return calculation values the change in one share's price. The reinvested-dividend calculation values the complete ending position.

Table 6: Cumulative Return Comparison

Measure

Result

Price return

9.90%

Reinvested-dividend return

20.25%

Difference

10.35 percentage points

Ending value of initial shares, excluding dividends

$10,990.41

The $10,990.41 figure excludes dividends entirely. It is therefore a price-only reference, not the ending wealth of an investor who elected to receive dividends in cash.

A reinvest-versus-cash comparison would require a separate cash ledger for the unchanged initial share count and an explicit assumption about any return earned on that cash. Without that comparison, the 10.35-percentage-point gap should be described as the difference between reinvested-dividend return and price return.

Reconcile the Ending Value

The bridge separates price appreciation on the initial holding from the ending value of shares acquired through reinvestment.

Table 7: Ending-Value Bridge

Component

Amount, USD

Starting investment

10,000.00

Price change on initial shares

990.41

Ending value of reinvested shares

1,034.73

Unpaid entitlements

0.00

Bridge total

12,025.14

Ending value from Table 5

12,025.14

Difference

0.00

The $955.39 reinvested during the window purchased shares worth $1,034.73 at the ending close. Adding those dividends separately to ending value would double-count cash already converted into shares.

The share-count reconciliation also matches: initial shares plus all shares added equals the final ledger balance, with a displayed difference of 0.000000 shares.

Both checks use the same underlying records as the ledger. They can expose arithmetic or aggregation errors, but a consistently applied incorrect input could still reconcile. The source dividend amounts in this run were not independently compared with Coca-Cola's announcements.

Where the Method Needs Additional Handling

The demonstrated KO window supports a straightforward sequential ledger: no split occurs, every dividend is paid before the ending date, and each reinvestment precedes the next ex-dividend date.

Changing the security or window can change those conditions. Before extending the calculation, address the relevant case:

Condition

Required treatment

Reinvestment moves beyond the payment date

Check the actual purchase date against the next ex-dividend date

No price returns within the search interval

Leave the input unavailable; do not substitute zero

Dividend remains unpaid at the ending date

Carry the entitlement separately without adding shares

Split occurs within the window

Align share counts, dividend rates, and price conventions

Reconciliation differs beyond rounding

Trace the difference before relying on the return

The prompts include a four-calendar-day price search, but that interval does not guarantee a usable trading-day record. Likewise, the unpaid-entitlement and split cases were not exercised by this example and should not be assumed to work simply by changing the ticker.

For an actual account reconciliation, replace the hypothetical execution convention with the account's dividend credits, purchase prices, fees, and tax treatment. For an assessment of distribution sustainability, capital return quality analysis addresses the separate relationship between payouts, cash generation, and financial capacity.

The ledger's analytical value is the ability to trace the reported return through entitlement, cash, execution price, and ending shares. That record makes the result reviewable and identifies which assumptions must change before it can represent a different account or reinvestment policy.

About the Author
Pranjal Saxena

Financial APIs, Claude MCP, and AI-driven research workflows

Pranjal Saxena writes technical content focused on financial data APIs, Claude MCP workflows, AI-driven research systems, and Python-based market analysis. For FMP, his work centers on turning structured financial data into practical, workflow-driven content for developers, analysts, and fintech teams. He combines experience in data science, NLP, generative AI, and financial API workflows to show how APIs, automation, and AI-assisted systems can support modern financial research and analysis.

Related

Financial data for every need

Real-time quotes and 30+ years of historical data, including prices, fundamentals, and insider transactions — all accessible via API.

Create Free Account