exponential moving average function for Q

I have found the ema function from the kxforums.com. But there issome error. Maybe because of the difference between K and Q. Cananybody help change the function for Q?/ the original function for exponential moving average[code:1]\ema:{a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(a*y)+b*x}\x _ y}[/code:1]I have changed it to the following format, but the “/” maybe shouldalso be replaced:ema:{[x;y] a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(a*y)+b*x}\x _ y};Thanks.Wind

X-Mailer: Apple Mail (2.930.3)Untested, but something like ema:{[x;y]b:1-a:2%x+1;c:(sum x#y)%x; ((x-1)#0n),c,c{a;b;c;d+b*c}[a;b]\x _y} should provide a starting point.On Apr 9, 2009, at 8:10 PM, Wind wrote:>> I have found the ema function from the kxforums.com. But there is> some error. Maybe because of the difference between K and Q. Can> anybody help change the function for Q?>> / the original function for exponential moving average> [code:1]\ema:{a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(a*y)+b*x}\x _ y}> [/code:1]>> I have changed it to the following format, but the “/” maybe should> also be replaced:> ema:{[x;y] a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(a*y)+b*x}\x _ y};>> Thanks.>> Wind> >

X-Mailer: Apple Mail (2.930.3)On Apr 10, 2009, at 11:10 AM, Wind wrote:> ema:{a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(a*y)+b*x}\x _ y}here’s a direct port from to k4:k)ema:{a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{a;b;x;y+b*x}[a;b] \x _ y}k3 must have made locals available to nested lambdas

I copied Nial’s ema function directly. It works well and is exactlywhat I need.Thanks Niall and Aaron.On Apr 10, 11:46?am, Niall Dalton <niall.dal…> wrote:> Untested, but something like ema:{[x;y]b:1-a:2%x+1;c:(sum x#y)%x;> ((x-1)#0n),c,c{a;b;c;d+bc}[a;b]\x _y} should provide a ?> starting point.>> On Apr 9, 2009, at 8:10 PM, Wind wrote:>>>> > I have found the ema function from the kxforums.com. ? But there is> > some error. ? Maybe because of the difference between K and Q. ?Can> > anybody help change the function for Q?>> > / the original function for exponential moving average> > [code:1]\ema:{a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(ay)+bx}\x _ y}> > [/code:1]>> > I have changed it to the following format, but the “/” maybe should> > also be replaced:> > ema:{[x;y] a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(ay)+b*x}\x _ y};>> > Thanks.>> > Wind</niall.dal…>

Date: Fri, 10 Apr 2009 09:30:34 +0100Message-ID: <1855e77f0904100130m1183e050nbeef3b19b4a31d5a@mail.gmail.com>Subject: Re: [personal kdb+] Re: exponential moving average function for QFrom: Attila Vrabecz <attila.vrabecz>To: personal-kdbplus@googlegroups.comm:{((x-1)#0n),i,{z+xy}[i:avg x#y;1-a;(x _y)a:2%1+x]}is a bit fasterq)x:1000000?10fq)\t ema[100;x]750q)\t m[100;x]531 AttilaOn Fri, Apr 10, 2009 at 6:58 AM, Wind wrote:>> I copied Nial’s ema function directly. ?It works well and is exactly> what I need.> Thanks Niall and Aaron.>>> On Apr 10, 11:46?am, Niall Dalton <niall.dal…> wrote:>> Untested, but something like ema:{[x;y]b:1-a:2%x+1;c:(sum x#y)%x;>> ((x-1)#0n),c,c{a;b;c;d+bc}[a;b]\x _y} should provide a>> starting point.>>>> On Apr 9, 2009, at 8:10 PM, Wind wrote:>>>>>>>> > I have found the ema function from the kxforums.com. ? But there is>> > some error. ? Maybe because of the difference between K and Q. ?Can>> > anybody help change the function for Q?>>>> > / the original function for exponential moving average>> > [code:1]\ema:{a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(ay)+bx}\x _ y}>> > [/code:1]>>>> > I have changed it to the following format, but the “/” maybe should>> > also be replaced:>> > ema:{[x;y] a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(ay)+b*x}\x _ y};>>>> > Thanks.>>>> > Wind> >></niall.dal…></attila.vrabecz>

if just want the first one as intial value, one can? use

ewma:{{y+x*z-y}[x:2%1+x][y]}

Xi

?

I tried Xi and Attila’s methods. All are perfect q codes.Thanks again.On Apr 10, 11:26?pm, Xi Chen <heydic…> wrote:> if just want the first one as intial value, one can ?use> ewma:{{y+xz-y}[x:2%1+x][y]}> Xi>> On Fri, Apr 10, 2009 at 9:30 AM, Attila Vrabecz <attila.vrab…>wrote:>>>> > m:{((x-1)#0n),i,{z+xy}[i:avg x#y;1-a;(x _y)a:2%1+x]}> > is a bit faster>> > q)x:1000000?10f> > q)\t ema[100;x]> > 750> > q)\t m[100;x]> > 531> > ?Attila>> > On Fri, Apr 10, 2009 at 6:58 AM, Wind <windspeed…> wrote:>> > > I copied Nial’s ema function directly. ?It works well and is exactly> > > what I need.> > > Thanks Niall and Aaron.>> > > On Apr 10, 11:46 am, Niall Dalton <niall.dal…> wrote:> > >> Untested, but something like ema:{[x;y]b:1-a:2%x+1;c:(sum x#y)%x;> > >> ((x-1)#0n),c,c{a;b;c;d+bc}[a;b]\x _y} should provide a> > >> starting point.>> > >> On Apr 9, 2009, at 8:10 PM, Wind wrote:>> > >> > I have found the ema function from the kxforums.com. ? But there is> > >> > some error. ? Maybe because of the difference between K and Q. ?Can> > >> > anybody help change the function for Q?>> > >> > / the original function for exponential moving average> > >> > [code:1]\ema:{a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(ay)+bx}\x _ y}> > >> > [/code:1]>> > >> > I have changed it to the following format, but the “/” maybe should> > >> > also be replaced:> > >> > ema:{[x;y] a:2%x+1;b:1-a;c:(+/x#y)%x;((x-1)#0n),c{(ay)+bx}\x _ y};>> > >> > Thanks.>> > >> > Wind</niall.dal…></windspeed…></attila.vrab…></heydic…>