Fair Rate of Overnight Indexed Swap

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fair Rate of Overnight Indexed Swap

Fabio
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 <iostream>
#include <ql/quantlib.hpp>

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<Date> dates(0);
vector<DiscountFactor> discountFactor(0);

dates.push_back(settlementDate);
dates.push_back(d2_1m);

discountFactor.push_back(1.0);
discountFactor.push_back(0.95);

InterpolatedDiscountCurve <LogLinear> eoniaCurve(dates, discountFactor, eonia_dc, calendar);

boost::shared_ptr<YieldTermStructure> OisCurve;

OisCurve = boost::shared_ptr<YieldTermStructure>(new InterpolatedDiscountCurve <LogLinear>(dates,                           discountFactor, eonia_dc, calendar));

Handle<YieldTermStructure> discountingTermStructure(OisCurve);

boost::shared_ptr<OvernightIndex> 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;

}
Reply | Threaded
Open this post in threaded view
|

Re: Fair Rate of Overnight Indexed Swap

Fabio
Ok, I managed to work it out. I post here a possible solution.

#pragma warning(disable:4996)

#include <iostream>
#include <vector>
#include <ql/quantlib.hpp>

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<Date> dates(0);
vector<DiscountFactor> 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<YieldTermStructure> cirOisCurve;
cirOisCurve = boost::shared_ptr<YieldTermStructure>(new InterpolatedDiscountCurve <LogLinear>(dates, discountFactors, Actual360()));

Handle<YieldTermStructure> discountingTermStructure(cirOisCurve);

boost::shared_ptr<OvernightIndex> 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<PricingEngine> 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;

}