Moving Median

179 views
Skip to first unread message

Roni Hoffman

unread,
Apr 13, 2018, 10:21:36 AM4/13/18
to Kdb+ Personal Developers
Hello All,

Is there a good way to get the moving median?  I see mavg, but would like to get the moving median by sym and can't quite figure out the best way to do it.  I'm sure its pretty easy but I'm missin it.

Thanks!

Kevin Smyth

unread,
Apr 13, 2018, 10:55:51 AM4/13/18
to personal...@googlegroups.com
Hi Roni,

There is a good general purpose function that Stephen Dempsey posted a few years back based on moving windows:

fwv:{x/'[flip reverse prev\[y-1;z]]}

// Moving median
fwv[med;3;til 10]

// Raw data output
fwv[(::);3;til 10]


Thanks,
Kevin


--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at https://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.

Roni Hoffman

unread,
Apr 13, 2018, 12:11:17 PM4/13/18
to Kdb+ Personal Developers
I see, Thanks Kevn!


On Friday, April 13, 2018 at 10:55:51 AM UTC-4, Kevin Smyth wrote:
Hi Roni,

There is a good general purpose function that Stephen Dempsey posted a few years back based on moving windows:

fwv:{x/'[flip reverse prev\[y-1;z]]}

// Moving median
fwv[med;3;til 10]

// Raw data output
fwv[(::);3;til 10]


Thanks,
Kevin

On 13 April 2018 at 15:21, Roni Hoffman <hoffm...@gmail.com> wrote:
Hello All,

Is there a good way to get the moving median?  I see mavg, but would like to get the moving median by sym and can't quite figure out the best way to do it.  I'm sure its pretty easy but I'm missin it.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbpl...@googlegroups.com.
To post to this group, send email to personal...@googlegroups.com.

Mark Kelly

unread,
Apr 14, 2018, 1:53:55 PM4/14/18
to Kdb+ Personal Developers
update mmed:med each {[w;s] {(neg &[x;count t])#t:y,z}[w]\[s]}[3;price] by sym from quote

time         sym  src   price mmed
----------------------------------
00:00:00.152 APPL GETGO 100   100
00:00:00.179 APPL GETGO 300   200
00:00:00.293 NYSE DB    100   100
00:00:00.378 NYSE SUN   300   200
00:00:00.494 NYSE BARX  100   100
00:00:00.577 APPL GETGO 300   300
00:00:00.951 CAT  GETGO 200   200
00:00:01.041 CAT  GETGO 200   200
00:00:01.149 APPL SUN   100   300
00:00:01.173 NYSE BARX  300   300
00:00:01.194 CAT  DB    200   200
00:00:01.276 NYSE GETGO 50    100
00:00:01.417 GOOG DB    200   200
00:00:01.944 APPL DB    200   200
00:00:02.157 APPL GETGO 100   100
00:00:02.490 GOOG GETGO 300   250
00:00:02.688 CAT  DB    200   200
00:00:02.741 CAT  DB    200   200
00:00:02.809 APPL SUN   200   200
00:00:03.037 NYSE DB    50    50  

This function will work for the first few values of each sym instead of giving nulls
Reply all
Reply to author
Forward
0 new messages