Coverage for source/indicators/ema_indicator_handler.py: 55%
11 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-07-30 20:59 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-07-30 20:59 +0000
1# indicators/ema_indicator_handler.py
3# global imports
4import pandas as pd
6# local imports
7from source.indicators import IndicatorHandlerBase
9class ExponentialMovingAverageIndicatorHandler(IndicatorHandlerBase):
10 """
11 Implements Exponential Moving Average (EMA) indicator. It gives more weight to recent prices
12 and reacts more quickly to price changes than a simple moving average.
13 """
15 def __init__(self, window_size: int = 20) -> None:
16 """
17 Class constructor.
19 Parameters:
20 window_size (int): Length of window that indicator should be applied over.
21 """
23 self.__window_size = window_size
25 def calculate(self, data: pd.DataFrame) -> pd.DataFrame:
26 """
27 Calculates Exponential Moving Average (EMA) indicator values for given data.
29 Parameters:
30 data (pd.DataFrame): Data frame with input data.
32 Returns:
33 (pd.DataFrame): Output data with calculated EMA values.
34 """
36 ema_data_df = pd.DataFrame(index = data.index)
37 ema_data_df['ema'] = data['close'].ewm(span = self.__window_size, adjust = False).mean()
39 return ema_data_df
41 def can_be_normalized(self) -> bool:
42 """
43 Checks if the indicator can be normalized.
45 Returns:
46 (bool): True if the indicator can be normalized, False otherwise.
47 """
49 return True