Moving average crossover
Moving averages are another popular regime definition method. This method is so simple and prevalent that even the most hardcore fundamental analysts who claim never to look at charts still like to have a 200-day simple moving average. This method is also computationally easy. There may be further refinements as to the type of moving averages from simple to exponential, triangular, adaptive. Yet, the principle is the same. When the faster moving average is above the slower one, the regime is bullish. When it is below the slower one, the regime is bearish. The code below shows how to calculate the regime with two moving averages using simple and exponential moving averages (SMA
and EMA
respectively):
#### Regime SMA EMA ####
def regime_sma(df,_c,st,lt):
'''
bull +1: sma_st >= sma_lt , bear -1: sma_st <= sma_lt
'''
sma_lt = df[_c].rolling(lt).mean()
sma_st = df[_c].rolling(st).mean()
rg_sma...