D3F4LT4ST / RL-trading

Forex trading strategy learning with reinforcement learning
7 stars 7 forks source link

TypeError: AroonIndicator.__init__() got an unexpected keyword argument 'close' #1

Closed Chaosqing closed 6 months ago

Chaosqing commented 7 months ago

TypeError Traceback (most recent call last) Cell In[18], line 1 ----> 1 ta_target_features = engineer_forex_features({TARGET : forex_data[TARGET]}, ForexFeEngStrategy.TA, {'lags' : 8})

File D:\RL_EX\RL-trading\rl_trading\data\forex_feature_engineering.py:48, in engineer_forex_features(data, strategy, strategy_params) 46 return _engineer_forex_features_basic(data, strategy_params) 47 elif strategy == ForexFeEngStrategy.TA: ---> 48 return _engineer_forex_features_ta(data, strategy_params)

File D:\RL_EX\RL-trading\rl_trading\data\forex_feature_engineering.py:167, in _engineer_forex_features_ta(data, lags) 164 pair_ta_features[f'<{pair} +DIR>'] = indicator_adx.adx_pos() 165 pair_ta_features[f'<{pair} -DIR>'] = indicator_adx.adx_neg() --> 167 indicator_aroon = AroonIndicator(close=pair_features_df['<CLOSE LAG 1>'], window=25, fillna=True) 168 pair_ta_features[f'<{pair} AROON>'] = indicator_aroon.aroon_indicator() 170 indicator_psar = PSARIndicator( 171 high=pair_features_df['<HIGH LAG 1>'] , 172 low=pair_features_df['<LOW LAG 1>'] , (...) 176 fillna=True, 177 )

TypeError: AroonIndicator.init() got an unexpected keyword argument 'close'

class AroonIndicator(IndicatorMixin): """Aroon Indicator

Identify when trends are likely to change direction.

Aroon Up = ((N - Days Since N-day High) / N) x 100
Aroon Down = ((N - Days Since N-day Low) / N) x 100
Aroon Indicator = Aroon Up - Aroon Down

https://www.investopedia.com/terms/a/aroon.asp

Args:
    high(pandas.Series): dataset 'High' column.
    low(pandas.Series): dataset 'Low' column.
    window(int): n period.
    fillna(bool): if True, fill nan values.
"""

def __init__(
    self, high: pd.Series, low: pd.Series, window: int = 25, fillna: bool = False
):
    self._high = high
    self._low = low
    self._window = window
    self._fillna = fillna
    self._run()

def _run(self):
    # Note: window-size + current time point = self._window + 1
    min_periods = 1 if self._fillna else self._window + 1

    rolling_high = self._high.rolling(self._window + 1, min_periods=min_periods)
    self._aroon_up = rolling_high.apply(
        lambda x: float(np.argmax(x)) / self._window * 100, raw=True
    )

    rolling_low = self._low.rolling(self._window + 1, min_periods=min_periods)
    self._aroon_down = rolling_low.apply(
        lambda x: float(np.argmin(x)) / self._window * 100, raw=True
    )

def aroon_up(self) -> pd.Series:
    """Aroon Up Channel

    Returns:
        pandas.Series: New feature generated.
    """
    aroon_up_series = self._check_fillna(self._aroon_up, value=0)
    return pd.Series(aroon_up_series, name=f"aroon_up_{self._window}")

def aroon_down(self) -> pd.Series:
    """Aroon Down Channel

    Returns:
        pandas.Series: New feature generated.
    """
    aroon_down_series = self._check_fillna(self._aroon_down, value=0)
    return pd.Series(aroon_down_series, name=f"aroon_down_{self._window}")

def aroon_indicator(self) -> pd.Series:
    """Aroon Indicator

    Returns:
        pandas.Series: New feature generated.
    """
    aroon_diff = self._aroon_up - self._aroon_down
    aroon_diff = self._check_fillna(aroon_diff, value=0)
    return pd.Series(aroon_diff, name=f"aroon_ind_{self._window}")
D3F4LT4ST commented 6 months ago

Thanks for catching. I have fixated the ta dependency version. https://github.com/D3F4LT4ST/RL-trading/commit/0fb7654979ab63bd79f13327a863a107ded4b2b9