I have below code and I want to do sumproduct. When I do sum(weight) at wj
, it works. But if I do sum(weight*price) at wj
, it failed. How can I do the sumproduct? Thanks!!
t:([]sym:3#`ibm;time:10:01:01 10:01:04 10:01:08;price:100 101 105);
price:101 103 103 104 104 107 108 107 108;
weight:98 99 102 103 103 104 106 106 107;
q:([]sym:`ibm; time:10:01:01+til 9; price:price; weight:weight);
f:`sym`time;
w:-2 1+\:t.time;
wj[w;f;t;(q;(sum;`price);(sum;`weight))]; // OK
wj[w;f;t;(q;(sum;`price);(sum;(*;`price;`weight)))]; // failed
Based on the documentation multi-column argumnents can be passed (since 3.6 2018.12.24), but it does not seem that expressions can be passed. Based on that you should be able to rewrite your calculation as a lambda that accepts multiple columns.
wj[w;f;t;(q;(sum;`price);({sum x*y};`price;`weight))]
sym time price weight
-------------------------
ibm 10:01:01 204 20095
ibm 10:01:04 414 42127
ibm 10:01:08 430 45474