how to construct yield curve in quantlib [ quantlib yield curve example ]

bloomberg or reuters can give you already bootstrapped curve in format [date] [discount factor]

here we’ll show a quantlib yield curve example construction

yield curve normally is used for getting a discount factor for a given date and for calculating euribor forwards

here we’ll show code snippet with quantlib which show show to use these functions

market date example:

valuation date: 31/dec/2012

[date] [discount factor]
30/12/2013 0.99
30/12/2014 0.98

we’ll calculate discount factor for 25/june /2013 and euribor forward 6m for the same date

#include <ql/quantlib.hpp>

using namespace std;
using namespace QuantLib;
using namespace boost;

int main()
{

vector<Date> dates; 
vector<DiscountFactor> discountFactor; 

Date valuationDate(31,December,2012);

dates.push_back(valuationDate); discountFactor.push_back(1.0); 

dates.push_back(Date(30,December, 2013));  discountFactor.push_back(0.99); 
dates.push_back(Date(30,December, 2014));  discountFactor.push_back(0.98); 

shared_ptr<YieldTermStructure> curve(new InterpolatedDiscountCurve<LogLinear>(dates,discountFactor,Actual360())); 

//discount factor
Date datex(25,June,2013);
double discount=curve->discount(datex);

//euribor forward
Period period(6*Months);
boost::shared_ptr<IborIndex> euribor(new Euribor(period));
double forward6m=curve->forwardRate(datex,period,curve->dayCounter(),QuantLib::Compounding::Simple);

}


Posted in quantlib