This commit is contained in:
ran 2017-10-31 21:57:58 +02:00 committed by gcarq
parent 2b74982a1d
commit 61f92b7460

View File

@ -248,45 +248,34 @@ def crossed_below(series1, series2):
def rolling_std(series, window=200, min_periods=None): def rolling_std(series, window=200, min_periods=None):
min_periods = window if min_periods is None else min_periods min_periods = window if min_periods is None else min_periods
try: if min_periods == window and len(series) > window:
if min_periods == window: return numpy_rolling_std(series, window, True)
return numpy_rolling_std(series, window, True) else:
else: try:
try: return series.rolling(window=window, min_periods=min_periods).std()
return series.rolling(window=window, min_periods=min_periods).std() except BaseException:
except BaseException: return pd.Series(series).rolling(window=window, min_periods=min_periods).std()
return pd.Series(series).rolling(window=window, min_periods=min_periods).std()
except BaseException:
return pd.rolling_std(series, window=window, min_periods=min_periods)
# --------------------------------------------- # ---------------------------------------------
def rolling_mean(series, window=200, min_periods=None): def rolling_mean(series, window=200, min_periods=None):
min_periods = window if min_periods is None else min_periods min_periods = window if min_periods is None else min_periods
try: if min_periods == window and len(series) > window:
if min_periods == window: return numpy_rolling_mean(series, window, True)
return numpy_rolling_mean(series, window, True) else:
else: try:
try: return series.rolling(window=window, min_periods=min_periods).mean()
return series.rolling(window=window, min_periods=min_periods).mean() except BaseException:
except BaseException: return pd.Series(series).rolling(window=window, min_periods=min_periods).mean()
return pd.Series(series).rolling(window=window, min_periods=min_periods).mean()
except BaseException:
return pd.rolling_mean(series, window=window, min_periods=min_periods)
# --------------------------------------------- # ---------------------------------------------
def rolling_min(series, window=14, min_periods=None): def rolling_min(series, window=14, min_periods=None):
min_periods = window if min_periods is None else min_periods min_periods = window if min_periods is None else min_periods
try: try:
try: return series.rolling(window=window, min_periods=min_periods).min()
return series.rolling(window=window, min_periods=min_periods).min()
except BaseException:
return pd.Series(series).rolling(window=window, min_periods=min_periods).min()
except BaseException: except BaseException:
return pd.rolling_min(series, window=window, min_periods=min_periods) return pd.Series(series).rolling(window=window, min_periods=min_periods).min()
# --------------------------------------------- # ---------------------------------------------
@ -294,12 +283,9 @@ def rolling_min(series, window=14, min_periods=None):
def rolling_max(series, window=14, min_periods=None): def rolling_max(series, window=14, min_periods=None):
min_periods = window if min_periods is None else min_periods min_periods = window if min_periods is None else min_periods
try: try:
try: return series.rolling(window=window, min_periods=min_periods).min()
return series.rolling(window=window, min_periods=min_periods).min()
except BaseException:
return pd.Series(series).rolling(window=window, min_periods=min_periods).min()
except BaseException: except BaseException:
return pd.rolling_min(series, window=window, min_periods=min_periods) return pd.Series(series).rolling(window=window, min_periods=min_periods).min()
# --------------------------------------------- # ---------------------------------------------