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
4
votes
1 answer

Weighted avgerage of list columns in kdb

How can I calculate a column of weighted averages from 2 other columns that both have multiple entries per row in kdb? For example, given the following table: T:([]sym:`a`b`c;size:(2 8;5 2 10;3 7);price:(1 2;1 1 10;2 4)) I would like to add the…
CWD
  • 323
  • 1
  • 6
4
votes
2 answers

q - recursion with /

In q, a common illustration for the over operator / is the implementation of fibonacci sequence 10 {x,sum -2#x}/ 1 1 This indeed prints the first 10 fibonacci numbers but doesn't make sense in regards of the definition of the over operator in this…
tenticon
  • 2,639
  • 4
  • 32
  • 76
4
votes
2 answers

q kdb fill missing fxrates

I have a table in kdb with 3 columns: date, currency, fx rate. Some of the fx are missing, and I want to replace the null fx by the value on the previous day, for the same currency obviously. I cannot use fills as it is because it may mix…
curious
  • 65
  • 5
4
votes
2 answers

[KDB+/Q]: Apply list of functions over data sequentially (pipe)

In kdb+/q, how to pipe data through a sequential list of functions so that output of previous step is the input to next step? For example: q)t:([]sym:`a`c`b;val:1 3 2) q)`sym xkey `sym xasc t / how to achieve the same result as…
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
4
votes
2 answers

Kdb - string to double or float

I am trying to convert a string into a double or a float in KDB - the string contains a number with "accounting" format of the like of 2,228,25 (amount) - is I use something like "j"$amount I get 50 44 50 50 56 46 50 53 as a return value. How do I…
GiPoldo
  • 51
  • 1
  • 2
4
votes
2 answers

Loop with EACH in Q KDB+

I've stock trade database (name "TRADES") and I'm trying for a long time to make a simple loop (with function EACH) which would sum all quantities that are above a pre-defined quantity threshold for every ISIN. The data looks like this: q) select…
Linas
  • 43
  • 1
  • 6
4
votes
1 answer

KDB/Q: Why I got length error when select data using vector condition for symbol list?

I have a table: t3:([]a:2 3 4;b:`CA`AB`) I have a query: select from t3 where b in ?[a=2;`CA`AB;`AB] Bong... it give me `length error. But these works: select from t3 where b in ?[a=2;`CA;`AB] select from t3 where b in `CA`AB Cannot think of…
Lance LI
  • 113
  • 3
  • 9
4
votes
1 answer

Sliding window on time in KDB/Q

There are some functions in Q/KDB that let us aggregate on a sliding window (msum, mavg, etc.). But these functions takes the number of previous rows into account. I'd like a function that would aggregate on a sliding window but with time instead of…
Sithered
  • 481
  • 7
  • 23
4
votes
2 answers

How do I perform an efficient left join in kdb?

I want to run a conventional SQL-style left join in KDB+ / Q. We get at least one row in the result for every row in the left table. If there is more than one match in the right table, I get a row for each of those, not just for the first…
JSLover
  • 165
  • 1
  • 10
4
votes
1 answer

How do a simultaneous ascending and descending sort in KDB/Q

In SQL, one can do SELECT from tbl ORDER BY col1, col2 DESC In KDB, one can do `col1 xasc select from tbl or `col2 xdesc select from tbl But how does one sort by col1 ascending then by col2 descending in KDB/Q?
gbronner
  • 1,907
  • 24
  • 39
4
votes
2 answers

KDB: select first n rows from each group

How can I extract the first n rows from each group? For example: for table bb: ([]sym:(4#`a),(5#`b);val: til 9) sym val ------------- a 0 a 1 a 2 a 3 b 4 b 5 b 6 b 7 b 8 How can I select…
ph0603
  • 41
  • 1
  • 3
4
votes
1 answer

Changing the IPython interpreter

I'm using Python with kdb+. To do this I'm using PyQ, which brings Python and kdb+/Q to the same process and allows both languages to operate on the same set of data/memory space. After some effort, I am able to load Python into the kdb+/Q process…
Morten
  • 1,819
  • 5
  • 28
  • 37
4
votes
2 answers

How to stream data in KDB?

I have access to a realtime KDB server that has tables with new data arriving every millisecond. Currently, I'm just using a naive method which is basically like: .z.ts:{ newData: getNewData[]; / get data arriving in the last second …
mchen
  • 9,808
  • 17
  • 72
  • 125
4
votes
3 answers

Downloading FTP files in Q (KDB)

Does anybody know if there is any way to download files from ftp server directly from Q (kdb) ? I know that it's possible to use http but didn't see any examples of using ftp. Seems only way is to write wrapper around something like curl etc, but…
mde
  • 334
  • 4
  • 9
4
votes
1 answer

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…
anu
  • 295
  • 2
  • 7
  • 15
1
2
3
16 17