q-lang

How to get range of elements in a list in KDB?

泪湿孤枕 提交于 2019-12-11 04:06:27
问题 For example, I have this list: test:(8;12;15;19;10) How may I select elements 2 to 4? When I try list[2;4] it doesn't work for me. 回答1: indexing a list is by far the fastest way. q)a 8 1 9 5 4 6 6 1 8 5 4 9 2 7 0 1 9 2 1 8 8 1 7 2 4 5 4 2 7 8 5 6 4 1 3 3 7 8 2.. q)\t do[100000;2 3 sublist a] 109 q)\t do[100000;a 2 3 4] 15 So just follow your list with a list of indexes. BTW you can create indexes with til q)til 2 0 1 q)2+til 2 2 3 回答2: You can use sublist for this test:(8;12;15;19;10); 2 3

How to produce a formatted date string in Q/KDB?

天大地大妈咪最大 提交于 2019-12-11 01:24:31
问题 How can one produce an ISO date string "yyyy-MM-dd" from a Q date type? I looked at concatenating the various parts but am not even able to get the day/month, e.g. d:2015.12.01;d.month prints 2015.12 , i.e. more than just the month. 回答1: q)"-" sv "." vs string[2015.12.01] "2015-12-01" vs vector from string, splits by "." above; sv string to vector, join by "-" above. Remember a string is just a char array, so you can grab each part as you require with indexing. But the above is useful as the

Changing the IPython interpreter

五迷三道 提交于 2019-12-10 17:10:56
问题 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 on OS X using the instructions from here, i.e. running q python.q [-<python option>@ <python option value>]* python-script This is all good, but I would like to use the above command as interpreter in IPython (Notebook for research, etc.). So, how

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

☆樱花仙子☆ 提交于 2019-12-07 07:08:45
问题 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 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 800.50;shares:500 100 500 900 100) data: dt sym price shares 2017.01.05D19:45:00:238248239 AAPL 101.20 500 2017

How to apply max function for each row in KDB?

[亡魂溺海] 提交于 2019-12-07 05:04:27
问题 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 Hint: Possibly this error refers to wrong type, e.g `a+1 What's wrong? 回答1: You can try using | q)update x|0.5 from myTable 回答2: It should work. It worked for me. This is the query I used for testing: update x:max(x;0.5) from myTable -- Check semicolon

How to join multiple tables

安稳与你 提交于 2019-12-06 13:35:12
问题 I'm trying to join multiple tables in q a b c key | valuea key | valueb key | valuec 1 | xa 1 | xb 2 | xc 2 | ya 2 | yb 4 | wc 3 | za The expected result is key | valuea | valueb | valuec 1 | xa | xb | 2 | ya | yb | xc 3 | za | | 4 | | | wc The can be acheieved simply with (a uj b) uj c BUT does anyone know how i can do it in functional form? I don't know how many tables i actually have I need basically a function that will go over the list and smash any number of keyed tables together... f:{

in Q, how to speed up unicoin mining? [closed]

那年仲夏 提交于 2019-12-05 19:41:56
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . 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! 回答1: Clearly Q is backwards compatible to R so it inherits its speed. This is by design. Happy mining! 来源: https:/

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

↘锁芯ラ 提交于 2019-12-05 15:55:28
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 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 800.50;shares:500 100 500 900 100) data: dt sym price shares 2017.01.05D19:45:00:238248239 AAPL 101.20 500 2017.01.05D20:46:00:282382392 GOOG 800.20 100 2017.01.05D21:47:00:232842342 AAPL 102.30 500 2017.01.05D22

How to apply max function for each row in KDB?

北慕城南 提交于 2019-12-05 07:21:39
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 Hint: Possibly this error refers to wrong type, e.g `a+1 What's wrong? You can try using | q)update x|0.5 from myTable Rahul It should work. It worked for me. This is the query I used for testing: update x:max(x;0.5) from myTable -- Check semicolon in max function Try the kdb vector conditional its similar to case-when in SQL: q)t:([] a:6?.9) q)t a ---

How to join multiple tables

心已入冬 提交于 2019-12-04 18:36:39
I'm trying to join multiple tables in q a b c key | valuea key | valueb key | valuec 1 | xa 1 | xb 2 | xc 2 | ya 2 | yb 4 | wc 3 | za The expected result is key | valuea | valueb | valuec 1 | xa | xb | 2 | ya | yb | xc 3 | za | | 4 | | | wc The can be acheieved simply with (a uj b) uj c BUT does anyone know how i can do it in functional form? I don't know how many tables i actually have I need basically a function that will go over the list and smash any number of keyed tables together... f:{[x] x uj priorx}; f[] each (a;b;c;d;e...) Can anyone help? or suggest anything? Thanks! Another