4

I have a function, f[symbol;date0;date1] , as well as a range of dates, say

2017.12.04
2017.12.05
2017.12.06

I'd like to run this function for a given symbol - assume "AAPL" - once for each day. In essence:

f[AAPL;2017.12.04;2017.12.04]
f[AAPL;2017.12.05;2017.12.05]
f[AAPL;2017.12.05;2017.12.05]

This function returns a table, so I'd like each date to just be appended to the previous results. What might be the best way to do this?

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Fomalhaut -C
  • 320
  • 2
  • 13

2 Answers2

4

The best approach for functions in this form is to use the kdb each-both in its generic form:

d:2017.12.04 2017.12.05 2017.12.06

f'[`AAPL;d;d]

kdb recognises the atomic first argument and list second argument, and applies the function to each in order. You can use raze to join each table in order as well:

raze f'[`AAPL;d;d]

then returns a single joined table, if the schema are the same.

Ryan McCarron
  • 889
  • 4
  • 10
2

assuming f produces identical columns for each call then you can just raze the result

q)f:{([]1#x;1#y;1#z)};
q)raze f'[`a;3#.z.d;3#.z.d-1]
x y          z
-----------------------
a 2018.02.07 2018.02.06
a 2018.02.07 2018.02.06
a 2018.02.07 2018.02.06

the result is a [larger] table with the results appended to each other

Sean O'Hagan
  • 1,681
  • 8
  • 14