This example shows how to set up a term structure and then price some simple bonds. The last part is dedicated to peripherical computations such as "Yield to Price" or "Price to Yield"
#include <ql/qldefines.hpp>
#ifdef BOOST_MSVC
#  include <ql/auto_link.hpp>
#endif
#include <ql/instruments/bonds/zerocouponbond.hpp>
#include <ql/instruments/bonds/floatingratebond.hpp>
#include <ql/pricingengines/bond/discountingbondengine.hpp>
#include <ql/cashflows/couponpricer.hpp>
#include <ql/termstructures/yield/piecewiseyieldcurve.hpp>
#include <ql/termstructures/yield/bondhelpers.hpp>
#include <ql/termstructures/volatility/optionlet/constantoptionletvol.hpp>
#include <ql/indexes/ibor/euribor.hpp>
#include <ql/indexes/ibor/usdlibor.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <ql/time/daycounters/actual360.hpp>
#include <ql/time/daycounters/thirty360.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <iomanip>
#if defined(QL_ENABLE_SESSIONS)
}
#endif
int main(int, char* []) {
    try {
        boost::timer timer;
        std::cout << std::endl;
        
        Date settlementDate(18, September, 2008);
         
        settlementDate = calendar.
adjust(settlementDate);
        Date todaysDate = calendar.
advance(settlementDate, -fixingDays, Days);
         
        std::cout << 
"Today: " << todaysDate.
weekday()
        << ", " << todaysDate << std::endl;
        std::cout << "Settlement date: " << settlementDate.weekday()
        << ", " << settlementDate << std::endl;
        
        
        
        
        
        
        
        
         boost::shared_ptr<Quote> zc3mRate(
new SimpleQuote(zc3mQuote));
         boost::shared_ptr<Quote> zc6mRate(
new SimpleQuote(zc6mQuote));
         boost::shared_ptr<Quote> zc1yRate(
new SimpleQuote(zc1yQuote));
                 3*Months, fixingDays,
                 true, zcBondsDayCounter));
                 6*Months, fixingDays,
                 true, zcBondsDayCounter));
                 1*Years, fixingDays,
                 true, zcBondsDayCounter));
        
        const Size numberOfBonds = 5;
                 Date (15, November, 2002),
         };
        };
                0.02375,
                0.04625,
                0.03125,
                0.04000,
                0.04500
        };
                100.390625,
                106.21875,
                100.59375,
                101.6875,
                102.140625
        };
        std::vector< boost::shared_ptr<SimpleQuote> > quote;
        for (
Size i=0; i<numberOfBonds; i++) {
             boost::shared_ptr<SimpleQuote> cp(
new SimpleQuote(marketQuotes[i]));
            quote.push_back(cp);
        }
        for (
Size i=0; i<numberOfBonds; i++) {
             quoteHandle[i].
linkTo(quote[i]);
        }
        
        std::vector<boost::shared_ptr<BondHelper> > bondsHelpers;
        for (
Size i=0; i<numberOfBonds; i++) {
                     quoteHandle[i],
                    settlementDays,
                    100.0,
                    schedule,
                    std::vector<Rate>(1,couponRates[i]),
                    redemption,
                    issueDates[i]));
            
            
            
            
            
            
            
            
            bondsHelpers.push_back(bondHelper);
        }
        
         
         
         double tolerance = 1.0e-15;
         
         std::vector<boost::shared_ptr<RateHelper> > bondInstruments;
         
         bondInstruments.push_back(zc3m);
         bondInstruments.push_back(zc6m);
         bondInstruments.push_back(zc1y);
         
         for (
Size i=0; i<numberOfBonds; i++) {
              bondInstruments.push_back(bondsHelpers[i]);
         }
         boost::shared_ptr<YieldTermStructure> bondDiscountingTermStructure(
                         settlementDate, bondInstruments,
                         termStructureDayCounter,
                         tolerance));
         
         
         
         
         
         
         
         
         boost::shared_ptr<Quote> d1wRate(
new SimpleQuote(d1wQuote));
         boost::shared_ptr<Quote> d1mRate(
new SimpleQuote(d1mQuote));
         boost::shared_ptr<Quote> d3mRate(
new SimpleQuote(d3mQuote));
         boost::shared_ptr<Quote> d6mRate(
new SimpleQuote(d6mQuote));
         boost::shared_ptr<Quote> d9mRate(
new SimpleQuote(d9mQuote));
         boost::shared_ptr<Quote> d1yRate(
new SimpleQuote(d1yQuote));
         
         boost::shared_ptr<Quote> s2yRate(
new SimpleQuote(s2yQuote));
         boost::shared_ptr<Quote> s3yRate(
new SimpleQuote(s3yQuote));
         boost::shared_ptr<Quote> s5yRate(
new SimpleQuote(s5yQuote));
         boost::shared_ptr<Quote> s10yRate(
new SimpleQuote(s10yQuote));
         boost::shared_ptr<Quote> s15yRate(
new SimpleQuote(s15yQuote));
         
         
         
         
         
         
                 1*Weeks, fixingDays,
                 true, depositDayCounter));
                 1*Months, fixingDays,
                 true, depositDayCounter));
                 3*Months, fixingDays,
                 true, depositDayCounter));
                 6*Months, fixingDays,
                 true, depositDayCounter));
                 9*Months, fixingDays,
                 true, depositDayCounter));
                 1*Years, fixingDays,
                 true, depositDayCounter));
         
         boost::shared_ptr<IborIndex> swFloatingLegIndex(
new Euribor6M);
         const Period forwardStart(1*Days);
                  calendar, swFixedLegFrequency,
                 swFixedLegConvention, swFixedLegDayCounter,
                 calendar, swFixedLegFrequency,
                 swFixedLegConvention, swFixedLegDayCounter,
                 calendar, swFixedLegFrequency,
                 swFixedLegConvention, swFixedLegDayCounter,
                 calendar, swFixedLegFrequency,
                 swFixedLegConvention, swFixedLegDayCounter,
                 calendar, swFixedLegFrequency,
                 swFixedLegConvention, swFixedLegDayCounter,
         
         
         
         
         std::vector<boost::shared_ptr<RateHelper> > depoSwapInstruments;
         depoSwapInstruments.push_back(d1w);
         depoSwapInstruments.push_back(d1m);
         depoSwapInstruments.push_back(d3m);
         depoSwapInstruments.push_back(d6m);
         depoSwapInstruments.push_back(d9m);
         depoSwapInstruments.push_back(d1y);
         depoSwapInstruments.push_back(s2y);
         depoSwapInstruments.push_back(s3y);
         depoSwapInstruments.push_back(s5y);
         depoSwapInstruments.push_back(s10y);
         depoSwapInstruments.push_back(s15y);
         boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(
                         settlementDate, depoSwapInstruments,
                         termStructureDayCounter,
                         tolerance));
         
         
         
         
         
         
         boost::shared_ptr<PricingEngine> bondEngine(
                 new DiscountingBondEngine(discountingTermStructure));
         
                 settlementDays,
                 faceAmount,
         zeroCouponBond.setPricingEngine(bondEngine);
         
                 settlementDays,
                 faceAmount,
                 fixedBondSchedule,
                 std::vector<Rate>(1, 0.045),
                 100.0, 
