Bull Bear States

Bull and Bear are commonly mentioned market dynamics that assist in deploying certain strategies. In this module, two algorithms for bull and bear market detection have been implemented. Pagan and Sossounov’s and Lunde and Timmermann’s algorithms are commonly used to detect different market regimes.


Underlying Literature

The following sources elaborate extensively on the topic:

Pagan and Sossounov

Influenced by Bry and Boschan’s paper (Cyclical Analysis of Time Series: Selected Procedures and Computer Programs, 1971. ), Pagan and Sossounov developed an algorithm to classify bull and bear states. The classification goes through four different filtering methods. The filtering steps are as followed:

  1. Use a window length for both directions to determine local extrema.

  2. Censor the first and last months to eliminate bias.

  3. Remove cycles with length shorter than the given parameter.

  4. Remove phases with length shorter than the given parameter unless if the change is greater than the threshold.

After each filtering method, the corresponding data undergoes an alternation filter that combines consecutive peaks and troughs.

Code implementation demo

Lunde and Timmermann

Lunde and Timmermann’s algorithm is based on realizing the absolute change from the highest or lowest point. Two parameters are used for Lunde and Timmermann: \(\lambda_1\) and \(\lambda_2\). The parameters are considered as switches that indicate the change of states.

Code implementation demo


In their paper, Lunde and Timmermann consider both symmetric (\(\lambda_1 = \lambda_2 =0.2\)) and asymmetric (\(\lambda_1 = 0.2, \lambda_2 = 0.1\)) parameters.


Below is an example on how to create labels for bull and bear detection.

Code example demo

Presentation Slides