QuantLib icon indicating copy to clipboard operation
QuantLib copied to clipboard

Potentially unsafe additions/subtractions of InterestRate objects

Open auto-differentiation-dev opened this issue 3 years ago • 1 comments
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.

boring-cyborg[bot] avatar Jun 24 '22 13:06 boring-cyborg[bot]