2023.06.04 02:47 AM
I have the below trades table in my q session:
q)meta trades
c | t f a
-----| -----
time | p
sym | s g
src | s g
price| f
size | i
q)
Then, why does it need each both for the sv function when x and y are joined already and then passed into sv:
q)update symsrc:{` sv'(x,'y)}[sym;src] from 1#trades
time sym src price size symsrc
--------------------------------------------------------
2023.06.04D08:00:49.248000000 ORCL L 40.67 3984 ORCL.L
q)update symsrc:{-1 .Q.s1 x,y; ` sv'(x,'y)}[sym;src] from 1#trades
`ORCL`L
time sym src price size symsrc
--------------------------------------------------------
2023.06.04D08:00:49.248000000 ORCL L 40.67 3984 ORCL.L
2023.06.04 03:15 AM - edited 2023.06.04 03:17 AM
You'll get a type error without the each, because you need to create a scalar from each vector (i.e. each pair of symbols)
q)t:([]sym:`ORCL`APPL;src:`L`R)
t
sym src
--------
ORCL L
APPL R
q) update symsrc:` sv (sym,'src) from t
'type
[0] update symsrc:` sv (sym,'src) from t
^
q) update symsrc:` sv'(sym,'src) from t
sym src symsrc
---------------
ORCL L ORCL.L
APPL R APPL.R
Bonus tip - as shown above, you can avoid using a lambda by using parenthesis so the parser doesn't interpret the comma as a new column statement.
2023.06.04 03:29 AM
David has already answered the question here, but it's worth noting that you can do this operation very succinctly using .Q.dd:
q)update symsrc:.Q.dd'[sym;src]from trades
time sym src price size symsrc
--------------------------------------------------------
2023.06.04D10:22:20.088377000 ORCL L 40.67 3984 ORCL.L
2023.06.04 03:15 AM - edited 2023.06.04 03:17 AM
You'll get a type error without the each, because you need to create a scalar from each vector (i.e. each pair of symbols)
q)t:([]sym:`ORCL`APPL;src:`L`R)
t
sym src
--------
ORCL L
APPL R
q) update symsrc:` sv (sym,'src) from t
'type
[0] update symsrc:` sv (sym,'src) from t
^
q) update symsrc:` sv'(sym,'src) from t
sym src symsrc
---------------
ORCL L ORCL.L
APPL R APPL.R
Bonus tip - as shown above, you can avoid using a lambda by using parenthesis so the parser doesn't interpret the comma as a new column statement.
2023.06.04 03:29 AM
David has already answered the question here, but it's worth noting that you can do this operation very succinctly using .Q.dd:
q)update symsrc:.Q.dd'[sym;src]from trades
time sym src price size symsrc
--------------------------------------------------------
2023.06.04D10:22:20.088377000 ORCL L 40.67 3984 ORCL.L
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.