Posted By: TrumpLost
Laguerre implementation - 04/25/22 04:35
I want to replicate the Laguerre filter in Python for my notebook research, but I don't fully understand how it works. I've read through Ehler's paper but I don't completely understand that either.
The main thing I'm confused about in the lite-C code is this line:
Here's the full code:
And here's a rewrite in Python, which I think is not right.
Would really appreciate some insights as to how L in the original functions. I don't see where L[1] is being assigned a value, are the values inside the L list rolling forward each time this function runs? What does SETSERIES() do? I couldn't find it in the manual. And what is the return value from series(Data[0],8)?
Thanks.
The main thing I'm confused about in the lite-C code is this line:
Code
vars L = series(Data[0],8);
Here's the full code:
Code
var Laguerre(var *Data, var alpha) { vars L = series(Data[0],8); SETSERIES(Data,0); if(alpha > 1.) alpha = smoothF(alpha); var alpha1 = 1.-alpha; L[0] = alpha*Data[0] + alpha1*L[1]; L[2] = -alpha1*L[0] + L[1] + alpha1*L[2+1]; L[4] = -alpha1*L[2] + L[2+1] + alpha1*L[4+1]; L[6] = -alpha1*L[4] + L[4+1] + alpha1*L[6+1]; return (L[0]+2.*L[2]+2.*L[4]+L[6])/6.; }
And here's a rewrite in Python, which I think is not right.
Code
class Laguerre(): def __init__(self, data: pd.Series, period): self.L = np.zeros(8) self.data0 = data[0] self.L[0] = self.data0 if(period > 1): period = smoothF(period) self.period1 = 1 - period def Update(self, price: float): self.L[0] = price * self.data0 + self.period1 * self.L[1] self.L[2] = -self.period1 * self.L[0] + self.L[1] + self.period1 * self.L[2+1] self.L[4] = -self.period1 * self.L[2] + self.L[2+1] + self.period1 * self.L[4+1] self.L[6] = -self.period1 * self.L[4] + self.L[4+1] + self.period1 * self.L[6+1] return (self.L[0] + 2 * self.L[2] + 2 * self.L[4] + self.L[6]) / 6
Would really appreciate some insights as to how L in the original functions. I don't see where L[1] is being assigned a value, are the values inside the L list rolling forward each time this function runs? What does SETSERIES() do? I couldn't find it in the manual. And what is the return value from series(Data[0],8)?
Thanks.