How to find the date and price that lowest close price occurs within certain date range ?

83 views
Skip to first unread message

bigbug

unread,
May 16, 2012, 10:46:56 PM5/16/12
to Kdb+ Personal Developers
Hi, there,

I have a table "stk_data" to contain the daily close price for all the
stocks in the market .
sym date close
-------------------------
SH600810 2012.05.17 8.01
SH600810 2012.05.16 7.89
SH600810 2012.05.15 8.1
SH600810 2012.05.14 8.36
SH600810 2012.05.11 8.35
SH600810 2012.05.10 8.16
SH600810 2012.05.09 8.12

And I want to define a function
"find_lowest[stk_data;start_date;end_date]" which output a table that
tells the date and the price that lowest close price occurs within the
period defined by the "start_date" and "end_date" . like this :

sym date_occur close
-------------------------
SH600810 2012.04.03 6.89
SH600732 2012.05.06 20.23
SH600367 2012.04.25 12.50

Can someone help to tell how to write the q code ?

Thanks,
Halley

Fintan Quill

unread,
May 16, 2012, 10:58:57 PM5/16/12
to personal...@googlegroups.com
select from stk_data where date within(start_date;end_date),close=(min;close)fby sym


--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To post to this group, send email to personal...@googlegroups.com.
To unsubscribe from this group, send email to personal-kdbpl...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.


bigbug

unread,
May 16, 2012, 11:20:39 PM5/16/12
to Kdb+ Personal Developers
I try "select from stk_data where date
within(2012.05.16;2012.01.01),close=(min;close) fby sym", but return
table is empty , just display the column name without any data !! (I
check the "stk_data" did have data inside.). Why ?
> >http://groups.google.com/group/personal-kdbplus?hl=en.- 隐藏被引用文字 -
>
> - 显示引用的文字 -

Fintan Quill

unread,
May 16, 2012, 11:24:25 PM5/16/12
to personal...@googlegroups.com
In your example start_date>end_date

Try:
select from stk_data where date within(2012.01.01;2012.05.16),close=(min;close) fby sym 

bigbug

unread,
May 16, 2012, 11:36:49 PM5/16/12
to Kdb+ Personal Developers
Amazing !! Thank you very much. I need to learn more to catch KDB+
capability.
> > > >http://groups.google.com/group/personal-kdbplus?hl=en.-隐藏被引用文字 -

Aaron Davies

unread,
May 17, 2012, 11:51:48 PM5/17/12
to personal...@googlegroups.com
>> select from stk_data where date within(2012.01.01;2012.05.16),close=(min;close) fby sym
>
> Amazing !! Thank you very much. I need to learn more to catch KDB+ capability.

note that the list form (parens and semi-colon) are unnecessary with literals

select from stk_data where date within 2012.01.01 2012.05.16,close=(min;close)fby sym

Attila Vrabecz

unread,
May 19, 2012, 5:31:13 AM5/19/12
to personal...@googlegroups.com
not just unnecessary, but has performance penalty implications
Reply all
Reply to author
Forward
0 new messages