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, |
On Mar 4, 2011, at 11:50 AM, mihai.bunea wrote: > 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 I'm not really sure what happens multiplying Days by floats here---I'd have to check the implementation. There might be some issues with conversions to int. The compiler is probably translating Days * 365.0 * 0.75 into Days * int(365) * int(0.75), that is, Days*365*0. Anyway, if you can change the day counter, I'd go for Actual360, which lends itself to fractions a lot better (0.75 of 365 is not a whole number of days). You might try: > DayCounter dayCounter = Actual360(); > Date startDate(01, March, 2012); // Swap starts at this date > Date endDate = startDate + 720*Days; // Swap ends at this date > Date evalDate = startDate + 270*Days; // There are 1.25 years left In any case, I'd use integers for the number of days (or if you want to write down the fractions for clarity, write something like Days * (360 * 0.75). Luigi ------------------------------------------------------------------------------ What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |