How clean the code up so usage is
ema(x, 5) returns the data now in emaout. Im trying to enclose everything in one def.
ex:
def ema(series, period):
return ema
Right now its in a for loop and a def. and would work with numpy array.
x = [32.47, 32.70, 32.77, 33.11, 33.25, 33.23, 33.23, 33.0, 33.04, 33.21]
def ema(series, period, prevma):
smoothing = 2.0 / (period + 1.0)
return prevma + smoothing * (series[bar] - prevma)
prevema = x[0]
emaout =[]
for bar, close in enumerate(x):
curema = ema(x, 5, prevema)
prevema = curema
emaout.append(curema)
print
print emaout