Skip to content

Commit

Permalink
add skipna para in moving_average to fix bug mlouielu#44
Browse files Browse the repository at this point in the history
  • Loading branch information
machineCYC committed Mar 27, 2019
1 parent cddddcc commit 84e57c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/reference/analytics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
:type data: list
:param days: 天數
:type days: int
:param skipna: 是否過濾缺失資料
:type: bool

分析 ``data`` 中之 ``days`` 日之平均數::

Expand Down
5 changes: 4 additions & 1 deletion twstock/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def continuous(self, data):
break
return cont * diff[0]

def moving_average(self, data, days):
def moving_average(self, data, days, skipna=True):
if skipna:
data = [x for x in data if x is not None]

result = []
data = data[:]
for _ in range(len(data) - days + 1):
Expand Down

0 comments on commit 84e57c7

Please sign in to comment.