1

I am referring to codes in the below link Identifying Extrema in Financial Data using Pandas

One of the functions has below code

def bear_market(symbol, window=90, correction = .2):
    return pd.rolling_apply(symbol, window, lambda x: x[-1]/x.max() < (1-correction))

it seems rolling_apply is now replaced by rolling in python, but I am still struggling to amend this code

pd.rolling_apply(symbol, window, lambda x: x[-1]/x.max() < (1-correction))

can someone help plz

user13412850
  • 509
  • 1
  • 5
  • 16

1 Answers1

0

Series.rolling() takes the window param and Rolling.apply() takes the lambda:

def bear_market(symbol, window=90, correction=0.2):
    return symbol.rolling(window).apply(lambda x: x[-1]/x.max() < (1-correction))
tdy
  • 36,675
  • 19
  • 86
  • 83