Im having trouble with pct_change giving a future warning. Heres a snippet of the code Im using:
def movers(df_close, idx, df_close_idx):
# df_close is a timeseries dataframe of prices of many tickers/symbols. Earlier dates may have NaN values instead of prices.
# Fill early NaN values with first non-NaN price later in column before calculating percentage changes
df_filled = df_close.bfill()
# Use ffill just in case later NaN values in df
df_filled = df_close.ffill()
# Define the conditions
c4plus = df_filled.pct_change(fill_method=None) >= 0.04
c4minus = df_filled.pct_change(fill_method=None) <= -0.04
c25_3plus = df_filled.pct_change(periods=63, fill_method=None) >= 0.25
c25_3minus = df_filled.pct_change(periods=63, fill_method=None) <= -0.25
c25_1plus = df_filled.pct_change(periods=21, fill_method=None) >= 0.25
c25_1minus = df_filled.pct_change(periods=21, fill_method=None) <= -0.25
c50_1plus = df_filled.pct_change(periods=21, fill_method=None) >= 0.50
c50_1minus = df_filled.pct_change(periods=21, fill_method=None) <= -0.50
c13_34plus = df_filled.pct_change(periods=34, fill_method=None) >= 0.13
c13_34minus = df_filled.pct_change(periods=34, fill_method=None) <= -0.13
The code produces seemingly correct reults, but gives 64(!) future warnings like this (one for each line each time its called in a loop):
... .py:1171: FutureWarning: The 'fill_method' and 'limit' keywords in DataFrame.pct_change are deprecated and will be removed in a future version. Call ffill before calling pct_change instead. c13_34minus = df_filled.pct_change(periods=34, fill_method=None) <= -0.13
Ive tied with/without fill_method=None and limit=None, and am already calling ffill before pct_change, as the warning suggests, and even without df_filled = df_close.ffill() the error still appears.
df_filled = df_close.fillna(method='bfill')
in place of df_filled = df_close.bfill() gives the same warning.
What am I doing wrong?
Thanks!