How to generate data by repeating multiple lists? (KDB)

I have a quotes[ticker;startDate;endDate] function and an indexConstituents[index;startDate;endDate] that gives below:

 daterange: 2017.12.05,2017.12.06; quotes'[AAPL;daterange] date time sym price 2017.12.05 09:45 AAPL 101.20 2017.12.06 09:45 AAPL 102.30 quotes'[GOOG;daterange] date time sym price 2017.12.05 10:00 GOOG 800.50 quotes'[BBRY;daterange] date time sym price 2017.12.06 11:15 BBRY 02.10 

and

 indexConstituents'[DJIA;daterange] date sym shares divisor 2017.12.05 AAPL 20 2 2017.12.05 GOOG 5 1 2017.12.06 AAPL 10 1.5 2017.12.06 BBRY 100 1 

I need a way to run the indexConstituents function as normal to get a list of components in a few days (as in the second table above) , then extract the data from table 1 for each component . Finally, I need to combine the data from both tables to get the following:

 data: date time sym price shares divisor 2017.12.05 09:45 AAPL 101.20 20 2 2017.12.06 09:45 AAPL 101.30 10 1.5 2017.12.05 10:00 GOOG 800.50 5 1 2017.12.06 11:15 BBRY 02.10 200 1 

Code for the first two tables:

 ([] date:2017.12.05,2017.12.06; time:09:45,09:45; sym:`AAPL,`AAPL; price:101.20,102.30) ([] date:2017.12.05,2017.12.05,2017.12.06,2017.12.06; sym:`AAPL,`GOOG,`AAPL,`BBRY; shares:20f,5f,10f,100f; divisor:2f,1f,1.5f,1f) 
+4
source share
1 answer

I think the best approach is to assign the resulting table from indexConstituents'[DJIA;daterange] variable so that we can pull out the sym column and apply distinct to it.

You can then use this sim list as the first argument to quotes .

Finally, join the two result tables.

 idx:indexConstituents'[DJIA;daterange]; q:quotes\:/:[distinct idx`sym;daterange]; q lj 2!idx 

Hope this helps!

+2
source

Source: https://habr.com/ru/post/1275238/


All Articles