TurningPointsResult#
- class cultivars.spectral.cycles.TurningPointsResult(*, peaks, troughs, contraction, phases, window, min_phase, min_cycle, nobs)[source]
Bases:
_SummaryMixinA dated chronology: peaks, troughs, the contraction indicator, and the phase table.
A peak at \(t\) is a local maximum over \(\pm\texttt{window}\) observations, a trough a local minimum, with the two alternating and every phase at least
min_phaseand every cycle at leastmin_cycleobservations long. Each completed phase from one turn to the next carries Harding and Pagan’s three numbers: its duration \(D\), its amplitude \(A = y_{\text{end}} - y_{\text{start}}\), and its excess\[E = \frac{\displaystyle \int_{\text{start}}^{\text{end}} \bigl(y_t - \ell_t\bigr)\, dt}{\tfrac{1}{2} D\, |A|},\]the area between the path and the straight line \(\ell\) joining its ends, relative to the triangle that line closes, positive when the path bows above the line. A contraction with positive excess fell fast and then flattened; an expansion with negative excess started slowly and accelerated.
- Variables:
peaks – Indices of the peaks, in time order.
troughs – Indices of the troughs, in time order.
contraction –
(T,)flags,Truefrom the observation after a peak through the following trough. Before the first turn and after the last the state is carried from the nearest turn.phases – One row per phase
(start, end, is_contraction, duration, amplitude, excess): the change in the series over the phase, and Harding-Pagan’s excess – the area between the path and the straight line joining its ends, divided by the triangle’s area, positive when the path bows above the line.window – Half-width of the local-extremum test.
min_phase – Shortest phase allowed.
min_cycle – Shortest peak-to-peak or trough-to-trough cycle allowed.
nobs – Observations.
Note
The chronology is a statement about the sample’s shape under the stated rules, not a test: no turn carries a p-value, and a turn near either end of the sample is provisional in the same way a Christiano-Fitzgerald cycle is, since the local-extremum window cannot look past the last observation. The first and last
windowobservations can never be turns, so a series that ends mid-phase has that phase open and absent fromphases, whilecontractionstill carries the last known state to the end.See also
TurningPoints– the producer, with the quarterly and monthly rule sets.concordance()– the agreement of two chronologies, also reachable asconcordance().MSAR– the model-based alternative, whose smoothed regime probabilities this chronology can be compared against.
References
Harding, D., & Pagan, A. (2002). Dissecting the cycle: A methodological investigation. Journal of Monetary Economics, 49(2), 365-381.
Bry, G., & Boschan, C. (1971). Cyclical Analysis of Time Series: Selected Procedures and Computer Programs. NBER.
Example
A 24-period cycle on a slow upward trend; the quarterly rules find every turn, and the asymmetry of the trend shows in the amplitudes:
>>> import numpy as np >>> t = np.arange(120.0) >>> y = 0.01 * t + 0.5 * np.sin(2 * np.pi * t / 24) >>> res = TurningPoints().date(y) >>> res.peaks, res.troughs (array([ 6, 30, 54, 78, 102]), array([ 18, 42, 66, 90, 114])) >>> res.n_cycles, res.nobs, float(res.contraction.mean()) (4, 120, 0.5) >>> start, end, is_contraction, duration, amplitude, excess = res.phases[0] >>> (start, end, is_contraction, duration), round(amplitude, 2), round(abs(excess), 3) ((6, 18, True, 12), -0.88, 0.0) >>> res.concordance(np.roll(res.contraction, 6)) 0.5
Private methods#
Average duration, amplitude and excess by phase type. |