Coverage for source/indicators/donchain_channels_indicator_handler.py: 92%
13 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/donchain_channels_indicator_handler.py
3# global imports
4import pandas as pd
6# local imports
7from source.indicators import IndicatorHandlerBase
9class DonchainChannelsIndicatorHandler(IndicatorHandlerBase):
10 """
11 Implements donchain channels indicator. It indicates the highest and the
12 lowest price for the certain period, creating so called channel. It also
13 calculates average price as the average of the lowest and the highest price.
14 """
16 def __init__(self, window_size: int = 20) -> None:
17 """
18 Class constructor.
20 Parameters:
21 window_size (int): Length of window that indicator should be applied over.
22 """
24 self.__window_size = window_size
26 def calculate(self, data: pd.DataFrame) -> pd.DataFrame:
27 """
28 Calculates donchain channels indicator values for given data.
30 Parameters:
31 data (pd.DataFrame): Data frame with input data.
33 Returns:
34 (pd.DataFrame): Output data with calculated donchain channels values.
35 """
37 donchian_df = pd.DataFrame(index = data.index)
38 donchian_df['dc_up'] = data['high'].rolling(window = self.__window_size, min_periods = 1).max()
39 donchian_df['dc_low'] = data['low'].rolling(window = self.__window_size, min_periods = 1).min()
40 donchian_df['dc_mid'] = (donchian_df['dc_up'] + donchian_df['dc_low']) / 2
42 return donchian_df
44 def can_be_normalized(self) -> bool:
45 """
46 Checks if the indicator can be normalized.
48 Returns:
49 (bool): True if the indicator can be normalized, False otherwise.
50 """
52 return True