From 58545b9a7d385c284d567a58a2326f16a3306cd3 Mon Sep 17 00:00:00 2001 From: wangzili Date: Wed, 23 Jan 2019 19:10:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96SMASeries=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E6=95=B0=E6=8D=AE=E9=87=8F=E5=B0=91=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E4=BC=98=E5=8A=BF=EF=BC=8C=E6=95=B0=E6=8D=AE=E9=87=8F=E5=A4=A7?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=9F=E5=BA=A6=E6=8F=90=E5=8D=87=E4=B8=80?= =?UTF-8?q?=E5=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- funcat/func.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/funcat/func.py b/funcat/func.py index aca5846..9fbf32a 100644 --- a/funcat/func.py +++ b/funcat/func.py @@ -75,11 +75,12 @@ class SMASeries(TwoArgumentSeries): """同花顺专用SMA""" def func(self, series, n, _): - results = np.nan_to_num(series).copy() + # results = np.nan_to_num(series).copy() # FIXME this is very slow - for i in range(1, len(series)): - results[i] = ((n - 1) * results[i - 1] + results[i]) / n - return results + # for i in range(1, len(series)): + # results[i] = ((n - 1) * results[i - 1] + results[i]) / n + results = series.fillna(0) + return results.ewm(min_periods=0, ignore_na=False, adjust=False, alpha=1/n).mean() class SumSeries(NumericSeries):