I am trying to create my own module that will calculate indicators, and I am implementing a function like this:
def average_day_range(price_df: PandasDataFrame, n: int=14, calculation_tool: int=0):
'''
0 - SMA, 1 - EMA, 2 - WMA, 3 - EWMA, 4 - VWMA, 5 - ALMA, 6 - LSMA, 7 - HULL MA
:param price_df:
:param n:
:param calculation_tool:
:return:
'''
if calculation_tool == 0:
sma_high = sma(price_df=price_df, input_mode=3, n=n, from_price=True)
sma_low = sma(price_df=price_df, input_mode=4, n=n, from_price=True)
adr = sma_high[f'SMA_{n}'] - sma_low[f'SMA_{n}']
adr.rename(columns={0: f'Average Day Range SMA{n}'})
return adr
elif calculation_tool == 1:
ema_high = ema(price_df=price_df, input_mode=3, n=n, from_price=True)
ema_low = ema(price_df=price_df, input_mode=4, n=n, from_price=True)
adr = ema_high[f'EMA_{n}'] - ema_low[f'EMA_{n}']
adr.rename(columns={0: f'Average Day Range SMA{n}'})
return adr
elif calculation_tool == 2:
ema_high = wma(price_df=price_df, input_mode=3, n=n, from_price=True)
ema_low = wma(price_df=price_df, input_mode=4, n=n, from_price=True)
adr = ema_high[f'EMA_{n}'] - ema_low[f'EMA_{n}']
adr.rename(columns={0: f'Average Day Range SMA{n}'})
return adr
elif calculation_tool == 3:
ewma_high = ewma(price_df=price_df, input_mode=3, n=n, from_price=True)
ewma_low = ewma(price_df=price_df, input_mode=4, n=n, from_price=True)
adr = ewma_high[f'EMA_{n}'] - ewma_low[f'EMA_{n}']
adr.rename(columns={0: f'Average Day Range SMA{n}'})
return adr
etc(...)
Is there a more convinient way to do the same but without if-elif
hell?