Date year fractions

Posted by mihai.bunea on
URL: http://quantlib.414.s1.nabble.com/Date-year-fractions-tp6234.html

Hello (again :)

The question i'm preparing to ask refers actually to the pricing of swaps.
Before that, however, i noticed a limitation of Quantlib which severely limits my attempts to use it: i want to be able to express year fractions of my choosing.
In this case, 0, 1.25 and 2.

Below is my attempt:

-------- CODE --------
DayCounter dayCounter = Actual365Fixed();
Date startDate(01, March, 2012); // Swap starts at this date
Date endDate = startDate + Days * 365.0 * 2.0; // Swap ends at this date
Date evalDate = startDate + Days * 365.0 * 0.75; // There are 1.25 years left
std::cout << "startDate " << startDate << " t=" << dayCounter.yearFraction(startDate, startDate) << std::endl;
std::cout << "evaluationDate " << evalDate << " t=" << dayCounter.yearFraction(startDate, evalDate) << std::endl;
std::cout << "endDate " << endDate << " t=" << dayCounter.yearFraction(startDate, endDate) << std::endl;

-------- RESULTS --------
startDate March 1st, 2012 t=0
evaluationDate March 1st, 2012 t=0
endDate March 1st, 2014 t=2

Looking over the Date class it's obvious that it can't be used to express arbitrary year fractions, as it's limited to integer calendar days.

Do you happen to know if there's anything i could use instead for this purpose?

Thanks in anticipo,
Mihai Bunea,