QuantLib
QuantLib copied to clipboard
Potentially unsafe additions/subtractions of InterestRate objects
trafficstars
InterestRate objects are often added / subtracted in the codebase without first checking if their conventions match. For example, there are several instances of code like this:
mu = riskFreeRate_->forwardRate(t0, t0+dt, Continuous).rate()
- dividendYield_->forwardRate(t0, t0+dt, Continuous).rate();
This is potentially unsafe in cases where both rate objects use different conventions.
As @lballabio suggested in #1413 , it would be safer to implement a custom operator+ and operator- in InterestRate that first checks that conventions match and returns another InterestRate object.
Thanks for posting! It might take a while before we look at your issue, so don't worry if there seems to be no feedback. We'll get to it.