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!
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!
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
I see, Thanks Kevn!
update mmed:med each {[w;s] {(neg &[x;count t])#t:y,z}[w]\[s]}[3;price] by sym from quotetime 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