Ranges

RDates.RDateRangeType
range(from::Date, rdate::RDate; inc_from=true, cal_mgr=nothing)
range(from::Date, to::Date, rdate::RDate; inc_from=true, inc_to=true, cal_mgr=nothing)

The range provides a mechanism for iterating over a range of dates given a period. This can provide a mechanism for getting an infinite range (from a given date) or appropriately clipped.

julia> collect(Iterators.take(range(Date(2017,1,25), rd"1d"), 3))
3-element Vector{Date}:
 2017-01-25
 2017-01-26
 2017-01-27
julia> collect(Iterators.take(range(Date(2017,1,25), rd"1d"; inc_from=false), 3))
3-element Vector{Date}:
 2017-01-26
 2017-01-27
 2017-01-28
julia> collect(range(Date(2019,4,17), Date(2019,4,22), rd"2d"))
3-element Vector{Date}:
 2019-04-17
 2019-04-19
 2019-04-21

Under the hoods, the range will multiply the period. Since non-periodic RDates will always give back self when you multiply it allows us to set a reference point.

julia> rd"1JAN2001+3m+3rd WED"
1JAN2001+3m[LDOM;PDOM]+3rd WED
julia> 3*rd"1JAN2001+3m+3rd WED"
1JAN2001+9m[LDOM;PDOM]+3rd WED

This provides the basic building blocks to come up with more complex functionality. For example to get the next four IMM dates

julia> d = Date(2017,1,1)
julia> collect(Iterators.take(range(d, rd"1MAR+3m+3rd WED"), 4))
4-element Vector{Date}:
 2017-03-15
 2017-06-21
 2017-09-20
 2017-12-20
source