Hi,
I have a historical table that contains date,ticker and price.
Something like this:
date ticker price
2009.04.06 XTZZ 9.265474
2009.04.07 XTZZ 10.65305
2009.04.08 XTZZ 11.73893
2009.04.09 XTZZ 11.63868
2009.04.10 XTZZ 11.48626
2009.04.13 XTZZ 12.57714
2009.04.14 XTZZ 14.28168
2009.04.15 XTZZ 15.07652
2009.04.16 XTZZ 13.20755
2009.04.17 XTZZ 13.40342
2009.04.20 XTZZ 13.79763
2009.04.21 XTZZ 14.54784
2009.04.22 XTZZ 14.91569
2009.04.23 XTZZ 14.53736
2009.04.24 XTZZ 14.53898
2009.04.27 XTZZ 15.57032
2009.04.28 XTZZ 16.87014
…
I would like to go through each row in the table and for each date,ticker want to get the date of max,min price in the past 15 days. # of days can be any, for now 15 days.
I have something like this:
t: update maxdate:({{[t;r] t:select from t where ticker=rticker,date within -15 0+r
date; exec first date from t where price=max price}'} t) from t
So I will have an output as:
date ticker price maxdate
2009.04.06 XTZZ 9.265474 2009.04.06
2009.04.07 XTZZ 10.65305 2009.04.07
2009.04.08 XTZZ 11.73893 2009.04.08
2009.04.09 XTZZ 11.63868 2009.04.08
2009.04.10 XTZZ 11.48626 2009.04.08
2009.04.13 XTZZ 12.57714 2009.04.13
2009.04.14 XTZZ 14.28168 2009.04.14
2009.04.15 XTZZ 15.07652 2009.04.15
2009.04.16 XTZZ 13.20755 2009.04.15
2009.04.17 XTZZ 13.40342 2009.04.15
2009.04.20 XTZZ 13.79763 2009.04.15
2009.04.21 XTZZ 14.54784 2009.04.15
2009.04.22 XTZZ 14.91569 2009.04.15
2009.04.23 XTZZ 14.53736 2009.04.15
2009.04.24 XTZZ 14.53898 2009.04.15
…
This works but looks like it’s taking very very long to compute for a table with about 2 mil rows.
Is there a better/faster way to compute this?
Thanks and appreciate your help!