def add_volume_ta(df: pd.DataFrame, high: str, low: str, close: str, volume: str, fillna: bool = False, colprefix: str = "") -> pd.DataFrame: """Add volume technical analysis features to dataframe. Args: df (pandas.core.frame.DataFrame): Dataframe base. high (str): Name of 'high' column. low (str): Name of 'low' column. close (str): Name of 'close' column. volume (str): Name of 'volume' column. fillna(bool): if True, fill nan values. colprefix(str): Prefix column names inserted Returns: pandas.core.frame.DataFrame: Dataframe with new features. """ # Accumulation Distribution Index df[f'{colprefix}volume_adi'] = AccDistIndexIndicator( high=df[high], low=df[low], close=df[close], volume=df[volume], fillna=fillna).acc_dist_index() # On Balance Volume df[f'{colprefix}volume_obv'] = OnBalanceVolumeIndicator( close=df[close], volume=df[volume], fillna=fillna).on_balance_volume() # Chaikin Money Flow df[f'{colprefix}volume_cmf'] = ChaikinMoneyFlowIndicator( high=df[high], low=df[low], close=df[close], volume=df[volume], fillna=fillna).chaikin_money_flow() # Force Index df[f'{colprefix}volume_fi'] = ForceIndexIndicator( close=df[close], volume=df[volume], n=13, fillna=fillna).force_index() # Money Flow Indicator df[f'{colprefix}volume_mfi'] = MFIIndicator( high=df[high], low=df[low], close=df[close], volume=df[volume], n=14, fillna=fillna).money_flow_index() # Ease of Movement indicator = EaseOfMovementIndicator(high=df[high], low=df[low], volume=df[volume], n=14, fillna=fillna) df[f'{colprefix}volume_em'] = indicator.ease_of_movement() df[f'{colprefix}volume_sma_em'] = indicator.sma_ease_of_movement() # Volume Price Trend df[f'{colprefix}volume_vpt'] = VolumePriceTrendIndicator( close=df[close], volume=df[volume], fillna=fillna).volume_price_trend() # Negative Volume Index df[f'{colprefix}volume_nvi'] = NegativeVolumeIndexIndicator( close=df[close], volume=df[volume], fillna=fillna).negative_volume_index() # Volume Weighted Average Price df[f'{colprefix}volume_vwap'] = VolumeWeightedAveragePrice( high=df[high], low=df[low], close=df[close], volume=df[volume], n=14, fillna=fillna ).volume_weighted_average_price() return df
def test_sma_ease_of_movement2(self): target = 'SMA_EMV' result = EaseOfMovementIndicator(high=self._df['High'], low=self._df['Low'], volume=self._df['Volume'], n=14, fillna=False).sma_ease_of_movement() pd.testing.assert_series_equal(self._df[target].tail(), result.tail(), check_names=False)
def setUpClass(cls): cls._df = pd.read_csv(cls._filename, sep=',') cls._params = dict(high=cls._df['High'], low=cls._df['Low'], volume=cls._df['Volume'], n=14, fillna=False) cls._indicator = EaseOfMovementIndicator(**cls._params)
def setUpClass(cls): cls._df = pd.read_csv(cls._filename, sep=",") cls._params = dict( high=cls._df["High"], low=cls._df["Low"], volume=cls._df["Volume"], window=14, fillna=False, ) cls._indicator = EaseOfMovementIndicator(**cls._params)