Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data for a time range in Q/kdb?

I have the following function in q:

{
    raze {[x]
        update PnlTime:x from
            flip ?[getPnl[`date`status!(2013.05.14;`traded)];
            ();();`date`Id`market`pnl!(`date;`Id;`market;x)]
    } each `pnl_0s`pnl_1s`pnl_5s
}

Here, I am retrieving data for a particular date from function getPnl and creating a new column pnl by joining pnl_0s etc. How can I modify this query so as to pass a time range (firstdate;lastdate)?

like image 538
anu Avatar asked Oct 22 '25 07:10

anu


1 Answers

Best answer depends on your table. If this a date-splayed table I'd imagine the best place to do this is inside the getPnl function. Presumably it's doing something like:

select from aTable where date=x,....

Replace with:

select from aTable where date within (d1;d2),...

For a date-splayed table there is no hit for "date=" vs "date within" when d1==d2.

If you don't have access to this function unfortunately you'll need to do another each, something like this:

say d1=2014.01.01, d2=2014.02.14

raze {[x] getPnl[`date`status!(x;`traded)]} each d1,d1+til 1+d2-d1

The last bit does the magic of creating a list of dates from d1 to d2 (inclusive)

like image 186
Manish Patel Avatar answered Oct 24 '25 08:10

Manish Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!