Date(15, May, 2007));
         fixedRateBond.setPricingEngine(bondEngine);
         
         
         const boost::shared_ptr<IborIndex> libor3m(
         libor3m->addFixing(
Date(17, July, 2008),0.0278625);
                 settlementDays,
                 faceAmount,
                 floatingBondSchedule,
                 libor3m,
                 
                 std::vector<Real>(1, 1.0),
                 
                 std::vector<Rate>(1, 0.001),
                 
                 std::vector<Rate>(),
                 
                 std::vector<Rate>(),
                 
                 true,
                 Date(21, October, 2005));
          floatingRateBond.setPricingEngine(bondEngine);
         
         
                 boost::shared_ptr<OptionletVolatilityStructure>(new
                                 settlementDays,
                                 calendar,
         pricer->setCapletVolatility(vol);
         setCouponPricer(floatingRateBond.cashflows(),pricer);
         
         forecastingTermStructure.
linkTo(depoSwapTermStructure);
         discountingTermStructure.linkTo(bondDiscountingTermStructure);
         
         liborTermStructure.linkTo(depoSwapTermStructure);
         
         std::cout << std::endl;
         
         Size widths[] = { 18, 10, 10, 10 };
          std::cout << std::setw(widths[0]) <<  "                 "
         << std::setw(widths[1]) << "ZC"
         << std::setw(widths[2]) << "Fixed"
         << std::setw(widths[3]) << "Floating"
         << std::endl;
         Size width = widths[0] + widths[1] + widths[2] + widths[3];
          std::string rule(width, '-');
         std::cout << rule << std::endl;
         std::cout << std::fixed;
         std::cout << std::setprecision(2);
         std::cout << std::setw(widths[0]) << "Net present value"
         << std::setw(widths[1]) << zeroCouponBond.NPV()
         << std::setw(widths[2]) << fixedRateBond.NPV()
         << std::setw(widths[3]) << floatingRateBond.NPV()
         << std::endl;
         std::cout << std::setw(widths[0]) << "Clean price"
         << std::setw(widths[1]) << zeroCouponBond.cleanPrice()
         << std::setw(widths[2]) << fixedRateBond.cleanPrice()
         << std::setw(widths[3]) << floatingRateBond.cleanPrice()
         << std::endl;
         std::cout << std::setw(widths[0]) << "Dirty price"
         << std::setw(widths[1]) << zeroCouponBond.dirtyPrice()
         << std::setw(widths[2]) << fixedRateBond.dirtyPrice()
         << std::setw(widths[3]) << floatingRateBond.dirtyPrice()
         << std::endl;
         std::cout << std::setw(widths[0]) << "Accrued coupon"
         << std::setw(widths[1]) << zeroCouponBond.accruedAmount()
         << std::setw(widths[2]) << fixedRateBond.accruedAmount()
         << std::setw(widths[3]) << floatingRateBond.accruedAmount()
         << std::endl;
         std::cout << std::setw(widths[0]) << "Previous coupon"
         << std::setw(widths[1]) << "N/A" 
         << std::setw(widths[2]) << 
io::rate(fixedRateBond.previousCouponRate())
         << std::setw(widths[3]) << 
io::rate(floatingRateBond.previousCouponRate())
         << std::endl;
         std::cout << std::setw(widths[0]) << "Next coupon"
         << std::setw(widths[1]) << "N/A" 
         << std::setw(widths[2]) << 
io::rate(fixedRateBond.nextCouponRate())
         << std::setw(widths[3]) << 
io::rate(floatingRateBond.nextCouponRate())
         << std::endl;
         std::cout << std::setw(widths[0]) << "Yield"
         << std::setw(widths[1])
         << std::setw(widths[2])
         << std::setw(widths[3])
         << std::endl;
         std::cout << std::endl;
         
         std::cout << "Sample indirect computations (for the floating rate bond): " << std::endl;
         std::cout << rule << std::endl;
         std::cout << "Yield to Clean Price: "
         std::cout << "Clean Price to Yield: "
         
         double seconds = timer.elapsed();
         seconds -= hours * 3600;
         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;
         return 0;
    } catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
        return 1;
    } catch (...) {
        std::cerr << "unknown error" << std::endl;
        return 1;
    }
}