Posted by
Smith, Dale (Norcross) on
URL: http://quantlib.414.s1.nabble.com/QuantLib-Users-IborIndex-Fixings-vs-Bloomberg-Fixings-tp5632p5645.html
Below is the code, ready to compile. I'm using VS 2010 and QuantLib 1.1. I also tried 1.2 with the same results.
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*!
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl
Copyright (C) 2004 Ferdinando Ametrano
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers -
http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<
[hidden email]>. The license is also available online at
<
http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
/* This example shows how to set up a Term Structure and then price a simple
swap.
*/
// the only header you need to use QuantLib
#include <ql/quantlib.hpp>
#include <ql/termstructures/yield/piecewiseyieldcurve.hpp>
#ifdef BOOST_MSVC
/* Uncomment the following lines to unmask floating-point
exceptions. Warning: unpredictable results can arise...
See
http://www.wilmott.com/messageview.cfm?catid=10&threadid=9481 Is there anyone with a definitive word about this?
*/
// #include <float.h>
// namespace { unsigned int u = _controlfp(_EM_INEXACT, _MCW_EM); }
#endif
#include <boost/timer.hpp>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace QuantLib;
using namespace std;
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Integer sessionId() { return 0; }
}
#endif
int main(int, char* []) {
try {
boost::timer timer;
std::cout << std::endl;
/*********************
*** MARKET DATA ***
*********************/
//
http://comments.gmane.org/gmane.comp.finance.quantlib.user/6922 //Calendar calendar = UnitedStates();
JointCalendar usdgbpCalendar = JointCalendar(UnitedStates(), UnitedKingdom());
// Use UK calendar since the BBA specified USD Libor follows UK calendar.
//Calendar calendar = UnitedKingdom(); // TARGET();
Date settlementDate(26, March, 2012);
// must be a business day
settlementDate = usdgbpCalendar.adjust(settlementDate);
Integer fixingDays = 2;
Date todaysDate = usdgbpCalendar.advance(settlementDate, -fixingDays, Days);
// nothing to do with Date::todaysDate
Settings::instance().evaluationDate() = todaysDate;
todaysDate = Settings::instance().evaluationDate();
std::cout << "Today: " << todaysDate.weekday()
<< ", " << todaysDate << std::endl;
std::cout << "Settlement date: " << settlementDate.weekday()
<< ", " << settlementDate << std::endl;
// ***
// Quotes from the deal pricing.
// ***
// Bloomberg interpolates the term structure, not the market rates.
// Below is the term structure from the Curves tab in SWPM.
Real d1dQuote = 0.002;
Real d1wQuote = 0.0022;
Real d2wQuote = 0.0023;
Real d3wQuote = 0.0023;
Real d1mQuote = 0.0024;
Real d2mQuote = 0.0036;
Real d3mQuote = 0.005;
Real fut1Quote = 99.5;
Real fut2Quote = 99.511;
Real fut3Quote = 99.482;
Real fut4Quote = 99.439;
Real fut5Quote = 99.391;
Real fut6Quote = 99.324;
Real fut7Quote = 99.242;
Real fut8Quote = 99.14;
Real fut9Quote = 99.039;
Real fut10Quote = 98.909;
Real fut11Quote = 98.759;
Real fut12Quote = 98.579;
Real s4yQuote = 0.0110528;
Real s5yQuote = 0.0139183;
Real s6yQuote = 0.0166578;
Real s7yQuote = 0.0190752;
Real s8yQuote = 0.0211655;
Real s9yQuote = 0.0228908;
Real s10yQuote = 0.0243784;
Real s11yQuote = 0.0258135;
Real s12yQuote = 0.0267813;
Real s15yQuote = 0.0291646;
Real s20yQuote = 0.0310002;
Real s25yQuote = 0.0318074;
Real s30yQuote = 0.0322509;
Real s40yQuote = 0.0320802;
Real s50yQuote = 0.0309723;
/********************
*** QUOTES ***
********************/
// SimpleQuote stores a value which can be manually changed;
// other Quote subclasses could read the value from a database
// or some kind of data feed.
boost::shared_ptr<Quote> d1dRate(new SimpleQuote(d1dQuote));
boost::shared_ptr<Quote> d1wRate(new SimpleQuote(d1wQuote));
boost::shared_ptr<Quote> d2wRate(new SimpleQuote(d2wQuote));
boost::shared_ptr<Quote> d3wRate(new SimpleQuote(d3wQuote));
boost::shared_ptr<Quote> d1mRate(new SimpleQuote(d1mQuote));
boost::shared_ptr<Quote> d2mRate(new SimpleQuote(d2mQuote));
boost::shared_ptr<Quote> d3mRate(new SimpleQuote(d3mQuote));
boost::shared_ptr<Quote> fut1Price(new SimpleQuote(fut1Quote));
boost::shared_ptr<Quote> fut2Price(new SimpleQuote(fut2Quote));
boost::shared_ptr<Quote> fut3Price(new SimpleQuote(fut3Quote));
boost::shared_ptr<Quote> fut4Price(new SimpleQuote(fut4Quote));
boost::shared_ptr<Quote> fut5Price(new SimpleQuote(fut5Quote));
boost::shared_ptr<Quote> fut6Price(new SimpleQuote(fut6Quote));
boost::shared_ptr<Quote> fut7Price(new SimpleQuote(fut7Quote));
boost::shared_ptr<Quote> fut8Price(new SimpleQuote(fut8Quote));
boost::shared_ptr<Quote> fut9Price(new SimpleQuote(fut9Quote));
boost::shared_ptr<Quote> fut10Price(new SimpleQuote(fut10Quote));
boost::shared_ptr<Quote> fut11Price(new SimpleQuote(fut11Quote));
boost::shared_ptr<Quote> fut12Price(new SimpleQuote(fut12Quote));
boost::shared_ptr<Quote> s4yRate(new SimpleQuote(s4yQuote));
boost::shared_ptr<Quote> s5yRate(new SimpleQuote(s5yQuote));
boost::shared_ptr<Quote> s6yRate(new SimpleQuote(s6yQuote));
boost::shared_ptr<Quote> s7yRate(new SimpleQuote(s7yQuote));
boost::shared_ptr<Quote> s8yRate(new SimpleQuote(s8yQuote));
boost::shared_ptr<Quote> s9yRate(new SimpleQuote(s9yQuote));
boost::shared_ptr<Quote> s10yRate(new SimpleQuote(s10yQuote));
boost::shared_ptr<Quote> s11yRate(new SimpleQuote(s11yQuote));
boost::shared_ptr<Quote> s12yRate(new SimpleQuote(s12yQuote));
boost::shared_ptr<Quote> s15yRate(new SimpleQuote(s15yQuote));
boost::shared_ptr<Quote> s20yRate(new SimpleQuote(s20yQuote));
boost::shared_ptr<Quote> s25yRate(new SimpleQuote(s25yQuote));
boost::shared_ptr<Quote> s30yRate(new SimpleQuote(s30yQuote));
boost::shared_ptr<Quote> s40yRate(new SimpleQuote(s40yQuote));
boost::shared_ptr<Quote> s50yRate(new SimpleQuote(s50yQuote));
/*********************
*** RATE HELPERS ***
*********************/
// RateHelpers are built from the above quotes together with
// other instrument dependant infos. Quotes are passed in
// relinkable handles which could be relinked to some other
// data source later.
// deposits
DayCounter depositDayCounter = Actual360();
boost::shared_ptr<RateHelper> d1d(new DepositRateHelper(Handle<Quote>(d1dRate), 1*Days, fixingDays, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
boost::shared_ptr<RateHelper> d1w(new DepositRateHelper(Handle<Quote>(d1wRate), 1*Weeks, fixingDays, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
boost::shared_ptr<RateHelper> d2w(new DepositRateHelper(Handle<Quote>(d2wRate), 2*Weeks, fixingDays, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
boost::shared_ptr<RateHelper> d3w(new DepositRateHelper(Handle<Quote>(d3wRate), 3*Weeks, fixingDays, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
boost::shared_ptr<RateHelper> d1m(new DepositRateHelper(Handle<Quote>(d1mRate), 1*Months, fixingDays, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
boost::shared_ptr<RateHelper> d2m(new DepositRateHelper(Handle<Quote>(d2mRate), 2*Months, fixingDays, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
boost::shared_ptr<RateHelper> d3m(new DepositRateHelper(Handle<Quote>(d3mRate), 3*Months, fixingDays, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
// setup futures
// Rate convexityAdjustment = 0.0;
Integer futMonths = 3;
Date imm = IMM::nextDate(settlementDate);
boost::shared_ptr<RateHelper> fut1(new FuturesRateHelper(Handle<Quote>(fut1Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut2(new FuturesRateHelper(Handle<Quote>(fut2Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut3(new FuturesRateHelper(Handle<Quote>(fut3Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut4(new FuturesRateHelper(Handle<Quote>(fut4Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut5(new FuturesRateHelper(Handle<Quote>(fut5Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut6(new FuturesRateHelper(Handle<Quote>(fut6Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut7(new FuturesRateHelper(Handle<Quote>(fut7Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut8(new FuturesRateHelper(Handle<Quote>(fut8Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut9(new FuturesRateHelper(Handle<Quote>(fut9Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut10(new FuturesRateHelper(Handle<Quote>(fut10Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut11(new FuturesRateHelper(Handle<Quote>(fut11Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
imm = IMM::nextDate(imm + 1);
boost::shared_ptr<RateHelper> fut12(new FuturesRateHelper(Handle<Quote>(fut12Price), imm, futMonths, usdgbpCalendar, ModifiedFollowing, true, depositDayCounter));
// setup swaps
Frequency swFixedLegFrequency = Annual;
BusinessDayConvention swFixedLegConvention = ModifiedFollowing;
DayCounter swFixedLegDayCounter = Thirty360();
boost::shared_ptr<IborIndex> swFloatingLegIndex(new USDLibor(Period(3, Months)));
boost::shared_ptr<RateHelper> s4y(new SwapRateHelper(Handle<Quote>(s4yRate), 4*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s5y(new SwapRateHelper(Handle<Quote>(s5yRate), 5*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s6y(new SwapRateHelper(Handle<Quote>(s6yRate), 6*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s7y(new SwapRateHelper(Handle<Quote>(s7yRate), 7*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s8y(new SwapRateHelper(Handle<Quote>(s8yRate), 8*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s9y(new SwapRateHelper(Handle<Quote>(s9yRate), 9*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s10y(new SwapRateHelper(Handle<Quote>(s10yRate), 10*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s11y(new SwapRateHelper(Handle<Quote>(s11yRate), 11*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s12y(new SwapRateHelper(Handle<Quote>(s12yRate), 12*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s15y(new SwapRateHelper(Handle<Quote>(s15yRate), 15*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s20y(new SwapRateHelper(Handle<Quote>(s20yRate), 20*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s25y(new SwapRateHelper(Handle<Quote>(s25yRate), 25*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s30y(new SwapRateHelper(Handle<Quote>(s30yRate), 30*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s40y(new SwapRateHelper(Handle<Quote>(s40yRate), 40*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
boost::shared_ptr<RateHelper> s50y(new SwapRateHelper(Handle<Quote>(s50yRate), 50*Years, usdgbpCalendar, swFixedLegFrequency, swFixedLegConvention, swFixedLegDayCounter, swFloatingLegIndex));
/*********************
** CURVE BUILDING **
*********************/
// Any DayCounter would be fine.
// ActualActual::ISDA ensures that 30 years is 30.0
DayCounter termStructureDayCounter =
ActualActual(ActualActual::ISDA);
double tolerance = 1.0e-15;
// A depo-futures-swap curve
std::vector<boost::shared_ptr<RateHelper> > depoFutSwapInstruments;
depoFutSwapInstruments.push_back(d1d);
depoFutSwapInstruments.push_back(d1w);
depoFutSwapInstruments.push_back(d2w);
depoFutSwapInstruments.push_back(d3w);
depoFutSwapInstruments.push_back(d1m);
depoFutSwapInstruments.push_back(d2m);
depoFutSwapInstruments.push_back(d3m);
depoFutSwapInstruments.push_back(fut1);
depoFutSwapInstruments.push_back(fut2);
depoFutSwapInstruments.push_back(fut3);
depoFutSwapInstruments.push_back(fut4);
depoFutSwapInstruments.push_back(fut5);
depoFutSwapInstruments.push_back(fut6);
depoFutSwapInstruments.push_back(fut7);
depoFutSwapInstruments.push_back(fut8);
depoFutSwapInstruments.push_back(fut9);
depoFutSwapInstruments.push_back(fut10);
depoFutSwapInstruments.push_back(fut11);
depoFutSwapInstruments.push_back(fut12);
depoFutSwapInstruments.push_back(s4y);
depoFutSwapInstruments.push_back(s5y);
depoFutSwapInstruments.push_back(s6y);
depoFutSwapInstruments.push_back(s7y);
depoFutSwapInstruments.push_back(s8y);
depoFutSwapInstruments.push_back(s9y);
depoFutSwapInstruments.push_back(s10y);
depoFutSwapInstruments.push_back(s11y);
depoFutSwapInstruments.push_back(s12y);
depoFutSwapInstruments.push_back(s15y);
depoFutSwapInstruments.push_back(s20y);
depoFutSwapInstruments.push_back(s25y);
depoFutSwapInstruments.push_back(s30y);
depoFutSwapInstruments.push_back(s40y);
depoFutSwapInstruments.push_back(s50y);
boost::shared_ptr<YieldTermStructure> depoFutSwapTermStructure(
//new PiecewiseYieldCurve<Discount, Linear>(
new PiecewiseYieldCurve<ZeroYield, Linear>(
settlementDate, depoFutSwapInstruments,
termStructureDayCounter,
tolerance));
// Term structures that will be used for pricing:
// the one used for discounting cash flows
RelinkableHandle<YieldTermStructure> discountingTermStructure;
// the one used for forward rate forecasting
RelinkableHandle<YieldTermStructure> forecastingTermStructure;
RelinkableHandle<YieldTermStructure> h;
/*********************
* SWAPS TO BE PRICED *
**********************/
// constant nominal 1,000,000 Euro
Real nominal = 10000000.0;
// fixed leg
Frequency fixedLegFrequency = Quarterly;
BusinessDayConvention fixedLegConvention = ModifiedFollowing;
BusinessDayConvention floatingLegConvention = ModifiedFollowing;
DayCounter fixedLegDayCounter = Thirty360();
//Rate fixedRate = 0.01373122;
Rate fixedRate = 0.01373120;
DayCounter floatingLegDayCounter = Actual360();
// floating leg
Frequency floatingLegFrequency = Quarterly;
boost::shared_ptr<IborIndex> idx(new USDLibor(Period(3, Months), forecastingTermStructure));
//boost::shared_ptr<IborIndex> idx(new Euribor3M(forecastingTermStructure));
//boost::shared_ptr<IborIndex> idx(new USDLibor(Period(3, Months), h));
Spread spread = 0.0;
idx->clearFixings();
idx->addFixing(Date(22, March, 2012), 0.0047365);
idx->addFixing(Date(22, June, 2012), 0.0046156);
idx->addFixing(Date(24, September, 2012), 0.0052129);
idx->addFixing(Date(21, December, 2012), 0.0056439);
idx->addFixing(Date(22, March, 2013), 0.006136);
idx->addFixing(Date(24, June, 2013), 0.0068255);
idx->addFixing(Date(24, September, 2013), 0.0076726);
idx->addFixing(Date(23, December, 2013), 0.0086831);
idx->addFixing(Date(24, March, 2014), 0.0097157);
idx->addFixing(Date(24, June, 2014), 0.0110484);
idx->addFixing(Date(24, September, 2014), 0.0126216);
idx->addFixing(Date(23, December, 2014), 0.0143848);
idx->addFixing(Date(24, March, 2015), 0.0161928);
idx->addFixing(Date(24, June, 2015), 0.0187209);
idx->addFixing(Date(24, September, 2015), 0.0200915);
idx->addFixing(Date(23, December, 2015), 0.0214196);
idx->addFixing(Date(23, March, 2016), 0.0231223);
idx->addFixing(Date(23, June, 2016), 0.0244363);
idx->addFixing(Date(22, September, 2016), 0.0257481);
idx->addFixing(Date(22, December, 2016), 0.0270144);
Integer lenghtInYears = 5;
VanillaSwap::Type swapType = VanillaSwap::Payer;
Date maturity = settlementDate + lenghtInYears*Years;
Schedule fixedSchedule(settlementDate, maturity,
Period(fixedLegFrequency),
usdgbpCalendar, fixedLegConvention,
fixedLegConvention,
DateGeneration::Backward, false);
Schedule floatSchedule(settlementDate, maturity,
Period(floatingLegFrequency),
usdgbpCalendar, floatingLegConvention,
floatingLegConvention,
DateGeneration::Backward, false);
VanillaSwap spot5YearSwap(swapType, nominal,
fixedSchedule, fixedRate, fixedLegDayCounter,
floatSchedule, idx, spread,
floatingLegDayCounter);
/***************
* SWAP PRICING *
****************/
// utilities for reporting
std::vector<std::string> headers(4);
headers[0] = "term structure";
headers[1] = "net present value";
headers[2] = "fair spread";
headers[3] = "fair fixed rate";
std::string separator = " | ";
Size width = headers[0].size() + separator.size()
+ headers[1].size() + separator.size()
+ headers[2].size() + separator.size()
+ headers[3].size() + separator.size() - 1;
std::string rule(width, '-'), dblrule(width, '=');
std::string tab(8, ' ');
// calculations
std::cout << dblrule << std::endl;
std::cout << "5-year market swap-rate = "
<< std::setprecision(8) << io::rate(s5yRate->value())
<< std::endl;
std::cout << dblrule << std::endl;
std::cout << tab << "5-years swap paying "
<< io::rate(fixedRate) << std::endl;
std::cout << headers[0] << separator
<< headers[1] << separator
<< headers[2] << separator
<< headers[3] << separator << std::endl;
std::cout << rule << std::endl;
Real NPV;
Rate fairRate;
Spread fairSpread;
boost::shared_ptr<PricingEngine> swapEngine(
new DiscountingSwapEngine(discountingTermStructure));
spot5YearSwap.setPricingEngine(swapEngine);
forecastingTermStructure.linkTo(depoFutSwapTermStructure);
discountingTermStructure.linkTo(depoFutSwapTermStructure);
//h.linkTo(indexTermStructure);
NPV = spot5YearSwap.NPV();
fairSpread = spot5YearSwap.fairSpread();
fairRate = spot5YearSwap.fairRate();
std::cout << std::setw(headers[0].size())
<< "depo-fut-swap" << separator;
std::cout << std::setw(headers[1].size())
<< std::fixed << std::setprecision(8) << NPV << separator;
std::cout << std::setw(headers[2].size())
<< io::rate(fairSpread) << separator;
std::cout << std::setw(headers[3].size())
<< io::rate(fairRate) << separator;
std::cout << std::endl;
//QL_REQUIRE(std::fabs(fairRate-s5yQuote)<1e-8,
// "5-years swap mispriced!");
Leg fixedLeg = spot5YearSwap.fixedLeg();
Leg floatLeg = spot5YearSwap.floatingLeg();
Leg::const_iterator i = fixedLeg.begin();
Leg::const_iterator e = fixedLeg.end();
Leg::const_iterator ii = floatLeg.begin();
cout << "Fixed Cf Amount|Fixed Cf Date|Float Cf Amount|Float Cf Date|Fixed Cf DF|Index Fixing\n";
for (; i != e; i++, ii++)
{
boost::shared_ptr<CashFlow> fixedCf = *i;
boost::shared_ptr<CashFlow> floatCf = *ii;
Date d = usdgbpCalendar.adjust(floatCf->date(), ModifiedFollowing);
cout << -fixedCf->amount() << "|" << fixedCf->date()
<< "|" << floatCf->amount() << "|" << floatCf->date()
<< "|" << discountingTermStructure->discount(fixedCf->date())
<< "|" << idx->fixing(d, false)
<< endl;
}
//cout << "Fixed Cf Amount|Fixed Cf Date|Float Cf Amount|Float Cf Date|Fixed Cf DF|Index Fixing\n";
//for (; i != e; i++, ii++)
//{
// boost::shared_ptr<CashFlow> fixedCf = *i;
// boost::shared_ptr<CashFlow> floatCf = *ii;
// Date d = calendar.adjust(floatCf->date(), ModifiedFollowing);
// cout << -fixedCf->amount() << "|" << fixedCf->date()
// << "|" << floatCf->amount() << "|" << floatCf->date()
// << "|" << discountingTermStructure->discount(fixedCf->date())
// << "|" << idx->fixing(d, false)
// << endl;
//}
Real seconds = timer.elapsed();
Integer hours = int(seconds/3600);
seconds -= hours * 3600;
Integer minutes = int(seconds/60);
seconds -= minutes * 60;
std::cout << " \nRun completed in ";
if (hours > 0)
std::cout << hours << " h ";
if (hours > 0 || minutes > 0)
std::cout << minutes << " m ";
std::cout << std::fixed << std::setprecision(0)
<< seconds << " s\n" << std::endl;
cout << "Press a key then Enter to exit.\n";
string s;
cin >> s;
return 0;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
cout << "Press a key then Enter to exit.\n";
string s;
cin >> s;
return 1;
} catch (...) {
std::cerr << "unknown error" << std::endl;
cout << "Press a key then Enter to exit.\n";
string s;
cin >> s;
return 1;
}
}
Thanks,
Dale Smith, Ph.D.
Senior Financial Quantitative Analyst
Risk & Compliance
Fiserv.
107 Technology Park
Norcross, GA 30092
Office: 678-375-5315
Mobile: 678-982-6599
Mail:
[hidden email]
www.fiserv.com
-----Original Message-----
From: Luigi Ballabio [mailto:
[hidden email]]
Sent: Monday, April 02, 2012 4:16 PM
To: Smith, Dale
Cc:
[hidden email]
Subject: Re: [Quantlib-users] [QuantLib-Users] IborIndex Fixings vs Bloomberg Fixings
Sorry, I had saved your post but I didn't have time to follow through.
Do you have a set of inputs that reproduces the problem? (Evaluation date, input rates, conventions you're using...)
Luigi
On Mon, Apr 2, 2012 at 9:49 PM, Smith, Dale <
[hidden email]> wrote:
> Sending again in hopes it was simply forgotten...
>
>
>
> Thanks,
>
> Dale Smith, Ph.D.
>
> Senior Financial Quantitative Analyst
>
> Risk & Compliance
>
> Fiserv.
>
> 107 Technology Park
>
> Norcross, GA 30092
>
> Office: 678-375-5315
>
> Mobile: 678-982-6599
>
> Mail:
[hidden email]
>
> www.fiserv.com
>
>
>
> From: Smith, Dale
> Sent: Thursday, March 29, 2012 10:43 AM
> To:
[hidden email]
> Subject: [QuantLib-Users] IborIndex Fixings vs Bloomberg Fixings
>
>
>
> Hello,
>
>
>
> I'm trying to tie out a QuantLib program with Bloomberg's SWPM screen.
> I have the deposit, futures, and swap rates as in the Swap example
> project, and created an IborIndex using the joint UK and US calendars
> to pick up both sets of holidays.
>
>
>
> boost::shared_ptr<IborIndex> idx(new USDLibor(Period(3, Months),
> forecastingTermStructure));
>
>
>
> forecastingTermStructure is linked to
>
>
>
> boost::shared_ptr<YieldTermStructure>
> depoFutSwapTermStructure(
>
> //new PiecewiseYieldCurve<Discount, Linear>(
>
> new PiecewiseYieldCurve<ZeroYield, Linear>(
>
> settlementDate,
> depoFutSwapInstruments,
>
> termStructureDayCounter,
>
> tolerance));
>
>
>
> My problem is the fixings used in the floating leg that Bloomberg uses
> are not the same as what QuantLib uses. I did do a clearFixing() on
> the IborIndex object and added the fixings I see on the SWPM Resets
> tab. I've also confirmed by calculations in Excel that the difference
> in cashflows on the floating leg is due entirely to the fixings.
>
>
>
> Bloomberg uses Piecewise Linear (Simple) for the interpolation. I
> changed that to Piecewise Linear (Continuous) but the fixings still
> don't match. I also changed to PiecewiseYieldCurve<ZeroYield, Linear>
> in my own code after confirming with Bloomberg they are interpolating
> the term structure, not the discount factors or the market rates.
>
>
>
> I've used Google to search for answers to this, and looked at the
> examples and unit tests in the QuantLib code. Is there anywhere I've
> missed in my searches?
>
>
>
> Thanks,
>
> Dale Smith, Ph.D.
>
> Senior Financial Quantitative Analyst
>
> Risk & Compliance
>
> Fiserv.
>
> 107 Technology Park
>
> Norcross, GA 30092
>
> Office: 678-375-5315
>
> Mobile: 678-982-6599
>
> Mail:
[hidden email]
>
> www.fiserv.com
>
>
>
>
> ----------------------------------------------------------------------
> --------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
>
http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> QuantLib-users mailing list
>
[hidden email]
>
https://lists.sourceforge.net/lists/listinfo/quantlib-users>
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users