Here is the working Python code. It's really slow, especially if applied to lower timeframes, so perhaps what would be useful is an implementation in the form of a numpy extension.
class Laguerre():
def __init__(self, alpha=0.5):
if alpha > 1.0:
self.alpha = smoothF(alpha)
else:
self.alpha = alpha
self.L = None
self.initialized = False
def Update(self, price):
if not self.initialized:
self.L = np.array([price for _ in range(1, 8)])
self.initialized = True
self.L = np.insert(self.L, 0, price, axis=0)[:8]
alpha1 = 1.0-self.alpha
self.L[0] = self.alpha * price + alpha1 * self.L[1]
self.L[2] = -alpha1 * self.L[0] + self.L[1] + alpha1 * self.L[3]
self.L[4] = -alpha1 * self.L[2] + self.L[3] + alpha1 * self.L[5]
self.L[6] = -alpha1 * self.L[4] + self.L[5] + alpha1 * self.L[7]
return (self.L[0] + 2.0 * self.L[2] + 2.0 * self.L[4] + self.L[6]) / 6.0
Here's the notebook snippet where I'm generating the smoothed curve:
L = Laguerre(0.5)
for i, r in df.iterrows():
df.loc[i,'L'] = L.Update(r.Close)
I'm wondering, is the intent of Zorro to be able to do the sort of data research that people are normally using jupyter notebooks for? Because Python is painfully slow, but tools like pandas and numpy are not, and work really well with matplotlib. Any advice is much appreciated.