Formula for the discount of a yield curve?

Posted by mihai.bunea on
URL: http://quantlib.414.s1.nabble.com/Formula-for-the-discount-of-a-yield-curve-tp6098.html

Could you please explain the formula used for computing the discount of a yield curve?

I tried to feed QuantLib the following simple case: cash deposit for 3 months (DepositRateHelper) with rate = 100% per year.
Use 365 days per year and no bussiness days adjustment: time in years is simply days_offset / 365.0.
What is the present value of 1$ in 90 days (QuantLib call to YieldTermStructure.discount(90 / 365.0))?

I couldn't find any documentation on the algorithm used for computing the discount, so i had to assume some.
For instance: http://en.wikipedia.org/wiki/Compound_interest

However, the interest as computed by Quantlib doesn't seem to be neither simple, nor periodically-compounded, nor continuously-compounded.

If it were continuously-compounded, then the discount would be:  1 / exp(r * t) = 1 / exp((100/100.0) * (90 / 365.0)) =~ 0.781472.
Instead, i'm getting: 0.802198.

Furthermore, if it were continuously-compounded, the result wouldn't depend on deposit's period expressed in days vs. months.
But, when expressing the deposit in 3*Months instead of 90*Days, i'm getting a different result: 0.809476.

** This leads me to the conclusion that it's better to ask what algorithm you are using instead of guessing or reverse-engineering the code.
** Actually i tried other compounding conventions from the Wikipedia link but without success.
** Reverse-engineering the code (the call to discount() method) also didn't work: the code it's definitely not self-documenting.

The only bit of documentation i found was in Luigi Ballabio's "Implementing QuantLib" PDF, chapter 3, parahraph 3.2.1. and it sais "Of course, there is a relationship between zero rates, forward rates, and discount factors; the knowledge of any one of them is sufficient to deduce the others (I won’t bore you with the formulas here—you know them.)"

Looks like as a matter of fact, i (we) don't know them, or better said (as the example above shows), those which i know don't match what QuantLib it's using.

So could you please give a bit more mathematical detail on these calculations?

Below it's an approximate listing of the code i was using:
>>
>> Calendar calendar = TARGET();
>> Date settlementDate(24, January, 2011);
>>
>> Integer fixingDays = 0;
>> Date todaysDate = calendar.advance(settlementDate, -fixingDays, Days);
>> Settings::instance().evaluationDate() = todaysDate;
>>
>> // deposit: 100% per year
>> Rate d1Quote=1.0;
>> boost::shared_ptr<Quote> d1Rate(new SimpleQuote(d1Quote));
>>
>> DayCounter depositDayCounter = Actual365Fixed();
>> boost::shared_ptr<RateHelper> d1(new DepositRateHelper(
>>     Handle<Quote>(d1Rate),
>>     90*Days,
>>   //3*Months,
>>     fixingDays,
>>     calendar,
>>     Unadjusted,
>>     true,
>>     depositDayCounter));
>>
>> DayCounter termStructureDayCounter = Actual365Fixed();
>>
>> // Deposit test curve
>> std::vector<boost::shared_ptr<RateHelper> > depoInstruments;
>> depoInstruments.push_back(d1);
>> boost::shared_ptr<YieldTermStructure> depoInstrumentsTermStructure(
>>     new PiecewiseYieldCurve<Discount,LogLinear>(
>>                                   settlementDate,
>>                                   depoInstruments,
>>                                   termStructureDayCounter,
>>                                   1.0e-15)); // tolerance
>>
>> Time elapsedTime = 90.0 / 365.0;
>> double discountFactor = depoInstrumentsTermStructure->discount(elapsedTime, true);
>>