QuantLib - Pricing Swaps

Hi all,

I am very new to both swaps and QuantLib, I have had a look at the pricing demo spreadsheet using QL as an .xll, I have a couple of questions about pricing swaps however.

I understand the basic concept of a swap (with a fixed and floating leg), however, after you have constructed a discount curve with the deposit/swap helpers in QL you have the NPV of the fixed leg. For the floating leg, however, you need the estimated forward rate.

I am a little confused about the classes such as (qlEuribor), used in the example, which takes inputs (ObjectID,Tenor(6M),YieldCurve(from bootstrap),Permanent,Trigger). After generation of the yield curve, what does the qlEuribor class do with just the Tenor and Yieldcruve? does it extract the forward rate from the yield curve? and is this pricing a swap using the Euribor rate? i.e would you switch the class to qlLibor to price using Libor?

Many thanks,

Hi Hob,

the QuantLib Project Suite contains a sample project Swap.
At best you debug it step by step :)

However, QuantLib is not easy.
If you are seriously going to learn it, have a look at this thread.
Hi Hob,

To start with it isn‘t necessary in QuantLib to construct a curve by bootstrapping to some rates or instruments, you can use the yieldTermStructures InterpolatedZeroCurve, InterpolatedForwardCurve, or InterpolatedDiscountCurve classes where you can just plug in the dates and rates and some interpolation type.

Since one leg in your swap are floating coupons in that leg has to be linked to some interest rate index. You could use just IborIndex class in quantlib (IborIndex derives from class InterestRateIndex).

The EurIbor class derives from IborIndex and just filles in some default values in the IborIndex constructur (for example which calendar to use, business day convention...).

The argument tenor in EurIbor is just the tenor of the Index for example quantlib offers some classes for EurIbor 1W,2W,1m,3m where you only need to add some yieldCurve which is used to estimate the forward rates. The yieldcurve is therefore used to forecast the index fixings (uses forward rates from the provided yield curve).

Let’s say you have constructed an IborIndex 6m which also has some underlying yieldcurve. The goal is to calculate the npv of a floating coupon which has a start date 1.6.2015.

The amount of the coupon is calculate as: nominal * rate * accrual time period

To estimate the rate the coupon calls a member function of the interest rate index called: Fixing

That function check the fixing date of the coupon (usually start date – number of fixing days and then adjusted to the current business day convention) and then compares that that with quantlib evaluation date (which is the date that qunatlib does all calculations under). If the fixing date is smaller than the evaluation date the index has to check historical index fixings which are provided be the user with addFixing member function of the index.

If the fixing date is larger than the evaluation date then the index uses forward rates. Since we have a 6m index the forward rates would be caluclated as:

Discount Factor at the fixing date (d1)

Discount Factor at fixing date advanced by 6months and adjusted for some businessday convention

Forward rate: (d1 / d2 – 1 ) / fraction between the dates with some daycounter rule.

The forward rate plus possible some spread is then used as rate when calculating the payment amount in the coupon.

Hopes this helps.