q)D1Bar:2013.07.26 2013.07.29 2013.07.30 2013.07.31 2013.08.01 2013.08.02 2013.08.04 2013.08.05 2013.08.06 2013.08.07 2013.08.08 2013.08.09 2013.08.11 2013.08.12 2013.08.13<o:p></o:p>
q)OpenAsk:1680.4 1686.5 1690.5 1693.9 1703.8 1703.7 1706.1 1707.1 1696.2 1690.2 1698.9 1692.9 1687.6 1684.3 1691.3<o:p></o:p>
<o:p> </o:p>
q)t:(D1Bar;OpenAsk)<o:p></o:p>
<o:p> </o:p>
q)f:{l@'(first z@) @/:y l:neg#/:,[til count y]}<o:p></o:p>
<o:p> </o:p>
q)update max5Date:D1Bar f[5;OpenAsk;idesc],Min5Date:D1Bar f[5;OpenAsk;iasc] from t<o:p></o:p>
<o:p> </o:p>
HTH,<o:p></o:p>
<o:p> </o:p>
Kim<o:p></o:p>
<o:p> </o:p>
Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von Francisco
Gesendet: Sonntag, 16. November 2014 14:29
An: personal-kdbplus@googlegroups.com
Betreff: [personal kdb+] How to calculate the date of max/min value in a number of days?<o:p></o:p>
<o:p> </o:p>
Hello, I have a table t with historical financial data:<o:p></o:p>
<o:p> </o:p>
D1Bar | OpenAsk<o:p></o:p>
----------| --------<o:p></o:p>
2013.07.26| 1680.4<o:p></o:p>
2013.07.29| 1686.5<o:p></o:p>
2013.07.30| 1690.5 <o:p></o:p>
2013.07.31| 1693.9<o:p></o:p>
2013.08.01| 1703.8 <o:p></o:p>
2013.08.02| 1703.7<o:p></o:p>
2013.08.04| 1706.1<o:p></o:p>
2013.08.05| 1707.1 <o:p></o:p>
2013.08.06| 1696.2 <o:p></o:p>
2013.08.07| 1690.2<o:p></o:p>
2013.08.08| 1698.9<o:p></o:p>
2013.08.09| 1692.9<o:p></o:p>
2013.08.11| 1687.6<o:p></o:p>
2013.08.12| 1684.3<o:p></o:p>
2013.08.13| 1691.3<o:p></o:p>
<o:p> </o:p>
And I need to add a column containing the date when OpenAsk was the maximum/minimum value in the last n days.<o:p></o:p>
<o:p> </o:p>
An example with n=5 (calculated by hand);<o:p></o:p>
<o:p> </o:p>
D1Bar | OpenAsk Max5Date Min5Date <o:p></o:p>
----------| ------------------------------<o:p></o:p>
2013.07.26| 1680.4 2013.07.26 2013.07.26<o:p></o:p>
2013.07.29| 1686.5 2013.07.29 2013.07.26<o:p></o:p>
2013.07.30| 1690.5 2013.07.30 2013.07.26 <o:p></o:p>
2013.07.31| 1693.9 2013.07.31 2013.07.26<o:p></o:p>
2013.08.01| 1703.8 2013.08.01 2013.07.26<o:p></o:p>
2013.08.02| 1703.7 2013.08.01 2013.07.29<o:p></o:p>
2013.08.04| 1706.1 2013.08.04 2013.07.30<o:p></o:p>
2013.08.05| 1707.1 2013.08.05 2013.07.31<o:p></o:p>
2013.08.06| 1696.2 2013.08.05 2013.08.06<o:p></o:p>
2013.08.07| 1690.2 2013.08.05 2013.08.07<o:p></o:p>
2013.08.08| 1698.9 2013.08.05 2013.08.07<o:p></o:p>
2013.08.09| 1692.9 2013.08.05 2013.08.07<o:p></o:p>
2013.08.11| 1687.6 2013.08.08 2013.08.11<o:p></o:p>
2013.08.12| 1684.3 2013.08.08 2013.08.12<o:p></o:p>
2013.08.13| 1691.3 2013.08.08 2013.08.12<o:p></o:p>
<o:p> </o:p>
How can it be done?<o:p></o:p>
<o:p> </o:p>
Thanks in advance<o:p></o:p>
<o:p> </o:p>
Francisco<o:p></o:p>
<o:p> </o:p>
–
Submitted via Google Groups