pazzo83 / QuantLib.jl

Quantlib implementation in pure Julia
Other
137 stars 42 forks source link

Backwards schedule bug? #20

Open birgira opened 2 years ago

birgira commented 2 years ago

I am getting wrong schedule output in couple of situations. Here is one example:

  using QuantLib

  effectiveDate = Date(2021,9,15)
  terminationDate =  Date(2032,9,1)
  convention = QuantLib.Time.Unadjusted()
  termDateConvention = QuantLib.Time.Unadjusted()
  cal = QuantLib.Time.TargetCalendar()
  tenor = QuantLib.Time.TenorPeriod(ql.Time.Monthly())

  QuantLib.Time.Schedule(effectiveDate,
                          terminationDate,
                          tenor,
                          convention,
                          termDateConvention,
                          QuantLib.Time.DateGenerationBackwards(), 
                          false,
                          cal).dates

The output starts as follows:

  134-element Vector{Date}:
   2021-09-15
   2021-09-01
   2021-10-01

I.e., there is one too many elements in the output vector (wrongly includes 2021-09-01). The issue lies in the function get_size. Instead of returning Int(ceil(ceil(Dates.value(td - ed) / 30) / Dates.value(p))), it looks like the function should return 12*(Dates.year(td) - Dates.year(ed)) + (Dates.month(td) - Dates.month(ed)) + 1