Questions tagged [q-lang]

The q language is a programming language by kx.com for querying kdb+ databases.

Q was developed by Arthur Whitney in 2003 and is built on top of the K programming language. The names q and kdb+ are often used interchangeably, but generally q refers to the programming language and kdb+ refers to the entire runtime environment.

245 questions
1
vote
1 answer

How to apply function that returns table to a list? (Q+KDB)

I have a function {[x]} that returns a table of time series values. I would like to apply this to different keys `a`b`c but am unable to do so using {[x]}/`a`b`c I'd like the result to be one table with the contents of each individual query. How can…
Fomalhaut -C
  • 320
  • 2
  • 13
1
vote
1 answer

q - cannot load log4q

I would like to use log4q. I downloaded the log4q.q file to my %QHOME% directory. When I try to load the script C:\Dev\q\w32\q.exe -p 5000 q) \l log4q.q I get ' [0] () ) When I try the same in qpad after connecting to localhost server…
tenticon
  • 2,639
  • 4
  • 32
  • 76
1
vote
1 answer

KDB performance: searching first item quicky

I have a sorted list v of around 20K items. I want to split it into 2 lists at the point where first v[i]>K N:20000; v:asc N?100000; / N random numbers sorted K:200; / threshold v1:v[where v<=K]; / "v<=K" has O(N) complexity,…
san
  • 355
  • 2
  • 7
1
vote
1 answer

q - internal state in while loop

In q, I am trying to call a function f on an incrementing argument id while some condition is not met. The function f creates a table of random length (between 1 and 5) with a column identifier which is dependent on the input id: f:{[id] len:(1?1 2…
tenticon
  • 2,639
  • 4
  • 32
  • 76
1
vote
1 answer

KDB column equal sign back tick not working

This query get the column data fromjust two app types -- STEALTH and BOMB US . This query worked fine until I had to isolate the eventtype column to just "AR" events. There is just too much data to not isolate it. I have never seen so much data. …
capser
  • 2,442
  • 5
  • 42
  • 74
1
vote
1 answer

Apply var to the last n numbers of a column in a table

In KDB I have a table with 4 columns, of which one is a returns column. I would like to create a 5th column that calculates the variance (var) of the past x elements of a specified column. I have managed this with two columns creating the returns of…
Sven F.
  • 77
  • 6
1
vote
2 answers

Find timestamp difference in day in kdb

How do you find the time difference in days between 2 timestamp in KDB? For eg. q)d1:2019.02.16D12:16:00.000 q)d2:.z.P how to find difference between these two timestamp in days? q)d1-d2 //in day
HadeS
  • 2,020
  • 19
  • 36
1
vote
1 answer

backtesting in kdb; updating/passing table as we parse each row of table

I have a trade table that contains historical execution records which contains timestamp, ric, side, price, quantity (where ric are all equities). Additionally, I have aj'ed the futures price snapshot table at each execution time. So, the trade…
jeonw
  • 123
  • 8
1
vote
4 answers

How to select the indices of a price series where there is a difference of x bips?

I have a price series and I'd like to know the indices where there has been a change of x bips. I worked out a very ugly way to accomplish this in a loop e.g. q)bips:200 q)level:0.001*bips / 0.2 q)price: 1.0 1.1 1.3 1.8 1.9 2.0…
SkyWalker
  • 13,729
  • 18
  • 91
  • 187
1
vote
3 answers

Add a filter based on other column values in kdb

I have a column containing symbols like EURUSD, USDINR etc. I need to create a new column based on the condition that if any of the first three or last three alphabets of the currency pairs belongs to this list ref: ("INR", "BLR"....) then I have to…
user8415577
1
vote
2 answers

How to optimize a batch pivotization?

I have a datetime list (which for some reason I call it column date) containing over 1k datetime. adates:2017.10.20T00:02:35.650 2017.10.20T01:57:13.454 ... For each of these dates I need to select the data from some table, then pivotize by a…
SkyWalker
  • 13,729
  • 18
  • 91
  • 187
1
vote
2 answers

kdb voolkup. get value from table that is mapped to smallest val larger than x

Assuming I have a dict d:flip(100 200 400 800 1600; 1 3 4 6 10) how can I create a lookup function that returns the value of the smallest key that is larger than x? Given a table tbl:flip `sym`val!(`a`b`c`d; 50 280 1200 1800) I would like to do…
chrise
  • 4,039
  • 3
  • 39
  • 74
1
vote
4 answers

How to get first day of year in KDB/Q?

I'm looking for efficient function to get the first day of year in Q. Like 2017.05.10 -> 2017.01.01 or 2016.08.19 -> 2016.01.01. The next snippet works, but it is not efficient {"D"$(string `year$x),".01.01"} .z.d
Anton Dovzhenko
  • 2,399
  • 11
  • 16
1
vote
2 answers

Recover the order of records

I have a table that in addition to some data has the n column storing the index of the next record. For example, q)show t:([]x:"cbad";n:3 0 1 4) x n --- c 3 b 0 a 1 d 4 I am looking for a method to recover the order of the records from this…
Alexander Belopolsky
  • 2,228
  • 10
  • 26
1
vote
1 answer

Load all records that contain `sym value from splayed tables in directory

I have tables called; quotes, trades and sym saved as splayed tables in a directory called splay in my q directory. I cannot figure out how to load these tables using the methods identified on the code.kx.com website. When I check the file…
L. Mackem
  • 41
  • 4