Skip to content

Commit ae201f5

Browse files
committed
updated smma with pandas
1 parent 0853297 commit ae201f5

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

pyti/smoothed_moving_average.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pyti.function_helper import fill_for_noncomputable_vals
55
from six.moves import range
66

7+
import pandas as pd
78

89
def smoothed_moving_average(data, period):
910
"""
@@ -13,8 +14,9 @@ def smoothed_moving_average(data, period):
1314
smma = avg(data(n)) - avg(data(n)/n) + data(t)/n
1415
"""
1516
catch_errors.check_for_period_error(data, period)
16-
smma = [((np.mean(data[idx-(period-1):idx+1]) -
17-
(np.mean(data[idx-(period-1):idx+1])/period) +
18-
data[idx])/period) for idx in range(0, len(data))]
19-
smma = fill_for_noncomputable_vals(data, smma)
20-
return smma
17+
# smma = [((np.mean(data[idx-(period-1):idx+1]) -
18+
# (np.mean(data[idx-(period-1):idx+1])/period) +
19+
# data[idx])/period) for idx in range(0, len(data))]
20+
# smma = fill_for_noncomputable_vals(data, smma)
21+
series = pd.Series(data)
22+
return series.ewm(alpha = 1.0/period).mean().values.flatten()

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
numpy
2+
pandas

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333

3434
packages=find_packages(exclude=['tests']),
3535

36-
install_requires=['numpy'],
36+
install_requires=['numpy', 'pandas'],
3737

3838
)

0 commit comments

Comments
 (0)