Login  Register

DiscountCurve

Posted by Ferdinando M. Ametrano-2 on Apr 24, 2002; 10:59am
URL: http://quantlib.414.s1.nabble.com/DiscountCurve-tp10053.html

Hi Andre

I did a few changes on TermStructures. I also did a few changes to
DiscountCurve:
1) 2 new methods:
            const std::vector<Date>& dates() const;
            const std::vector<Time>& times() const;
2) required sorted dates and decreasing discount factors in the constructor
3) removed forwardImpl and zeroYieldImpl. Now DiscountCurve uses these
methods as inherited by DiscountStructure

Point 3 is the most important. Taking a look at your implementation of
forwardImpl and zeroYieldImpl I spotted some inconsistencies with the
TermStructures interface, mainly the fact that forward(Date, bool) must
return an annual continuous compounded rate.
In TermStructure zero and forward rates are assumed to be continuous
compounded rates: this is probably an error we did in the original design,
but unless we fix it everywhere this is the way to go.

Please let me know if after my patch DiscountCurve still works the way you
wanted. I can always roll back my patch if needed.

I would also like to introduce another change: I would require the user to
provide a discount grid starting with the first discount equal to 1.00, so
that we can assume that the first date is the settlement date. I think this
would be safer. Here's what I have in mind:
         DiscountCurve::DiscountCurve(const Date & todaysDate,
             const Calendar & calendar, const DayCounter & dayCounter,
             Currency currency, const std::vector < Date > &dates,
             const std::vector < DiscountFactor > &discounts)
         : todaysDate_(todaysDate), settlementDate_(dates_[0]),
           calendar_(calendar), dayCounter_(dayCounter),
           currency_(currency), dates_(dates), discounts_(discounts) {

              QL_REQUIRE(dates.size()>1, "DiscountCurveDiscountCurve :"
                 " too few dates");
              QL_REQUIRE(discounts_[0]==1.0, "DiscountCurveDiscountCurve :"
                 " invalid first discount, not equal to one");
              QL_REQUIRE(todaysDate_<=settlementDate_,
                 "DiscountCurveDiscountCurve :"
                 " today's date greater than settlement date");

              times_.resize(dates.size());
              times_[0]=0.0;

              for(Size i = 1; i < dates.size(); i++) {
                  QL_REQUIRE(dates_[i]>dates_[i-1],
                     "DiscountCurveDiscountCurve : invalid date");
                  QL_REQUIRE(discounts_[i]<=discounts_[i-1],
                     "DiscountCurveDiscountCurve : invalid discount");
                  times_[i] = dayCounter_.yearFraction(settlementDate_,
                     dates_[i]);
              }

             interpolation_ = Handle < DfInterpolation >
                 (new DfInterpolation(times_.begin(), times_.end(),
                 discounts.begin(), true));
       }

I haven't applied this patch because it will change the constructor
signature, so I will wait for your approval.

thank you for your contribution

ciao -- Nando

PS please note this message is for the quantlib-dev list, not quantlib-users

PS2 I would also remove settlementDays() from the TermStructure interface.
It is not used anywhere in the library and it is misleading (e.g. it has no
relation with the settlement days of the instruments used to bootstrap the
curve).
Anyone against this change?