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

in Q, how to speed up unicoin mining?

There's a new language Q, based on R, which was based on S ... you get the idea. Sadly, Q appears to be very slow in automining unicoins. Plus, Q : we don't have TIME for your little games!
Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
7
votes
1 answer

KDB+ / Q Accessing root namespace from namespace

how can I access functions/variables in the root namespace once I jumped into another namespace. Example like this: q)\d .cfg q)domIV:1000 q)\d . q)n:1000 And then later on I know how to access the variable domIV from the other namespace, but I…
Martin Mlostek
  • 2,755
  • 1
  • 28
  • 57
7
votes
5 answers

KDB; stripping characters from column of symbols

Any ideas how to do this nicely in KDB? Consider the table X:([]a:1 2 3;b:`abc11`abc22`abc33;c:10 20 30) I now want a new table Y that has the "abc" stripped out of the symbols in the second column, such that: Y:([]a:1 2 3;b:`11`22`33;c:10 20 30)
bigO6377
  • 1,256
  • 3
  • 14
  • 28
7
votes
2 answers

Merging sym files for splayed tables

I have two directories that each contain a date-partitioned splayed table. Each directory has its own sym file as expected. The tables are exactly the same. I want to consolidate this into one directory but am having issues doing so. Initially I…
Geoffrey Absalom
  • 1,815
  • 15
  • 16
6
votes
3 answers

How to apply max function for each row in KDB?

I want to ensure all values in column x are no smaller than 0.5, so I do: update x:max (x 0.5) from myTable But this gives an error (in Studio For KDB+): An error occurred during execution of the query. The server sent the response: type Studio…
mchen
  • 9,808
  • 17
  • 72
  • 125
6
votes
2 answers

kdb ticker plant: where to find documentation on .u.upd?

I am aware of this resource. But it does not spell out what parameters .u.upd takes and how to check if it worked. This statement executes without error, although it does not seem to do anything: .u.upd[`t;(`$"abc";1;2;3)] If I define the table…
user443854
  • 7,096
  • 13
  • 48
  • 63
5
votes
3 answers

Passing db path to \l or .Q.l using a variable

I'm writing a q script that loads a db in a particular path and does some processing on it. The location of the db is currently hardcoded in the script, but I want to pass the db path as an argument and get it to load from the path in the…
Sahas
  • 10,637
  • 9
  • 41
  • 51
5
votes
4 answers

kdb q - lookup in nested list

Is there a neat way of looking up the key of a dictionary by an atom value if that atom is inside a value list ? Assumption: The value lists of the dictionary have each unique elements Example: d:`tech`fin!(`aapl`msft;`gs`jpm) / would like to get…
tenticon
  • 2,639
  • 4
  • 32
  • 76
5
votes
1 answer

Unix Timestamp in kdb/q

Is there a built-in way of getting the Unix timestamp in kdb/q? Something like `float$.z.p would be ideal; otherwise I'll have to resort to a more laborious implementation where I count the seconds from Jan 1 1970.
nightTrevors
  • 639
  • 4
  • 11
  • 24
5
votes
1 answer

How to use .year inside function in KDB?

I would like to use dot notation to extract the year of a date. q) myDate:2014.01.01; q) myDate.year 2014i / works OK But when inside a function, f:{[x] :x.year}; f[myDate] I get an error (I use Studio for KDB+) An error occurred during…
mchen
  • 9,808
  • 17
  • 72
  • 125
5
votes
2 answers

How to remove consecutive duplicate rows in KDB?

For instance, if I have the below table, then I want to remove the 3rd row: Stock Price ------------------- GOOG 101 GOOG 102 GOOG 102 <- want to remove this GOOG 101 Note: even though row 4 is a duplicate of row 1, I don't want…
mchen
  • 9,808
  • 17
  • 72
  • 125
4
votes
1 answer

How to generate datatable by iterating through multiple lists? (KDB)

I have a function quotes[ticker;startDate;endDate], and a function indexConstituents[index;startDate;endDate] that yield the below: daterange: 2017.12.05,2017.12.06; quotes'[AAPL;daterange] date time sym price 2017.12.05 09:45 AAPL…
Fomalhaut -C
  • 320
  • 2
  • 13
4
votes
2 answers

Iterate function over list of inputs (Q/KDB)

I have a function, f[symbol;date0;date1] , as well as a range of dates, say 2017.12.04 2017.12.05 2017.12.06 I'd like to run this function for a given symbol - assume "AAPL" - once for each day. In…
Fomalhaut -C
  • 320
  • 2
  • 13
4
votes
2 answers

Apply formula to current and previous rows only (Q/KDB)

I have a formula that I'd like to apply row-by-row, such that only the current and previous rows on any given row are included in calculation. Consider this data: data:([]dt:2017.01.05D19:45:00.238248239 2017.01.05D20:46:00.282382392…
Fomalhaut -C
  • 320
  • 2
  • 13
4
votes
3 answers

Create rolling calculation based unique entries (Q/KDB+)

I have a table: q)data:([]dt:2017.01.05D19:45:00.238248239 2017.01.05D20:46:00.282382392 2017.01.05D21:47:00.232842342 2017.01.05D22:48:00.835838442 2017.01.05D20:49:00.282382392;sym:`AAPL`GOOG`AAPL`BBRY`GOOG;price:101.20 800.20 102.30 2.20…
Fomalhaut -C
  • 320
  • 2
  • 13
1
2 3
16 17