Getting the third Friday of the month

Here is another possibility:

function get_next_expiry(calc_date:: Date, month:: Integer; holidays:: AbstractArray = [])
    # get 3rd Wednesday of the corresponding month
    expiry_date = Dates.tonext(calc_date + Month(month-1)) do x
       Dates.dayofweek(x) == Dates.Friday && Dates.dayofweekofmonth(x) == 3
    end
    # move to next business day if the day is a holiday - not sure if you need this
    Dates.tonext(expiry_date, same=true) do x
        isbusday(x, holidays=holidays)
    end
end

# get the next 300 3rd Fridays, shifted to next business day if required
expiry_dates = get_next_expiry.(START_DATE, 1:300; holidays=target_holidays)
2 Likes