How is market capitalisation computed?

i have been doing work with historical data in an attempt to mimic automated alpha research in the past, see: Historical ticker components

lately i have been looking at market capitalisation. eodhd offers an api endpoint (Historical Market Capitalization API | Free & paid plans) but it is not clear how this is calculated.
i have pulled fundamental and eod price data for aapl, and computed market cap as shares * eod adjusted close.

here is market cap as returned by the api and market cap as computed from historical prices and historical outstanding shares
aapl_mcap

and here is the difference between the two as a ration of the market cap returned from the api

aapl_mcap_diff

this diff plot shows a clear diff between data sources but a more important drift in value over the years.

the reason to compute the market cap separately from the api is so we have access to older market cap data, as the above shows, the api only has market cap for appl from 2019 onward.

i would like to know if eodhd is computing the market cap data with a different function, it does not seem likely, or if you are computing it with different data, more likely.

Hello. Please provide the exact tickers, API requests and formulas used in your calculations for us to be able to start checking this.

hi @Alex_B
the ticker is aapl, the api requests for fundamentals give me the outstanding shares, the eod endpoint has the adjusted closed. the formula is as simple as “last” market cap times the last adjusted close.

Market cap (if you mean the Highlights::MarketCapitalization field) multiplied by adjusted close doesn’t give market cap. Please be more specific, with exact dates and prices, and it’s better if you provide a csv file of your calculations for that period. Via email please.

here you go:
https://csvbase.com/medecau/eodhd-aapl-mcap-diff

and here’s the code that generated the above data:

import os
import requests
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt


sess = requests.Session()

eodhd_api_key = os.environ["EODHD_API_KEY"]

api_suffix = f"?api_token={eodhd_api_key}&fmt=json"

url = f"https://eodhd.com/api/fundamentals/AAPL.US{api_suffix}"
aapl_data = sess.get(url).json()

url = f"https://eodhd.com/api/eod/AAPL.US{api_suffix}"
aapl_eod_data = sess.get(url).json()

url = f"https://eodhd.com/api/historical-market-cap/AAPL.US{api_suffix}"
aapl_mcap_data = sess.get(url).json()


aapl_eod = pd.DataFrame(aapl_eod_data)
aapl_eod = aapl_eod[["date", "adjusted_close"]]
aapl_eod.rename(columns={"adjusted_close": "close"}, inplace=True)
aapl_eod["date"] = pd.to_datetime(aapl_eod["date"])
aapl_eod = aapl_eod.set_index("date")
aapl_eod


aapl_shares = pd.DataFrame(aapl_data["outstandingShares"]["quarterly"].values())
aapl_shares["data"] = pd.to_datetime(aapl_shares["dateFormatted"])
aapl_shares = aapl_shares.set_index("data")
aapl_shares = aapl_shares[["shares"]]
aapl_shares


aapl_mcap = aapl_eod.copy()
aapl_mcap["shares"] = aapl_shares["shares"]
aapl_mcap.ffill(inplace=True)
aapl_mcap["mcap_computed"] = aapl_mcap["close"] * aapl_mcap["shares"]
aapl_mcap.dropna(subset=["mcap_computed"], inplace=True)


aapl_mcap_eodhd = pd.DataFrame(aapl_mcap_data.values())
aapl_mcap_eodhd["date"] = pd.to_datetime(aapl_mcap_eodhd["date"])
aapl_mcap_eodhd = aapl_mcap_eodhd.set_index("date")
aapl_mcap["mcap_eodhd"] = aapl_mcap_eodhd["value"]


aapl_mcap = aapl_mcap[["mcap_computed", "mcap_eodhd"]]
aapl_mcap["diff"] = (aapl_mcap["mcap_eodhd"] - aapl_mcap["mcap_computed"]) / aapl_mcap[
    "mcap_eodhd"
]
aapl_mcap.to_csv("aapl_mcap.csv")

sns.lineplot(data=aapl_mcap[["mcap_computed", "mcap_eodhd"]])
plt.show()

sns.lineplot(data=aapl_mcap["diff"])
plt.show()