Hilbert Transform Dominant Cycle Phase (HT_DCPHASE)

Calculate the Hilbert Transform Dominant Cycle Phase (HT_DCPHASE): where the prices are within their main cycle, in degrees.

The dominant cycle phase is the position of the price within its dominant cycle, in degrees. It is the angle of the discrete Fourier transform of the smoothed price over exactly one dominant cycle period, corrected for the lag of the smoothing. The phase advances by about 360 degrees divided by the period each period while the price cycles, and barely moves (or moves backwards) while it trends. It runs from -45 to 315 degrees and wraps around once per cycle.

The formula is as follows:

\[\text{Smooth} = \frac{4 \cdot \text{Price} + 3 \cdot \operatorname{Price}(t-1) + 2 \cdot \operatorname{Price}(t-2) + \operatorname{Price}(t-3)}{10}\] \[H(x) = (0.0962 \cdot x + 0.5769 \cdot x(t-2) - 0.5769 \cdot x(t-4) - 0.0962 \cdot x(t-6)) \cdot (0.075 \cdot \operatorname{Period}(t-1) + 0.54)\] \[\text{Detrender} = H(\text{Smooth}),\;\; Q_{1} = H(\text{Detrender}),\;\; I_{1} = \operatorname{Detrender}(t-3)\] \[I_{2} = 0.2 \cdot (I_{1} - H(Q_{1})) + 0.8 \cdot \operatorname{I2}(t-1)\;\;\text{and}\;\; Q_{2} = 0.2 \cdot (Q_{1} + H(I_{1})) + 0.8 \cdot \operatorname{Q2}(t-1)\] \[\text{Re} = 0.2 \cdot (I_{2} \cdot \operatorname{I2}(t-1) + Q_{2} \cdot \operatorname{Q2}(t-1)) + 0.8 \cdot \operatorname{Re}(t-1)\] \[\text{Im} = 0.2 \cdot (I_{2} \cdot \operatorname{Q2}(t-1) - Q_{2} \cdot \operatorname{I2}(t-1)) + 0.8 \cdot \operatorname{Im}(t-1)\] \[\text{Period} = \frac{360}{\operatorname{arctan}\left(\frac{\text{Im}}{\text{Re}}\right) \;\text{in degrees}},\;\; \text{limited to between 0.67 and 1.5 times Period(t-1) and to between 6 and 50 periods},\;\; \text{then smoothed as}\; 0.2 \cdot \text{Period} + 0.8 \cdot \operatorname{Period}(t-1)\] \[\text{Dominant Cycle Period} = 0.33 \cdot \text{Period} + 0.67 \cdot \text{Dominant Cycle Period}(t-1)\] \[N = \text{the Dominant Cycle Period rounded to the nearest whole period}\] \[\text{Real} = \sum \sin\left(\frac{360 \cdot i}{N}\right) \cdot \operatorname{Smooth}(\text{t-i})\;\;\text{and}\;\; \text{Imag} = \sum \cos\left(\frac{360 \cdot i}{N}\right) \cdot \operatorname{Smooth}(\text{t-i}) \;\text{for}\; i = 0 \;\text{to}\; N - 1\] \[\text{Dominant Cycle Phase} = \operatorname{arctan}\left(\frac{\text{Real}}{\text{Imag}}\right) + 90 + \frac{360}{\text{Dominant Cycle Period in degrees}},\;\; \text{plus 180 when Imag is negative and minus 360 when above 315}\]

Example · AAPL, MSFT · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_hilbert_dominant_cycle_phase:

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_hilbert_dominant_cycle_phase()

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

What was the phase of the dominant cycle in Apple's and Microsoft's prices in 2025?

Which returns:

Parameters

get_hilbert_dominant_cycle_phase accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Options are: “intraday” (intraday prices), “daily” (daily prices), “weekly” (weekly prices), “monthly” (monthly prices), “quarterly” (quarterly prices), “yearly” (yearly prices). Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”."Close"
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the dominant cycle phase. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Ehlers, J.F. (2001). “Rocket Science for Traders: Digital Signal Processing Applications.” John Wiley & Sons.
  • Library Referenced against TA-Lib’s HT_DCPHASE
  • Library Shares similar logic as pandas-ta-classic’s ht_dcphase
Share