## [Quantlib-users] Fair Rate of Overnight Indexed Swap

 [Quantlib-users] Fair Rate of Overnight Indexed Swap From: Fabio - 2014-03-09 15:13:30 ```Hi, I got stuck into this problem. My purpose is to compute the fair rate of an Eonia OIS with start date 13 December 2012 and maturity 14 January 2013. I guess the discount curve is properly build and the OIS is correctly defined, nontheless, after calling the method fairRate(), the returned value is -1.#IND. I'm quite new to QuantLib and not able to work this problem around. Can anyone help me, please? Thank you! #pragma warning(disable:4996) #include #include using namespace std; using namespace boost; using namespace QuantLib; int main(){ Calendar calendar = TARGET(); Date today(11, December, 2012); Eonia eonia; DayCounter eonia_dc = eonia.dayCounter(); Natural settlementDays = 2; Date settlementDate = calendar.advance(today, settlementDays, Days); Date d2_1m(14, January, 2013); // DISCOUNTING CURVE CONSTRUCTION vector dates(0); vector discountFactor(0); dates.push_back(settlementDate); dates.push_back(d2_1m); discountFactor.push_back(1.0); discountFactor.push_back(0.95); InterpolatedDiscountCurve eoniaCurve(dates, discountFactor, eonia_dc, calendar); boost::shared_ptr OisCurve; OisCurve = boost::shared_ptr(new InterpolatedDiscountCurve (dates, discountFactor, eonia_dc, calendar)); Handle discountingTermStructure(OisCurve); boost::shared_ptr eoniaIndex(new Eonia(discountingTermStructure)); // SOME OIS CHARACTERISTICS Real nominal = 100000.0; Spread spread = 0.0; Rate fixedRate = 0.00074; OvernightIndexedSwap::Type type = OvernightIndexedSwap::Payer; Frequency legFrequency = Annual; BusinessDayConvention legConvention = Unadjusted; Schedule schedule(settlementDate, d2_1m, Period(legFrequency), calendar, legConvention, legConvention, DateGeneration::Forward, false); OvernightIndexedSwap ois_swap(type, nominal, schedule, fixedRate, eonia_dc, eoniaIndex, spread); // FAIR RATE CALCULATION Rate fairRate = 0.0; fairRate = ois_swap.fairRate(); cout << "Fair Rate: " << fairRate << endl; getchar(); return 0; } -- View this message in context: http://quantlib.10058.n7.nabble.com/Fair-Rate-of-Overnight-Indexed-Swap-tp15053.html Sent from the quantlib-users mailing list archive at Nabble.com. ```

 [Quantlib-users] Fair Rate of Overnight Indexed Swap From: Fabio - 2014-03-09 15:13:30 ```Hi, I got stuck into this problem. My purpose is to compute the fair rate of an Eonia OIS with start date 13 December 2012 and maturity 14 January 2013. I guess the discount curve is properly build and the OIS is correctly defined, nontheless, after calling the method fairRate(), the returned value is -1.#IND. I'm quite new to QuantLib and not able to work this problem around. Can anyone help me, please? Thank you! #pragma warning(disable:4996) #include #include using namespace std; using namespace boost; using namespace QuantLib; int main(){ Calendar calendar = TARGET(); Date today(11, December, 2012); Eonia eonia; DayCounter eonia_dc = eonia.dayCounter(); Natural settlementDays = 2; Date settlementDate = calendar.advance(today, settlementDays, Days); Date d2_1m(14, January, 2013); // DISCOUNTING CURVE CONSTRUCTION vector dates(0); vector discountFactor(0); dates.push_back(settlementDate); dates.push_back(d2_1m); discountFactor.push_back(1.0); discountFactor.push_back(0.95); InterpolatedDiscountCurve eoniaCurve(dates, discountFactor, eonia_dc, calendar); boost::shared_ptr OisCurve; OisCurve = boost::shared_ptr(new InterpolatedDiscountCurve (dates, discountFactor, eonia_dc, calendar)); Handle discountingTermStructure(OisCurve); boost::shared_ptr eoniaIndex(new Eonia(discountingTermStructure)); // SOME OIS CHARACTERISTICS Real nominal = 100000.0; Spread spread = 0.0; Rate fixedRate = 0.00074; OvernightIndexedSwap::Type type = OvernightIndexedSwap::Payer; Frequency legFrequency = Annual; BusinessDayConvention legConvention = Unadjusted; Schedule schedule(settlementDate, d2_1m, Period(legFrequency), calendar, legConvention, legConvention, DateGeneration::Forward, false); OvernightIndexedSwap ois_swap(type, nominal, schedule, fixedRate, eonia_dc, eoniaIndex, spread); // FAIR RATE CALCULATION Rate fairRate = 0.0; fairRate = ois_swap.fairRate(); cout << "Fair Rate: " << fairRate << endl; getchar(); return 0; } -- View this message in context: http://quantlib.10058.n7.nabble.com/Fair-Rate-of-Overnight-Indexed-Swap-tp15053.html Sent from the quantlib-users mailing list archive at Nabble.com. ```
 Re: [Quantlib-users] Fair Rate of Overnight Indexed Swap From: Fabio - 2014-03-10 13:51:35 ```Ok, I managed to work it out. I post here a possible solution. #pragma warning(disable:4996) #include #include #include using namespace std; using namespace boost; using namespace QuantLib; int main(){ // GENERAL SETTINGS Calendar calendar = TARGET(); Date settlementDate(13, December, 2012); Integer settlementDays = -2; Date today = calendar.advance(settlementDate, settlementDays, Days); Settings::instance().evaluationDate() = today; // DATES AND DISCOUNT FACTORS vector dates(0); vector discountFactors(0); for (int i=0; i<13; i++){ dates.push_back(settlementDate + i*Years); } for (int i=0; i<13; i++){ discountFactors.push_back(1.0 - i*0.01); } // DISCOUNT CURVE CONSTRUCTION boost::shared_ptr cirOisCurve; cirOisCurve = boost::shared_ptr(new InterpolatedDiscountCurve (dates, discountFactors, Actual360())); Handle discountingTermStructure(cirOisCurve); boost::shared_ptr eonia(new Eonia(discountingTermStructure)); // SWAP SET-UP Date previousResetDate(today); Date maturity(20, December, 2012); Real nominal = 100000.0; Spread spread = 0.0; Rate fixedRate = 0.00070; OvernightIndexedSwap::Type type = OvernightIndexedSwap::Payer; BusinessDayConvention legConvention = ModifiedFollowing; Frequency legFrequency = Annual; eonia->addFixing(eonia->fixingDate(previousResetDate),0.01,true); Schedule schedule(settlementDate, maturity, Period(legFrequency), TARGET(), legConvention, legConvention, DateGeneration::Forward, false); OvernightIndexedSwap ois_swap(type, nominal, schedule, fixedRate, Thirty360(), eonia, spread); // SWAP PRICING boost::shared_ptr swapEngine(new DiscountingSwapEngine(discountingTermStructure)); ois_swap.setPricingEngine(swapEngine); double npv = ois_swap.NPV(); double fairRate = ois_swap.fairRate(); cout << "Fair Rate: " << fairRate << endl; cout << "Net Present Value: " << npv << endl; getchar(); return 0; } -- View this message in context: http://quantlib.10058.n7.nabble.com/Fair-Rate-of-Overnight-Indexed-Swap-tp15053p15056.html Sent from the quantlib-users mailing list archive at Nabble.com. ```