Detrended Price Oscillator
Calculate the Detrended Price Oscillator (DPO) for a given price series.
The Detrended Price Oscillator (DPO) is an indicator that helps identify short-term cycles by removing longer-term trends from prices.
The formula is as follows:
\[\text{Displacement} = \operatorname{floor}(\text{Number of Periods} / 2) + 1\] \[\text{DPO} = \operatorname{Close}(t - \text{Displacement}) - \operatorname{SMA}(\text{Close},\; \text{Number of Periods}) (t)\]Also known as: DPO, detrended price oscillator. Note the moving average itself is not shifted - only the close price used for the comparison is looked up further back in time; see momentum_model.get_detrended_price_oscillator for the full explanation.
Detrended Price Oscillator in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_detrended_price_oscillator as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
tickers=["NGUSD"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.technicals.get_detrended_price_oscillator().tail(5)
Or, after setting up the Finance Toolkit MCP, ask:
How did the price of natural gas cycle around its trend from 26 to 31 December 2025, measured by the Detrended Price Oscillator?
Which returns:
| Date | NGUSD | Benchmark |
|---|---|---|
| 2025-12-26 | -0.0693 | -12.8207 |
| 2025-12-28 | -0.155 | -7.9386 |
| 2025-12-29 | -0.0764 | -2.4429 |
| 2025-12-30 | -0.0021 | -0.8893 |
| 2025-12-31 | -0.0493 | 0.9886 |
Parameters
get_detrended_price_oscillator accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The time period to consider for historical data. Can be “intraday”, “daily”, “weekly”, “monthly”, “quarterly” or “yearly”. Defaults to “daily”. | "weekly" |
close_column | str | The column in the historical data that represents the closing prices. Defaults to “Adj Close”. | "Close" |
window | int | The number of periods to consider for the DPO calculation. Defaults to 14. | 20 |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
growth | bool | Whether to calculate the growth of the indicator values. Defaults to False. | True |
lag | int | list[int] | The lag to use for the growth calculation. Defaults to 1. | 4 |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |