Pricing Interest Rate swap at future dates
Posted by Mariano Zeron on Aug 09, 2016; 3:52pm
URL: http://quantlib.414.s1.nabble.com/Pricing-Interest-Rate-swap-at-future-dates-tp17639.html
I’m trying to compute a price distribution at different points in time in the future for an interest rate swap. The idea is to then use the price distributions to compute CVA, Initial Margin, etc. However, the tricky part so far has been pricing the interest rate swap (which has been fixed in the past, of course) at different points in time in the future.
Say the interest rate swap started on 1, March, 2016 (as seen in the code below). The interest rate swap is evaluated on the 10, November, 2016, (but of course the idea is to vary this date depending on the dates we want price distributions for). The problem I’ve been getting is that when the valuation date is after the settle date, I get the following exception:
2nd leg: Missing Euribor1Y Actual/360 fixing for February 26th, 2016
Code:
Calendar calendar = TARGET();
// -- Swap parameters
Real nominal = 1000000.0;
Date SettleDate(1, March, 2016);
Date maturity(1, March, 2026);
double spread = 0.02;
double fixedRate = 0.04;
Frequency fixedLegFrequency = Annual;
Frequency floatingLegFrequency = Annual;
VanillaSwap::Type swapType = VanillaSwap::Payer;
// -- Valuation date
Date valuationDate(10, November, 2016);
valuationDate = calendar.adjust(valuationDate);
Settings::instance().evaluationDate() = valuationDate;
// -- Specifying discount curve (simple example. Normally it would have 12 tenors)
vector<Date> dates;
vector<DiscountFactor> discountFactor;
dates.push_back(valuationDate); discountFactor.push_back(1.0);
dates.push_back(valuationDate + 1 * Years); discountFactor.push_back(0.99);
dates.push_back(valuationDate + 15 * Years); discountFactor.push_back(0.80);
boost::shared_ptr<YieldTermStructure> forwardCurve(new InterpolatedDiscountCurve<LogLinear>(dates, discountFactor, ActualActual()));
boost::shared_ptr<YieldTermStructure> discountCurve(new InterpolatedDiscountCurve<LogLinear>(dates, discountFactor, ActualActual()));
Handle<YieldTermStructure> discountingTermStructure(discountCurve);
Handle<YieldTermStructure> forwardingTermStructure(forwardCurve);
Schedule fixedSchedule(SettleDate, maturity, Period(fixedLegFrequency),
TARGET(), ModifiedFollowing, ModifiedFollowing,
DateGeneration::Forward, false);
Schedule floatSchedule(SettleDate, maturity, Period(floatingLegFrequency),
TARGET(), ModifiedFollowing, ModifiedFollowing,
DateGeneration::Forward, false);
boost::shared_ptr<IborIndex> euribor(new Euribor(Period(floatingLegFrequency), forwardingTermStructure));
//euribor->addFixing(euribor->fixingDate(SettleDate), 0.01, true);
VanillaSwap swap(swapType, nominal, fixedSchedule, fixedRate, ActualActual(),
floatSchedule, euribor, spread, ActualActual());
boost::shared_ptr<PricingEngine> swapEngine(new DiscountingSwapEngine(discountingTermStructure));
swap.setPricingEngine(swapEngine);
double res = swap.NPV();
It seems that boost::shared_ptr<IborIndex> euribor needs the rate from the previous payment date in order to specify the rate which is applied to the notional. From what I’ve read in other threads, one can use euribor->addFixing.
First problem/inconvenience, is that for each time point in the future, one has to keep track of which is the previous payment date. The second is that one needs to come up with a value for the rate which must be specified for this payment date. Is there a method (or methods) for euribor that help in this case? euribor already contains the curve to used to compute rates on the floating leg (boost::shared_ptr<YieldTermStructure> forwardCurve), can it not be extrapolated to the previous payment date and use that rate?
Any suggestions on how to deal with this issue will be highly appreciated