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
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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.