如何在每一行上应用函数,并且传入的参数之一是表格

时间:2018-07-20 18:16:55

标签: vectorization apply kdb

我想创建一列,以检查是否可以使用3个列ID在另一个表中找到表的每一行。 x, y and z是表的列,transferrable是第二个表

我尝试过:

elligibleCrossMarginTransfers:{[x;y;z;transferrable]
    potentialTransfers: select from transferrable where marginPctPost>collateralUpperLimitPct,not crossMargin;
    if[1<count select from potentialTransfers where client=x, primeBroker=y,parentPortfolioId=z;
      :1b]; //determine if parentPortfolio of crossMargin exists as possible transfer from other non-cross Margin counts
    :0b
    };
crossMarginNegExcess:update elligibleToTransfer:elligibleCrossMarginTransfers'[client;primeBroker;parentPortfolioId;transferrable] from crossMarginNegExcess

1 个答案:

答案 0 :(得分:2)

您是否正在寻找类似的东西?

q)0N!t:flip `a`b`c!(`a`b`c;1 2 3;10 20 30)
+`a`b`c!(`a`b`c;1 2 3;10 20 30)
a b c
------
a 1 10
b 2 20
c 3 30
q)0N!t2:flip `a`b`c!(`a`B`c;1 -2 3;10 -20 30)
+`a`b`c!(`a`B`c;1 -2 3;10 -20 30)
a b  c
--------
a 1  10
B -2 -20
c 3  30
q)t[`elligibleToTransfer]:(`a`b#t) in `a`b#t2
q)t
a b c  elligibleToTransfer
--------------------------
a 1 10 1
b 2 20 0
c 3 30 1
q)

使用两个示例更新您可以尝试使用的数据(提供一些示例以获得更完整的答案)

crossMarginNegExcess[`elligibleToTransfer]:(`client`primeBroker`parentPortfolioId#crossMarginNegExcess) in select client,primeBroker,parentPortfolioId from transferrable where marginPctPost>collateralUpperLimitPct,not crossMargin
//all qsql
update elligibleToTransfer:1b from `crossMarginNegExcess where ([]client;primeBroker;parentPortfolioId) in select client,primeBroker,parentPortfolioId from transferrable where marginPctPost>collateralUpperLimitPct,not crossMargin