lballabio / QuantLib

The QuantLib C++ library
http://quantlib.org
Other
5.23k stars 1.78k forks source link

FixedRateCoupon not respecting endOfMonth flag on Schedule when creating reference periods for irregular coupons #210

Closed ryantaylor closed 7 years ago

ryantaylor commented 7 years ago

Say I want to price a fixed-rate bond with the following properties:

Issue Date: January 17, 2017
Settlement Date: January 29, 2017
First Coupon Date: February 28, 2017
Maturity Date: February 28, 2018
Day Counter: ISMA Actual/Actual
Business Day Convention: Unadjusted
End of Month: true
Tenor: Semiannual

Currently, QuantLib produces the following legs for this schedule:

#1
lastDate: January 29th, 2017
couponDate: February 28th, 2017
refStartDate: August 28st, 2016
refEndDate: February 28th, 2017

#2
lastDate: February 28th, 2017
couponDate: August 31st, 2017
refStartDate: February 28th, 2017
refEndDate: August 31st, 2017

#3
lastDate: August 31st, 2017
couponDate: February 28th, 2018
refStartDate: August 31st, 2017
refEndDate: February 28th, 2018

#4
lastDate: February 28th, 2018
couponDate: February 28th, 2018
refStartDate: February 28th, 2018
refEndDate: February 28th, 2018

The incorrect value is refStartDate for leg 1; it doesn't respect the endOfMonth flag, which is why it's set to August 28th, 2016 instead of the correct value of August 31st, 2016. This affected the discount factor of the first leg, which in turn causes an incorrect price to be calculated.

I have a simple PR that addresses this one cast (in FixedRateCoupon), but I noticed the problem in a number of other classes. This is the one case I care about right now though, so it's the one case I've put the most effort into.

lballabio commented 7 years ago

Closed by #214.