Search code examples
kdbq-lang

Finding dates, omitting weekends and holidays


I'm trying to think of the best way to create a function that avoids using loops/while. Any ideas?

Given a function prototype:

{[sd;n:hols]
/ return list of n number of dates <= SD, excluding weekends and hols 

}

Thanks and happy holidays


Solution

  • An alternative solution would exclude the holidays before calculating the modulus:

    {[sd;n;hols] d where 1<mod[d:except[;hols]sd-til n]7}

    The components here are similar to Ryan's answer, other than using "except" to exclude the holidays.

    In order to extract exactly n days, you can initially generate a larger list and return a sublist of the correct length, e.g.

    {[sd;n;hols] n#d where 1<mod[d:except[;hols]sd-til 2*n]7}