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.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Detrended Price Oscillator for you. Just ask in plain English.
Calculate the Detrended Price Oscillator in Python
The Detrended Price Oscillator is available in the Technicals module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_detrended_price_oscillator as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(tickers=["AAPL", "MSFT"])
toolkit.technicals.get_detrended_price_oscillator()
Which returns:
| Date | AAPL | MSFT | Benchmark |
|---|---|---|---|
| 2026-06-18 | -16.7529 | -21.8536 | -11.8786 |
| 2026-06-22 | -14.9607 | -26.2107 | -22.3686 |
| 2026-06-23 | -10.2421 | -31.1771 | -9.6843 |
| 2026-06-24 | -13.4786 | -28.7893 | -5.4164 |
| 2026-06-25 | -7.3379 | -18.6071 | 7.3607 |
| 2026-06-26 | -3.6886 | -23.1914 | 2.87 |
| 2026-06-29 | -5.7957 | -34.6771 | -5.5257 |
| 2026-06-30 | -2.7321 | -29.1271 | 0.95 |
| 2026-07-01 | -3.0679 | -34.5314 | -0.3893 |
| 2026-07-02 | -4.285 | -23.1193 | -9.3429 |
Parameters
get_detrended_price_oscillator accepts the following parameters:
- period (str, optional): The time period to consider for historical data. Can be “daily”, “weekly”, “quarterly”, or “yearly”. Defaults to “daily”.
- close_column (str, optional): The column in the historical data that represents the closing prices. Defaults to “Adj Close”.
- window (int, optional): The number of periods to consider for the DPO calculation. Defaults to 14.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
- growth (bool, optional): Whether to calculate the growth of the indicator values. Defaults to False.
- lag (int | list[int], optional): The lag to use for the growth calculation.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. Defaults to 1.
Related Momentum Indicators
The Technicals module page introduces the module, and the sidebar lists all of its functions.