Support

Applying adjustment factors

Overview

The following examples demonstrate how to use the Reference client to retrieve all relevant adjustment factors for corporate actions affecting a specific equity. These factors are then applied to daily close prices (using UTC date boundaries) to create a smoother time series that accounts for the impact of the capital events.

See also
See also

Adjustment factors dataset guide for further details and considerations for applying adjustment factors.

Procedure

The following steps outline the procedure for both examples:

  • Obtain data. Retrieve the adjustment factors for the desired security and time range
  • Pre-process data.
    • Filter single listings
    • Filter (A)pply status events
    • Select one option per corporate action event
    • Convert the ex_date index to tz-aware UTC timestamps
  • Apply adjustment factors. Iterate over all factors and apply the cumulative product to all records prior to the ex_date

Dividend adjustments

In the first example, we will use Microsoft Corporation (MSFT) shares, known for consistently issuing quarterly dividends. Our time range will be from the beginning of June 2018 to the end of June 2024. We will observe the cumulative effect of these dividends on the price series over time and plot both the adjusted and original unadjusted daily close prices.

import databento as db
import matplotlib.pyplot as plt
import pandas as pd

# Set parameters
dataset = "XNAS.ITCH"
symbol = "MSFT"
start = "2018-06"
end = "2025-04"

# Create a reference client
ref_client = db.Reference(key="$YOUR_API_KEY")

# Request adjustment factors data for the relevant time range
df_factors = ref_client.adjustment_factors.get_range(
    symbols=symbol,
    start=start,
    end=end,
    countries=["US"],
)

# Filter listing on Nasdaq/NGS (Global Select Market)
df_factors = df_factors[df_factors["operating_mic"] == "XNGS"]

# Filter factors with (A)pply status
df_factors = df_factors[df_factors["status"] == "A"]

# Filter option 1 (default) for all factors
df_factors = df_factors[(df_factors["option"] == 1)]

# Convert the ex_dates index to UTC timestamps
df_factors.index = pd.to_datetime(df_factors.index, utc=True)

# Create a historical client
hist_client = db.Historical(key="$YOUR_API_KEY")

# Request daily bars data to obtain close prices
data = hist_client.timeseries.get_range(
    dataset=dataset,
    schema="ohlcv-1d",
    symbols=symbol,
    start=start,
    end=end,
)
df_bars = data.to_df()

# Apply the adjustment factors:
# Create a new dataframe for the adjusted prices
df_adjusted = pd.DataFrame(index=df_bars.index)

# Copy the close column from df_bars
df_adjusted = df_bars[["close"]].copy()
df_adjusted["close_adjusted"] = df_adjusted["close"]

# Iterate through the factors and apply cumulative product
for ex_date, factor in zip(df_factors.index, df_factors["factor"]):
    df_adjusted.loc[df_adjusted.index < ex_date, "close_adjusted"] *= factor

# Plot the results
plt.plot(df_adjusted["close"], label="close")
plt.plot(df_adjusted["close_adjusted"], label="adjusted")
plt.legend()
plt.xlabel("Date (UTC)")
plt.ylabel("Daily Close Price (USD)")
plt.title(f"{symbol}")
plt.show()

MSFT adjusted close

Forward split adjustments

In the second example, we will use Tesla Inc (TSLA) shares, which have experienced significant price growth in recent years. Companies often split their shares to lower the stock price after rapid growth. Our analysis will cover the period from the beginning of June 2018 to the end of June 2024.

Tesla underwent two major stock splits in August 2020 and August 2022, resulting in substantial step changes in the close price series. We will apply adjustment factors to account for these splits and create a smoother time series that reflects the true underlying price over time. We'll also plot both the adjusted and original unadjusted daily close prices.

import databento as db
import matplotlib.pyplot as plt
import pandas as pd

# Set parameters
dataset = "XNAS.ITCH"
symbol = "TSLA"
start="2018-06"
end="2025-04"

# Create a reference client
ref_client = db.Reference(key="$YOUR_API_KEY")

# Request adjustment factors data for the relevant time range
df_factors = ref_client.adjustment_factors.get_range(
    symbols=symbol,
    start=start,
    end=end,
    countries=["US"],
)

# Filter listing on Nasdaq/NGS (Global Select Market)
df_factors = df_factors[df_factors["operating_mic"] == "XNGS"]

# Filter factors with (A)pply status
df_factors = df_factors[df_factors["status"] == "A"]

# Filter option 1 (default) for all factors
df_factors = df_factors[(df_factors["option"] == 1)]

# Convert the ex_dates index to UTC timestamps
df_factors.index = pd.to_datetime(df_factors.index, utc=True)

# Create a historical client
hist_client = db.Historical(key="$YOUR_API_KEY")

# Request daily bars data to obtain close prices
data = hist_client.timeseries.get_range(
    dataset=dataset,
    schema="ohlcv-1d",
    symbols=symbol,
    start=start,
    end=end,
)
df_bars = data.to_df()

# Apply the adjustment factors:
# Create a new dataframe for the adjusted prices
df_adjusted = pd.DataFrame(index=df_bars.index)

# Copy the close column from df_bars
df_adjusted = df_bars[["close"]].copy()
df_adjusted["close_adjusted"] = df_adjusted["close"]

# Iterate through the factors and apply cumulative product
for ex_date, factor in zip(df_factors.index, df_factors["factor"]):
    df_adjusted.loc[df_adjusted.index < ex_date, "close_adjusted"] *= factor

# Plot the results
plt.plot(df_adjusted["close"], label="close")
plt.plot(df_adjusted["close_adjusted"], label="adjusted")
plt.legend()
plt.xlabel("Date (UTC)")
plt.ylabel("Daily Close Price (USD)")
plt.title(f"{symbol}")
plt.show()

TSLA adjusted close