2,212 questions
1
vote
2
answers
68
views
enumerating contiguous ones in kdb+
Given a list of 0s and 1s, say l: 0 0 1 1 1 0 0 1 1 I would like to get a sequence beginning with 1 for each contiguous set of 1s. Thus the required output should be l: 0 0 1 2 3 0 0 1 2. How can I ...
0
votes
3
answers
44
views
adding to a column which is list of symbols and finding right datatype from meta information
I have a table which has 2 columns whose elements are list of symbols. I want to modify one of these columns to append a symbol to existing list of symbols, how can i do it ?
/Table with 2 columns ...
0
votes
2
answers
63
views
How can I close over variables in kdb/Q?
Consider the following function that adds 1 to each element in the list.
f : {{x + 1} each x}
f[(1;2;3)]
2 3 4
However, the following function does not work -- I'm assuming that the incr identifier ...
1
vote
1
answer
81
views
What type of composition is (count 1 2 3,)
I understand (count 1 2 3,) is a composition, because I see its type is 105.
q)type(count 5 6,)
105h
Initially I thought this is an example of implicit composition, which
Compose one or more unary ...
0
votes
4
answers
94
views
Return value from list of list when criteria met in KDB
I have a list of list which has 4 columns. Now I want to iterate over each list in list of list to find the first list which has say value ABC for first column and value XYZ for 3rd col. If this ...
-1
votes
2
answers
45
views
How to map nested list elements to corresponding ids creating a uid table column?
Two variables:
q) indexList
,1452750
,966036
,1125386
,1450294
,1450293
,1452030
,1570712
421818 421840 421897 421988 422026 422059 422084
851199 851271
695902 695928
,933185
679878 679882 679886 ...
0
votes
1
answer
60
views
(q/kdb+) How to group data with slight date discrepancies (+/-1 day) for unique identifier creation
I am trying to create uniqueid column for each child (as they appear more than once in the table) so that I can identify between children with same name (no child has the same dadname, mumname and ...
-1
votes
2
answers
79
views
kdb+/q: Select all data within a given range from another table
Consider the following two tables, table_a and table_b. table_a has data for an entire day, and table_b has data within certain ranges.
The question is: how can I get entries from table_a which fall ...
0
votes
1
answer
46
views
filtering columns that have lists for rows based on other scalar columns in kdb
w:(1 2;3 4;5 2); l:til count w; h:l+1;
show t:([] l; h; w);
l h w
-------
0 1 1 2
1 2 3 4
2 3 5 2
I have a table t with a column w which has lists for rows. I would like to only keep elements in ...
2
votes
3
answers
97
views
How to update values from null to 0 dynamically?
Input:
Name
Maths
Science
Dena
95
Karan
90
97
Jack
We need to update values from null to 0 dynamically in KDB qsql.
I'd like to use a functional qsql query in KDB.
Expected output:
Name
Maths
...
0
votes
1
answer
57
views
Kdb DbMaint from symbol to symbol List
I have an existing symbol column in HDB and want to cast that to a symbol list, can anyone advise what is the best way of doing that?
I know that adding a column is as follows:
.ds.hdb.addCol[`:.;`tab;...
0
votes
1
answer
81
views
Exploding kdb column of key:value pairs into multiple ones
I have a kdb table with a format that could be summarized with
app type labels
--------------------------------------------------------
app1 frontend ("language:js";"owner:bob"...
0
votes
1
answer
46
views
extracting info from a table column which is a list of lists in kdb
I have the following linear regression functions
// linear regression y vs x
// returns: intercept slope
linear:{
if[not (count x)=(count y); show "x and y must have the same length"; ...
3
votes
1
answer
85
views
vectorized kdb/q function from c++ loops
Here's c++ code to calculate pivot highs, containing two nested for loops:
std::vector<double>
pivothigh(const std::vector<double> &src,
const unsigned int left,
...
0
votes
1
answer
67
views
find ranked local extrema in kdb
I'm trying to find k: the local maxima and minima in a list a enlosed in the table t below. Further, I'd like to rank the minima and maxima based on a but only relative to other maxima and minima as ...
0
votes
2
answers
67
views
Create new column based on comparing last two rows for a specific order ID in a kdb+ table
There is a table that exists with many entries for unique orderIDs, (i.e. unique orderID 123 can have N number of entries). I wanted to compare the last 2 entries for each unique orderID that I have, ...
0
votes
1
answer
75
views
Obtaining non-overlapping trades in kdb
I've a table t as
q)trades: ([]
signalTime: 2024.01.05 2024.01.12 2024.01.19 2024.01.25 2024.02.02 2024.02.09 2024.02.16 2024.02.23 2024.03.01 2024.03.07;
exitTime: 2024.01.25 2024.02.01 2024....
0
votes
2
answers
91
views
Rolling sum of a column by sym in KDB table
Trying to reverse engineer a line of qsql code or write a function to get the result of the rcc column in the below table. I know it's the rolling creditNettingValue by sym, however struggling with ...
0
votes
1
answer
61
views
How would changing a folder that a symlink points to affect a running app?
I don't know how to search for this online.
I am doing regular deployments every week.
I have a folder structure like this
folder1/myApp_tps_20240928_DEV/<app_code_here>
folder1/...
0
votes
2
answers
61
views
trouble with rescaling function
I have a table t
t:([] x: 1 2 3 4 5; y: 5.1 2.4 3.3 4.5 1.5);
x y
-----
1 5.1
2 2.4
3 3.3
4 4.5
5 1.5
and I'm trying to rescale the x and y rows of t such that the larger one becomes 1 and the ...
0
votes
1
answer
89
views
Namespace behavior in kdb
I have a file in KDB project which only has namespace declared in it. e.g
.file.namespace1:`someValue;
.file.namespace2.dict: flip `value1`value2`value3!(`I;20;200);
.file.namespace3.dict: flip `...
0
votes
1
answer
70
views
Update column value based on mapping table
I have the following table
tab:([]exec_location_1:`PA1`DNS`DNS;quantity_s9:8 40 20;mf_quantity_s17:123 123 4;eq_quantity_s17:10 20 30)
and I need to update it with a new column quantity which is based ...
0
votes
1
answer
87
views
How to efficiently exclude not null values of list of floats and ints from tables for multiple tables and dynamic cols
How to efficiently exclude not null values of list of floats and ints from tables for multiple tables and dynamic cols
tab1:update volume:0n from ([] date:2024.01.01+til 10;sym:10?`appl`msgt`googl;...
0
votes
1
answer
73
views
kdb - lj 3 tables on key column
is anyone able to tell me if there is an efficient way to left join 3 tables on orderID column?
for uj I tried the following which is fine:
() uj/(a;b;c)
but can we do similar for a lj with xkey over ...
0
votes
0
answers
70
views
Vectorising an iterative implied volatility function
I'd like to calculate the implied volatility (IV) of a table t containing an option chain.
The function to calculate the IV is:
// Newton-Raphson method to find implied volatility
impliedVol:{[S;K;T;r;...
0
votes
3
answers
92
views
Convert a column of dictionary datatype to table in kdb
I was trying to convert a column which has a dictionary datatype on a table to a separate table to fetch information from it easily. This works with a simple uj for me when the dictionaries have the ...
0
votes
1
answer
70
views
KDB+ DB maintenance
in my table I am seeing mixed datatypes which I want to fix by running dbmaint
I need to make sure that eventType holds a list of symbols so anything that doesnt match that needs ran against db maint ...
0
votes
1
answer
64
views
A compiled list of different functionality kdb provide via ! operators along with negitive numbers ( e.g -11! `tplogs)
I am looking to find list of different functionality that kdb provides via different calls such as -11! ( replay logs ), -26! ( SSL details )... etc.. I want to see if there is a place where I can ...
0
votes
1
answer
99
views
SET SSL_VERIFY as NO to download CSV file from KDB
I have kdb 64 bit installed on windows and wanted to run below kdb command to download a csv file and load it as table into data variable.
q)("**III";1#",") 0: "\n" vs .Q....
0
votes
1
answer
70
views
Cast column types for a table sourced from json
I parsed a json table and I ended up with many columns of mixed type.
([]col1:("tet1";"test2";());col2:(234j;0b;33j);col3:("sda";0b;"");col4:(0b;"";&...
0
votes
2
answers
104
views
Improving efficiency of uj in kdb for a large table
I have a not so massive table. About 500k records.
But it is a nested JSON.
I have to load it, parse it and flatten the dict (each row is a dict and can have different depths)
This takes quite some ...
0
votes
1
answer
66
views
Trying to loading a csv file into a q table via remote connection and keep getting - '/
I am using the example here to load a csv file...
https://code.kx.com/q/learn/tour/csvs/
But changed it slightly as I need to do this via a remote connection.
I know the file is where it needs to be......
0
votes
1
answer
75
views
how to use amend in update statement
We have a table tab
tab:update volume:0n from ([] date:2024.01.01+til 10;sym:10?`appl`msgt`googl;volume:10#(enlist 0.5+300?til 100)) where i in (1;5;8);
We want to update the column volume such a way ...
0
votes
1
answer
101
views
How do we update a table column which is list type based on list indices range
How do we update a table column which is list type based on list indices range
sample table
tab:([] date:2024.01.01+til 30;sym:30?`appl`msgt`googl;volume:30#(enlist 0.5+300?til 100));
Lets just work ...
0
votes
1
answer
72
views
Fail to load library in KDB kernel jupyter notebook
I have installed the arrowkdb library, and use it to load parquet files in KDB. My $QHOME directory now contains:
├── kc.lic
├── arrowkdb.q
├── l64
│ ├──arrowkdb.so
│ └── q
└── q.k
But when use \...
0
votes
4
answers
105
views
use reverse rank in a fby statement
How does one accomplish a reverse rank in an fby?
In the below, how would we select the two largest values of col2 by date?
q)dt: 2024.05.13 2024.05.17 2024.05.16 2024.05.17 2024.05.14 2024.05.13 2024....
0
votes
1
answer
102
views
Compare two tables row wise using Q/kdb
I would like to compare data from two tables with same columns. What I think is I can use match operator (~) between the tables in each row of those tables, however, If the table size is big I am ...
0
votes
1
answer
103
views
kdb+/q When to actually reload the hdb?
In most kdb systems its typical to reload the hdb (\l .) after any data persistence has occurred. With larger hdbs, this reload can sometimes be costly especially when there are multiple flat files.
...
0
votes
1
answer
89
views
kdb q functional select variable as symbol or not
With the following:
q)t:([] e:1 2 3 4 5 6; a:0 0 1 2 3 4; b: 1 2 0 0 3 4; c:1 2 3 4 0 1)
q)t
e a b c
-------
1 0 1 1
2 0 2 2
3 1 0 3
4 2 0 4
5 3 3 0
6 4 4 1
q)colist: `a`b`c
q)colist
`a`b`c
...
0
votes
1
answer
59
views
k) portion of parse tree of user defined function
In the below, why does the eval fail but the value works?
Also, what exactly is the k){x'y} part of the parse output and why did I have to enclose it in quotes for the value statement to work?
q)...
0
votes
1
answer
73
views
kdb/q How do I change all values of 0n in table column?
I am originally trying to save a table in kdb, but I was getting a type error:
q)save `:tbl.csv
'type
[14] save `:tbl.csv
^
When I looked up the reason for why this might be the case, it ...
2
votes
1
answer
104
views
How to select distinct by max value of other column
I have the following code:
select count i by sym, typ from tbl;
Which returns the following:
| sym | typ | x |
-------------------
| ABC | A | 122 |
| ABC | B | 37 |
| JKL | C | 19 |
| XYZ |...
0
votes
3
answers
115
views
how to ssr more than one string in a table at the same time
I would like to replace for more than one condition:
Example:
tab:([]a:`a`b`c;b:("abc-d";"rdf,e";"ertfg"))
update b:{ssr[x;"-"|",";" "]} ...
0
votes
3
answers
83
views
Union of list of dictionaries in KDB
I am trying to join an arbitrarily long list of dictionaries into one dictionary where matching keys will take the union of distinct values and new keys are simply inserted. Is there a way to do that ...
0
votes
1
answer
87
views
Incompatible list lengths when passing a list of symbols into function parameter?
I have a function that filters on a master table as the below:
condSel:{[tabl;colNames;colValues]
wc: {(in;x;enlist y)}.'flip(colNames;colValues);
res: ?[tabl;wc;0b;()];
res
I can apply ...
0
votes
1
answer
71
views
kdb/q xdesc on table, within primary id
I'm trying to get a single line item per id with the largest count, like below:
Primary
Name
Count
1a
AXA
11
1a
FLO
1
1a
FLO
60
1a
AXA
14
2e
AXA
1
2e
ROT
1
2e
ROT
6
2e
ROT
4
tb: ([] Primary:`...
0
votes
2
answers
66
views
a list of N subsequent elements in KDB
Given the table t: ([] a: 1 2 3 4), how can one obtain the column b for e.g.,
n=2
a b
-----
1 1 2
2 2 3
3 3 4
4 ,4
n=3
a b
-------
1 1 2 3
2 2 3 4
3 3 4
4 ,4
where n is the number of subsequent ...
0
votes
3
answers
124
views
Why is SUM not ignoring NULLs in functional form?
I have the following bit of code inside a functional select argument:
a: (enlist col)!enlist(sum;(enlist,`dealsA`dealsB`dealsC));
However, if any value within the three columns I am attempting to sum ...
0
votes
1
answer
60
views
fills on empty sub lists in KDB
Consider a table containing a column a which is a list of lists as
q) show t: ([] a: ((1;2); (); (); (5;6); (); ()));
a
---
1 2
()
()
5 6
()
()
I'm having trouble filling the empty sublists () ...
0
votes
1
answer
91
views
How can I dynamically update column names within a function?
I built a table selector that can produce many tables from a master table by filtering on a specific column that I desire with the required values.
I would like the columns of the table, i.e. '...