Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: partially SettingWithCopyWarning #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
python3 -m venv venv
. venv/bin/activate
pip install -r requirements-test.txt
pip install pycodestyle
- run:
name: Run linter
command: |
Expand Down
174 changes: 87 additions & 87 deletions ta/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,27 @@ def add_volume_ta(
"""

# Accumulation Distribution Index
df[f"{colprefix}volume_adi"] = AccDistIndexIndicator(
df.loc[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(
df.loc[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(
df.loc[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(
df.loc[f"{colprefix}volume_fi"] = ForceIndexIndicator(
close=df[close], volume=df[volume], window=13, fillna=fillna
).force_index()

# Money Flow Indicator
df[f"{colprefix}volume_mfi"] = MFIIndicator(
df.loc[f"{colprefix}volume_mfi"] = MFIIndicator(
high=df[high],
low=df[low],
close=df[close],
Expand All @@ -119,21 +119,21 @@ def add_volume_ta(
indicator_eom = EaseOfMovementIndicator(
high=df[high], low=df[low], volume=df[volume], window=14, fillna=fillna
)
df[f"{colprefix}volume_em"] = indicator_eom.ease_of_movement()
df[f"{colprefix}volume_sma_em"] = indicator_eom.sma_ease_of_movement()
df.loc[f"{colprefix}volume_em"] = indicator_eom.ease_of_movement()
df.loc[f"{colprefix}volume_sma_em"] = indicator_eom.sma_ease_of_movement()

# Volume Price Trend
df[f"{colprefix}volume_vpt"] = VolumePriceTrendIndicator(
df.loc[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(
df.loc[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(
df.loc[f"{colprefix}volume_vwap"] = VolumeWeightedAveragePrice(
high=df[high],
low=df[low],
close=df[close],
Expand Down Expand Up @@ -168,46 +168,46 @@ def add_volatility_ta(
"""

# Average True Range
df[f"{colprefix}volatility_atr"] = AverageTrueRange(
df.loc[f"{colprefix}volatility_atr"] = AverageTrueRange(
close=df[close], high=df[high], low=df[low], window=10, fillna=fillna
).average_true_range()

# Bollinger Bands
indicator_bb = BollingerBands(
close=df[close], window=20, window_dev=2, fillna=fillna
)
df[f"{colprefix}volatility_bbm"] = indicator_bb.bollinger_mavg()
df[f"{colprefix}volatility_bbh"] = indicator_bb.bollinger_hband()
df[f"{colprefix}volatility_bbl"] = indicator_bb.bollinger_lband()
df[f"{colprefix}volatility_bbw"] = indicator_bb.bollinger_wband()
df[f"{colprefix}volatility_bbp"] = indicator_bb.bollinger_pband()
df[f"{colprefix}volatility_bbhi"] = indicator_bb.bollinger_hband_indicator()
df[f"{colprefix}volatility_bbli"] = indicator_bb.bollinger_lband_indicator()
df.loc[f"{colprefix}volatility_bbm"] = indicator_bb.bollinger_mavg()
df.loc[f"{colprefix}volatility_bbh"] = indicator_bb.bollinger_hband()
df.loc[f"{colprefix}volatility_bbl"] = indicator_bb.bollinger_lband()
df.loc[f"{colprefix}volatility_bbw"] = indicator_bb.bollinger_wband()
df.loc[f"{colprefix}volatility_bbp"] = indicator_bb.bollinger_pband()
df.loc[f"{colprefix}volatility_bbhi"] = indicator_bb.bollinger_hband_indicator()
df.loc[f"{colprefix}volatility_bbli"] = indicator_bb.bollinger_lband_indicator()

# Keltner Channel
indicator_kc = KeltnerChannel(
close=df[close], high=df[high], low=df[low], window=10, fillna=fillna
)
df[f"{colprefix}volatility_kcc"] = indicator_kc.keltner_channel_mband()
df[f"{colprefix}volatility_kch"] = indicator_kc.keltner_channel_hband()
df[f"{colprefix}volatility_kcl"] = indicator_kc.keltner_channel_lband()
df[f"{colprefix}volatility_kcw"] = indicator_kc.keltner_channel_wband()
df[f"{colprefix}volatility_kcp"] = indicator_kc.keltner_channel_pband()
df[f"{colprefix}volatility_kchi"] = indicator_kc.keltner_channel_hband_indicator()
df[f"{colprefix}volatility_kcli"] = indicator_kc.keltner_channel_lband_indicator()
df.loc[f"{colprefix}volatility_kcc"] = indicator_kc.keltner_channel_mband()
df.loc[f"{colprefix}volatility_kch"] = indicator_kc.keltner_channel_hband()
df.loc[f"{colprefix}volatility_kcl"] = indicator_kc.keltner_channel_lband()
df.loc[f"{colprefix}volatility_kcw"] = indicator_kc.keltner_channel_wband()
df.loc[f"{colprefix}volatility_kcp"] = indicator_kc.keltner_channel_pband()
df.loc[f"{colprefix}volatility_kchi"] = indicator_kc.keltner_channel_hband_indicator()
df.loc[f"{colprefix}volatility_kcli"] = indicator_kc.keltner_channel_lband_indicator()

# Donchian Channel
indicator_dc = DonchianChannel(
high=df[high], low=df[low], close=df[close], window=20, offset=0, fillna=fillna
)
df[f"{colprefix}volatility_dcl"] = indicator_dc.donchian_channel_lband()
df[f"{colprefix}volatility_dch"] = indicator_dc.donchian_channel_hband()
df[f"{colprefix}volatility_dcm"] = indicator_dc.donchian_channel_mband()
df[f"{colprefix}volatility_dcw"] = indicator_dc.donchian_channel_wband()
df[f"{colprefix}volatility_dcp"] = indicator_dc.donchian_channel_pband()
df.loc[f"{colprefix}volatility_dcl"] = indicator_dc.donchian_channel_lband()
df.loc[f"{colprefix}volatility_dch"] = indicator_dc.donchian_channel_hband()
df.loc[f"{colprefix}volatility_dcm"] = indicator_dc.donchian_channel_mband()
df.loc[f"{colprefix}volatility_dcw"] = indicator_dc.donchian_channel_wband()
df.loc[f"{colprefix}volatility_dcp"] = indicator_dc.donchian_channel_pband()

# Ulcer Index
df[f"{colprefix}volatility_ui"] = UlcerIndex(
df.loc[f"{colprefix}volatility_ui"] = UlcerIndex(
close=df[close], window=14, fillna=fillna
).ulcer_index()

Expand Down Expand Up @@ -240,54 +240,54 @@ def add_trend_ta(
indicator_macd = MACD(
close=df[close], window_slow=26, window_fast=12, window_sign=9, fillna=fillna
)
df[f"{colprefix}trend_macd"] = indicator_macd.macd()
df[f"{colprefix}trend_macd_signal"] = indicator_macd.macd_signal()
df[f"{colprefix}trend_macd_diff"] = indicator_macd.macd_diff()
df.loc[f"{colprefix}trend_macd"] = indicator_macd.macd()
df.loc[f"{colprefix}trend_macd_signal"] = indicator_macd.macd_signal()
df.loc[f"{colprefix}trend_macd_diff"] = indicator_macd.macd_diff()

# SMAs
df[f"{colprefix}trend_sma_fast"] = SMAIndicator(
df.loc[f"{colprefix}trend_sma_fast"] = SMAIndicator(
close=df[close], window=12, fillna=fillna
).sma_indicator()
df[f"{colprefix}trend_sma_slow"] = SMAIndicator(
df.loc[f"{colprefix}trend_sma_slow"] = SMAIndicator(
close=df[close], window=26, fillna=fillna
).sma_indicator()

# EMAs
df[f"{colprefix}trend_ema_fast"] = EMAIndicator(
df.loc[f"{colprefix}trend_ema_fast"] = EMAIndicator(
close=df[close], window=12, fillna=fillna
).ema_indicator()
df[f"{colprefix}trend_ema_slow"] = EMAIndicator(
df.loc[f"{colprefix}trend_ema_slow"] = EMAIndicator(
close=df[close], window=26, fillna=fillna
).ema_indicator()

# Average Directional Movement Index (ADX)
indicator_adx = ADXIndicator(
high=df[high], low=df[low], close=df[close], window=14, fillna=fillna
)
df[f"{colprefix}trend_adx"] = indicator_adx.adx()
df[f"{colprefix}trend_adx_pos"] = indicator_adx.adx_pos()
df[f"{colprefix}trend_adx_neg"] = indicator_adx.adx_neg()
df.loc[f"{colprefix}trend_adx"] = indicator_adx.adx()
df.loc[f"{colprefix}trend_adx_pos"] = indicator_adx.adx_pos()
df.loc[f"{colprefix}trend_adx_neg"] = indicator_adx.adx_neg()

# Vortex Indicator
indicator_vortex = VortexIndicator(
high=df[high], low=df[low], close=df[close], window=14, fillna=fillna
)
df[f"{colprefix}trend_vortex_ind_pos"] = indicator_vortex.vortex_indicator_pos()
df[f"{colprefix}trend_vortex_ind_neg"] = indicator_vortex.vortex_indicator_neg()
df[f"{colprefix}trend_vortex_ind_diff"] = indicator_vortex.vortex_indicator_diff()
df.loc[f"{colprefix}trend_vortex_ind_pos"] = indicator_vortex.vortex_indicator_pos()
df.loc[f"{colprefix}trend_vortex_ind_neg"] = indicator_vortex.vortex_indicator_neg()
df.loc[f"{colprefix}trend_vortex_ind_diff"] = indicator_vortex.vortex_indicator_diff()

# TRIX Indicator
df[f"{colprefix}trend_trix"] = TRIXIndicator(
df.loc[f"{colprefix}trend_trix"] = TRIXIndicator(
close=df[close], window=15, fillna=fillna
).trix()

# Mass Index
df[f"{colprefix}trend_mass_index"] = MassIndex(
df.loc[f"{colprefix}trend_mass_index"] = MassIndex(
high=df[high], low=df[low], window_fast=9, window_slow=25, fillna=fillna
).mass_index()

# CCI Indicator
df[f"{colprefix}trend_cci"] = CCIIndicator(
df.loc[f"{colprefix}trend_cci"] = CCIIndicator(
high=df[high],
low=df[low],
close=df[close],
Expand All @@ -297,7 +297,7 @@ def add_trend_ta(
).cci()

# DPO Indicator
df[f"{colprefix}trend_dpo"] = DPOIndicator(
df.loc[f"{colprefix}trend_dpo"] = DPOIndicator(
close=df[close], window=20, fillna=fillna
).dpo()

Expand All @@ -315,9 +315,9 @@ def add_trend_ta(
nsig=9,
fillna=fillna,
)
df[f"{colprefix}trend_kst"] = indicator_kst.kst()
df[f"{colprefix}trend_kst_sig"] = indicator_kst.kst_sig()
df[f"{colprefix}trend_kst_diff"] = indicator_kst.kst_diff()
df.loc[f"{colprefix}trend_kst"] = indicator_kst.kst()
df.loc[f"{colprefix}trend_kst_sig"] = indicator_kst.kst_sig()
df.loc[f"{colprefix}trend_kst_diff"] = indicator_kst.kst_diff()

# Ichimoku Indicator
indicator_ichi = IchimokuIndicator(
Expand All @@ -329,10 +329,10 @@ def add_trend_ta(
visual=False,
fillna=fillna,
)
df[f"{colprefix}trend_ichimoku_conv"] = indicator_ichi.ichimoku_conversion_line()
df[f"{colprefix}trend_ichimoku_base"] = indicator_ichi.ichimoku_base_line()
df[f"{colprefix}trend_ichimoku_a"] = indicator_ichi.ichimoku_a()
df[f"{colprefix}trend_ichimoku_b"] = indicator_ichi.ichimoku_b()
df.loc[f"{colprefix}trend_ichimoku_conv"] = indicator_ichi.ichimoku_conversion_line()
df.loc[f"{colprefix}trend_ichimoku_base"] = indicator_ichi.ichimoku_base_line()
df.loc[f"{colprefix}trend_ichimoku_a"] = indicator_ichi.ichimoku_a()
df.loc[f"{colprefix}trend_ichimoku_b"] = indicator_ichi.ichimoku_b()
indicator_ichi_visual = IchimokuIndicator(
high=df[high],
low=df[low],
Expand All @@ -342,14 +342,14 @@ def add_trend_ta(
visual=True,
fillna=fillna,
)
df[f"{colprefix}trend_visual_ichimoku_a"] = indicator_ichi_visual.ichimoku_a()
df[f"{colprefix}trend_visual_ichimoku_b"] = indicator_ichi_visual.ichimoku_b()
df.loc[f"{colprefix}trend_visual_ichimoku_a"] = indicator_ichi_visual.ichimoku_a()
df.loc[f"{colprefix}trend_visual_ichimoku_b"] = indicator_ichi_visual.ichimoku_b()

# Aroon Indicator
indicator_aroon = AroonIndicator(close=df[close], window=25, fillna=fillna)
df[f"{colprefix}trend_aroon_up"] = indicator_aroon.aroon_up()
df[f"{colprefix}trend_aroon_down"] = indicator_aroon.aroon_down()
df[f"{colprefix}trend_aroon_ind"] = indicator_aroon.aroon_indicator()
df.loc[f"{colprefix}trend_aroon_up"] = indicator_aroon.aroon_up()
df.loc[f"{colprefix}trend_aroon_down"] = indicator_aroon.aroon_down()
df.loc[f"{colprefix}trend_aroon_ind"] = indicator_aroon.aroon_indicator()

# PSAR Indicator
indicator_psar = PSARIndicator(
Expand All @@ -360,14 +360,14 @@ def add_trend_ta(
max_step=0.20,
fillna=fillna,
)
# df[f'{colprefix}trend_psar'] = indicator.psar()
df[f"{colprefix}trend_psar_up"] = indicator_psar.psar_up()
df[f"{colprefix}trend_psar_down"] = indicator_psar.psar_down()
df[f"{colprefix}trend_psar_up_indicator"] = indicator_psar.psar_up_indicator()
df[f"{colprefix}trend_psar_down_indicator"] = indicator_psar.psar_down_indicator()
# df.loc[f'{colprefix}trend_psar'] = indicator.psar()
df.loc[f"{colprefix}trend_psar_up"] = indicator_psar.psar_up()
df.loc[f"{colprefix}trend_psar_down"] = indicator_psar.psar_down()
df.loc[f"{colprefix}trend_psar_up_indicator"] = indicator_psar.psar_up_indicator()
df.loc[f"{colprefix}trend_psar_down_indicator"] = indicator_psar.psar_down_indicator()

# Schaff Trend Cycle (STC)
df[f"{colprefix}trend_stc"] = STCIndicator(
df.loc[f"{colprefix}trend_stc"] = STCIndicator(
close=df[close],
window_slow=50,
window_fast=23,
Expand Down Expand Up @@ -405,25 +405,25 @@ def add_momentum_ta(
"""

# Relative Strength Index (RSI)
df[f"{colprefix}momentum_rsi"] = RSIIndicator(
df.loc[f"{colprefix}momentum_rsi"] = RSIIndicator(
close=df[close], window=14, fillna=fillna
).rsi()

# Stoch RSI (StochRSI)
indicator_srsi = StochRSIIndicator(
close=df[close], window=14, smooth1=3, smooth2=3, fillna=fillna
)
df[f"{colprefix}momentum_stoch_rsi"] = indicator_srsi.stochrsi()
df[f"{colprefix}momentum_stoch_rsi_k"] = indicator_srsi.stochrsi_k()
df[f"{colprefix}momentum_stoch_rsi_d"] = indicator_srsi.stochrsi_d()
df.loc[f"{colprefix}momentum_stoch_rsi"] = indicator_srsi.stochrsi()
df.loc[f"{colprefix}momentum_stoch_rsi_k"] = indicator_srsi.stochrsi_k()
df.loc[f"{colprefix}momentum_stoch_rsi_d"] = indicator_srsi.stochrsi_d()

# TSI Indicator
df[f"{colprefix}momentum_tsi"] = TSIIndicator(
df.loc[f"{colprefix}momentum_tsi"] = TSIIndicator(
close=df[close], window_slow=25, window_fast=13, fillna=fillna
).tsi()

# Ultimate Oscillator
df[f"{colprefix}momentum_uo"] = UltimateOscillator(
df.loc[f"{colprefix}momentum_uo"] = UltimateOscillator(
high=df[high],
low=df[low],
close=df[close],
Expand All @@ -445,44 +445,44 @@ def add_momentum_ta(
smooth_window=3,
fillna=fillna,
)
df[f"{colprefix}momentum_stoch"] = indicator_so.stoch()
df[f"{colprefix}momentum_stoch_signal"] = indicator_so.stoch_signal()
df.loc[f"{colprefix}momentum_stoch"] = indicator_so.stoch()
df.loc[f"{colprefix}momentum_stoch_signal"] = indicator_so.stoch_signal()

# Williams R Indicator
df[f"{colprefix}momentum_wr"] = WilliamsRIndicator(
df.loc[f"{colprefix}momentum_wr"] = WilliamsRIndicator(
high=df[high], low=df[low], close=df[close], lbp=14, fillna=fillna
).williams_r()

# Awesome Oscillator
df[f"{colprefix}momentum_ao"] = AwesomeOscillatorIndicator(
df.loc[f"{colprefix}momentum_ao"] = AwesomeOscillatorIndicator(
high=df[high], low=df[low], window1=5, window2=34, fillna=fillna
).awesome_oscillator()

# KAMA
df[f"{colprefix}momentum_kama"] = KAMAIndicator(
df.loc[f"{colprefix}momentum_kama"] = KAMAIndicator(
close=df[close], window=10, pow1=2, pow2=30, fillna=fillna
).kama()

# Rate Of Change
df[f"{colprefix}momentum_roc"] = ROCIndicator(
df.loc[f"{colprefix}momentum_roc"] = ROCIndicator(
close=df[close], window=12, fillna=fillna
).roc()

# Percentage Price Oscillator
indicator_ppo = PercentagePriceOscillator(
close=df[close], window_slow=26, window_fast=12, window_sign=9, fillna=fillna
)
df[f"{colprefix}momentum_ppo"] = indicator_ppo.ppo()
df[f"{colprefix}momentum_ppo_signal"] = indicator_ppo.ppo_signal()
df[f"{colprefix}momentum_ppo_hist"] = indicator_ppo.ppo_hist()
df.loc[f"{colprefix}momentum_ppo"] = indicator_ppo.ppo()
df.loc[f"{colprefix}momentum_ppo_signal"] = indicator_ppo.ppo_signal()
df.loc[f"{colprefix}momentum_ppo_hist"] = indicator_ppo.ppo_hist()

# Percentage Volume Oscillator
indicator_pvo = PercentageVolumeOscillator(
volume=df[volume], window_slow=26, window_fast=12, window_sign=9, fillna=fillna
)
df[f"{colprefix}momentum_ppo"] = indicator_pvo.pvo()
df[f"{colprefix}momentum_ppo_signal"] = indicator_pvo.pvo_signal()
df[f"{colprefix}momentum_ppo_hist"] = indicator_pvo.pvo_hist()
df.loc[f"{colprefix}momentum_ppo"] = indicator_pvo.pvo()
df.loc[f"{colprefix}momentum_ppo_signal"] = indicator_pvo.pvo_signal()
df.loc[f"{colprefix}momentum_ppo_hist"] = indicator_pvo.pvo_hist()

return df

Expand All @@ -502,17 +502,17 @@ def add_others_ta(
pandas.core.frame.DataFrame: Dataframe with new features.
"""
# Daily Return
df[f"{colprefix}others_dr"] = DailyReturnIndicator(
df.loc[f"{colprefix}others_dr"] = DailyReturnIndicator(
close=df[close], fillna=fillna
).daily_return()

# Daily Log Return
df[f"{colprefix}others_dlr"] = DailyLogReturnIndicator(
df.loc[f"{colprefix}others_dlr"] = DailyLogReturnIndicator(
close=df[close], fillna=fillna
).daily_log_return()

# Cumulative Return
df[f"{colprefix}others_cr"] = CumulativeReturnIndicator(
df.loc[f"{colprefix}others_cr"] = CumulativeReturnIndicator(
close=df[close], fillna=fillna
).cumulative_return()

Expand Down