This algorithm to identify bull and bear markets was invented by Mr. Lin Song
in 2013. It is much simpler and quick. The outline is as below.
1) Use a moving window to filter out the local peaks and troughs. The window
is rolling without overlapping.
2) Push the local turning points in a list in an ascending order with respect
3) Suppress successive local turning points such that they are both local
peaks or troughs. Only peak with higher price or trough with lower price is
4) Refine the local turning points by filtering out those candidates that the
relative change with their precedents is not beyond the threshold (20%).
5) Discard the local turning points that are too close to the begin date or
end date of the trading horizon.