SlideShare a Scribd company logo
1 of 28
QuantLib for Fixed Income
Products
-Jun Hong
Fixed income refers to any type of investment under which the borrower(issuer) is
obliged to make payments of a fixed amount (coupons and face value) on a fixed
schedule.
Up front, the investor longs the bond and pay 8,500. The sellor has to pay her the coupons by a fixed
schedule. At the maturity, the last coupon and the principal are paid.
Basic Business Knowledge
• Bonds and notes are quoted by clean prices and settled by dirty prices
• Dirty price is also called full price or invoice price
• Dirty price = clean price + accrued interest
• Accrued interest (AI) is the interest that has accumulated since the previous coupon payment
date
• Why don’t we quote the dirty prices? AI will arise and drop to zero basing on the coupon schedule
and that will distort the price
• Note that bonds are settled by dirty price and compared by yield to maturity because the
coupons are bonds different
• US treasury products consists of bills (12m and less), notes (<10 Year), and bonds (10 to 30 Year).
In addition we have STRIPS and TIPS.
• Bills are zero coupon products quoted by discount rate
Major QuantLib Classes for Fixed Income Analytics
• Cashflows and Cashflow: fixed income is mainly about cash flows. Cashflows is a tool box for Cashflow handling
• Schedule: helps to find out the dates for the cash flows
• DayCounter: for day count method. e.g. ACT/ACT
• BusinessDayConvention: for cash flow date adjustment
• Coupon: coupon is a subclass of Cashflow class
• Calendar: help to figure out holidays and business days
• InterestRate: has methods for rates related calculation
• Bond and FixedRateBond: fixed rate bond is a basic one we need to focus on
• We have classes for floaters, zero coupons, and inflation linked bonds (CPIBond)
• BondFuctions: helper class for cash flow related calculation
• BondHelper: helper class to link bond and curve together
• There are examples over QuantLib 1.7test-suitebonds.cpp and QuantLib1.7ExamplesBondsBonds.cpp
CashFlow, Coupon, and FixedRateCoupon
• CashFlow: it has information about the date and amount of cash flow
• Leg: It is a vector of CashFlow
typedef std::vector<boost::shared_ptr<CashFlow> > Leg;
• Coupon: implements part of the CashFlow interface but it is still abstract. It
provides derived classes with methods related to accrued interest calculation.
• FixedRateCoupon:
• FixedRateLeg: helper class building a sequence of fixed rate coupons
Class Calendar.hpp
• This class provides methods for determining whether a date is a business day or a
holiday for a given market.
• It is used for incrementing/decrementing a date of a given number of business
days e.g. T+1
• Evaluation date is not that important for most calculations and we care more
about the settlement date.
• Period class is a time unit we frequently use and it could be year, month, week, or
day.
Settlement Day
Settlement is more important than evaluation day. For example, a bond with
different evaluation days but the same settlement day would have the same price if
you pass different yield to maturity.
BusinessDayConvention.hpp
• These conventions specify the methods used to adjust a date in case it is not a
business day
Method Description
Following Choose the first business day after the given holiday.
Preceding Choose the first business day before the given holiday
Modified Following Choose the first business day after the given holiday unless it belongs to a different month, in
which case choose the first business day before the holiday.
Modified Preceding Choose the first business day before the given holiday unless it belongs to a different month, in
which case choose the first business day after the holiday.
Unadjusted Do not adjust
Nearest Choose the nearest business day to the given holiday. If both the preceding and following
business days are equally far away, default to following business day
Half Month Modified Following Choose the first business day after the given holiday unless that day crosses the mid-month
(15th) or the end of month, in which case choose the first business day before the holiday
Reference Data for a Fixed Income Products
• Straight forward concepts like maturity or coupon will not be explained here.
• Settlement Date: The is the date on which a trade is cleared. Namely, money and
product change hands.
• Issue Date: This is the earliest date on which the settlement can occur.
• Dated Date: This is the date from which the interest starts to accrue. It can be on,
before, or after the issue date. The dated date must be less than two normal
coupon periods before the first coupon date.
• Last Coupon Date: This is the last coupon date prior to maturity date. Note there
is a coupon payment on the maturity date but that is not called the last coupon
date.
About the Cash Flows
• First coupon period, regular coupon period, and last coupon period
• The first coupon period and last coupon period could be short, long,
or normal. The regular coupon periods are always normal.
First
Coupon
Period
Last
Coupon
Period
Regular
Coupon
Periods
About the Irregular First Coupon Period
• Normally the dated date is the same as issue date
• Short first coupon period
• Long first coupon period
Pseudo
Issue
Date
Normal
Issue
Date
First
Coupon
Date
Dated
Date
Normal
Issue
Date
First
Coupon
Date
Dated
Date
About the Irregular Last Coupon Period
• In most case normal maturity date is the same as maturity date
• Short first coupon period
LCF = (MD – LCD)/(NMD – LCD)
• Long first coupon period
LCF = 1+(MD – NMD)/(PMD – NMD)
Last
Coupon
Date
Normal
Maturity
Date
Pseudo
Maturity
Date
Maturity
Date
Last
Coupon
Date
Normal
Maturity
Date
Maturity
Date
Day Count Methods (DCM)
• QuantLib has the above DCM under QuntLib-1.7qltimedaycounters folder
• ACT/ACT
• ACT/365
• ACT(NL)/365: Feb 29 is not counted
• ACT/365(366 in a leap year)
• ACT/360
• 30/360
• 30/365 and 30E/360 are added to QuantLib yet
Some Examples for DCM
• ACT/ACT
D2-D1
Mar 1 to Mar 31 -> 30 days
Mar 1 to Apr 1 -> 31 days
• 30/360: each month counts as 30 days
Number od days = (Y2-Y1)360+(M2-M1)30+(D2-D1)
D2-D1
Mar 1 to Mar 31 -> 30 days
Mar 1 to Mar 30 -> 29 days
Mar 1 to Apr 1 -> 30 days
• 30E/360: the 31st is treated as if it was the 30th
D2-D1
Mar 1 to Mar 31 -> 29 days
Mar 1 to Mar 30 -> 29 days
Mar 1 to Apr 1 -> 30 days
Accrued Interest and DCM
• Accrued Interest is affected by the day count method
Previous Cpn
1/15/2016
Next Cpn
7/15/2016
Settlement
5/31/2016
DCM Jan 15 to May 31 Jan 15 to Jul 15 AIF
Act/Act 137 182 137/182
Act/365 137 365/2 137/182.5
Act(NL)/365 136 (Feb 29 not counted) 365/2 136/182.5
Act/360 137 360/2 137/180
30/360 136: (5-1)30+31-15 360/2 136/180
30/365 136 365/2 136/182.5
30E/360 136: (5-1)30+30-15 360/2 135/180
Ex-Dividend Trading
• Exist in some countries such as Australia and South Afarica
• Happens when the settlement date is on or after ex-dividend date and before the
next coupon date
Schedule.hpp
• This class is used to generate cash flow schedule. Fixed income is all about cash flows and
discounting.
• The date from the first to the last coupon period is very predictable except the end of month
adjustment. The first and last coupon period could be long or short. That is why the first coupon
date and the last coupon date are important. Issue date and maturity dates help on defining the
first and last coupon periods.
• End of month adjustment:
• If the
• QuantLib terminologies in this class may not match the bond products that well and here is a few
I noticed …
• effectiveDate: dated date
• terminationDate: maturity date
• firstDate: first coupon date
• nextToLastDate: last coupon date
CashFlows.hpp
• Note CashFlows is different from CashFlow and it is a tool box for Cashflow
handling
• It provides methods for cash flow iteration, accrued interest, net present value
(yield to price), price to yield conversion, dv01, duration, modified duration,
convexity, z-spread, and par rates calculations.
• Net present value (npv) could also be done via a curve discounting
• Fixed income pricing is all about discount the cash flows using a curve.
• Price and Yield conversion doesn’t depend on a yield curve and a formula is
sufficient.
Class InterestRate.hpp
• This class encapsulates the interest rate compounding algebra.
• It manages day count conventions, frequency, compounding conventions, and conversion
between different conventions.
• It handles compound (discount) factor calculations, and implied and equivalent rate
calculations.
• Supports simple, compounded, continuous, simple then compounded methods to
calculate discount factor
Simple: 1+(r/f)*fraction
Compounded: (1+r/f)^(n+ fraction)
Continuous: e^(rt)
Simple then compounded: use simple for the first period and compounded
for the rest of cash flows
fraction = number of days / period length
When Settlement Date is not in the Last Coupon Period
𝐂𝐥𝐞𝐚𝐧 𝐏𝐫𝐢𝐜𝐞 =
𝟏
(𝟏 +
𝒀
𝒇
) 𝑫𝑭
× {
𝒄
𝒇
+
𝒄
𝒀
𝟏 −
𝟏
𝟏 +
𝒀
𝒇
𝐧 + (𝐏𝐚𝐫 +
𝒄
𝒇
× 𝑳𝑪𝑭) ×
𝟏
𝟏 +
𝒀
𝒇
𝐧+𝐋𝐃𝐅} −
𝒄
𝒇
× 𝑨𝑰𝑭
Y: yield to maturity
f: frequency of coupon. 2 for semiannual
c: coupon
Par: redemption
LCF: last coupon factor is used to calculate the cpn on maturity date
LDF: used to discount cash flow at the maturity to last coupon date
n: number of coupon remaining – 2
AIF: accrued interest factor
Price Yield Formula Explained
𝐂𝐥𝐞𝐚𝐧 𝐏𝐫𝐢𝐜𝐞 =
𝟏
(𝟏 +
𝒀
𝒇
) 𝑫𝑭
× {
𝒄
𝒇
+
𝒄
𝒀
𝟏 −
𝟏
𝟏 +
𝒀
𝒇
𝐧 + (𝐏𝐚𝐫 +
𝒄
𝒇
× 𝑳𝑪𝑭) ×
𝟏
𝟏 +
𝒀
𝒇
𝐧+𝐋𝐃𝐅} −
𝒄
𝒇
× 𝑨𝑰𝑭
𝐂𝐥𝐞𝐚𝐧 𝐏𝐫𝐢𝐜𝐞 = 𝑫𝒊𝒔𝒄𝒐𝒖𝒏𝒕 𝒇𝒓𝒐𝒎 𝑪 𝒕𝒐 𝑩 × 𝑪𝒑𝒏 𝒂𝒕 𝑪 + 𝑪𝒑𝒏 𝒇𝒓𝒐𝒎 𝑫 𝒕𝒐 𝑬 + 𝑷𝒂𝒓 𝒂𝒏𝒅 𝑳𝒂𝒔𝒕 𝑪𝒑𝒏 − 𝑨𝑰
When Settlement Date is in the Last Coupon Period
It is quite common to use simple interest rate when only one period is left
Bond Inheritance Tree
The current bond tree
Bond interface defines methods such as accrued interest not meaningful for zero coupon bond. In the future, it makes
more sense to have a tree like this.
CPIBond is essentially a floating rate via adjusting the principal. We might want to put it together with floaters.
Bond
ZeroCouponBond FloatingRateBond FixedRateBond CPIBond
CouponBond
ZeroCouponBond FloatingRateBond FixedRateBondCPIBond
Bond
Class Bond.hpp
• Constructor
• accruedAmount(): calculate the accrued interest
• cleanPrice() and yield() methods: price and yield conversion
• Provide access to cashflow
It is quite natural to use schedule to specify the cash flow dates and pass the
settlement date, face value, coupon rate, DCM, payment convention, notional, and
issue date to build a bond.
Class FixedRateBond.cpp – Construct a Bond
Some thoughts to share
• Reading the code without any background knowledge is doable but time
consuming. That is why I prepared this document.
• Product knowledge is indispensable and there a lot of books and web sites for
that. Learning product knowledge by reading the QuantLib code is not
productive. I found myself in most case have a big picture and end up finding the
practical details in the code.
• It would be helpful to use a spread sheet to work out the details and then
implement it in QuantLib. It is indirect but effective.
Here is a Spread Sheet Example for Chinese Government Bond
To be continued …
• I am going to write about index lined bond like TIPS
• If you see any error in this document, please email me at
jhong111@yahoo.com and I will correct it accordingly

More Related Content

What's hot

interest rate parity
interest rate parityinterest rate parity
interest rate parityvijukrish
 
The Portfolio Management Process.ppt
The Portfolio Management Process.pptThe Portfolio Management Process.ppt
The Portfolio Management Process.pptYinka Daramola
 
Currency Derivatives
Currency DerivativesCurrency Derivatives
Currency DerivativesICAB
 
Equity instruments ppt
Equity instruments pptEquity instruments ppt
Equity instruments pptGulshanS4
 
International portfolio management basics
International  portfolio management basicsInternational  portfolio management basics
International portfolio management basicsmadydey
 
Diapositiva esposicion sistema financiero
Diapositiva esposicion sistema financieroDiapositiva esposicion sistema financiero
Diapositiva esposicion sistema financieroDANILOHUERA
 
Introduction to fixed income securities
Introduction to fixed income securitiesIntroduction to fixed income securities
Introduction to fixed income securitiesSameen Zaidi
 
Valuation of bond and shares
Valuation of bond and sharesValuation of bond and shares
Valuation of bond and sharesstudent
 
Pull Back Swing Trading Strategy I The Only Way To Trade Stocks and E-Mini Re...
Pull Back Swing Trading Strategy I The Only Way To Trade Stocks and E-Mini Re...Pull Back Swing Trading Strategy I The Only Way To Trade Stocks and E-Mini Re...
Pull Back Swing Trading Strategy I The Only Way To Trade Stocks and E-Mini Re...Marketgeekschannel
 
Diferencias en tre devaluacion y depreciacion del dinero unh ing sistemas
Diferencias en tre devaluacion y depreciacion del dinero unh ing sistemasDiferencias en tre devaluacion y depreciacion del dinero unh ing sistemas
Diferencias en tre devaluacion y depreciacion del dinero unh ing sistemasmichaz
 
Tema 11 - El dinero, los bancos y la política monetaria
Tema 11 - El dinero, los bancos y la política monetaria Tema 11 - El dinero, los bancos y la política monetaria
Tema 11 - El dinero, los bancos y la política monetaria anaguiber
 
Portfolio management strategies
Portfolio management strategiesPortfolio management strategies
Portfolio management strategiesBikash Kumar
 
Indian Capital Markets Basic
Indian Capital Markets BasicIndian Capital Markets Basic
Indian Capital Markets BasicAbhijeet Deshmukh
 
Trading and settelment in stock exchange..docx1
Trading and settelment in stock exchange..docx1Trading and settelment in stock exchange..docx1
Trading and settelment in stock exchange..docx1Rajvi Dedhia
 
International monetary system
International monetary systemInternational monetary system
International monetary systemVishnu Vijay
 
Index funds & its effects on indian economy
Index funds & its effects on indian economyIndex funds & its effects on indian economy
Index funds & its effects on indian economySayoni Ghosh
 

What's hot (20)

interest rate parity
interest rate parityinterest rate parity
interest rate parity
 
The Portfolio Management Process.ppt
The Portfolio Management Process.pptThe Portfolio Management Process.ppt
The Portfolio Management Process.ppt
 
Currency Derivatives
Currency DerivativesCurrency Derivatives
Currency Derivatives
 
Financial services lecture notes
Financial services lecture notesFinancial services lecture notes
Financial services lecture notes
 
Equity instruments ppt
Equity instruments pptEquity instruments ppt
Equity instruments ppt
 
International portfolio management basics
International  portfolio management basicsInternational  portfolio management basics
International portfolio management basics
 
Currency derivatives
Currency derivativesCurrency derivatives
Currency derivatives
 
Diapositiva esposicion sistema financiero
Diapositiva esposicion sistema financieroDiapositiva esposicion sistema financiero
Diapositiva esposicion sistema financiero
 
Introduction to fixed income securities
Introduction to fixed income securitiesIntroduction to fixed income securities
Introduction to fixed income securities
 
Technical analysis
Technical analysisTechnical analysis
Technical analysis
 
Valuation of bond and shares
Valuation of bond and sharesValuation of bond and shares
Valuation of bond and shares
 
Pull Back Swing Trading Strategy I The Only Way To Trade Stocks and E-Mini Re...
Pull Back Swing Trading Strategy I The Only Way To Trade Stocks and E-Mini Re...Pull Back Swing Trading Strategy I The Only Way To Trade Stocks and E-Mini Re...
Pull Back Swing Trading Strategy I The Only Way To Trade Stocks and E-Mini Re...
 
Diferencias en tre devaluacion y depreciacion del dinero unh ing sistemas
Diferencias en tre devaluacion y depreciacion del dinero unh ing sistemasDiferencias en tre devaluacion y depreciacion del dinero unh ing sistemas
Diferencias en tre devaluacion y depreciacion del dinero unh ing sistemas
 
Tema 11 - El dinero, los bancos y la política monetaria
Tema 11 - El dinero, los bancos y la política monetaria Tema 11 - El dinero, los bancos y la política monetaria
Tema 11 - El dinero, los bancos y la política monetaria
 
Portfolio management strategies
Portfolio management strategiesPortfolio management strategies
Portfolio management strategies
 
Indian Capital Markets Basic
Indian Capital Markets BasicIndian Capital Markets Basic
Indian Capital Markets Basic
 
Stock Valuation
Stock ValuationStock Valuation
Stock Valuation
 
Trading and settelment in stock exchange..docx1
Trading and settelment in stock exchange..docx1Trading and settelment in stock exchange..docx1
Trading and settelment in stock exchange..docx1
 
International monetary system
International monetary systemInternational monetary system
International monetary system
 
Index funds & its effects on indian economy
Index funds & its effects on indian economyIndex funds & its effects on indian economy
Index funds & its effects on indian economy
 

Similar to QuantLib Bond Analytics Tutorial

Foreign exchange arithmetic
Foreign exchange arithmetic Foreign exchange arithmetic
Foreign exchange arithmetic rajat_prasad
 
engineering economics.pptx
engineering economics.pptxengineering economics.pptx
engineering economics.pptxJacobMallari3
 
ch14- LONG TERM LIABILITIES.ppt
ch14- LONG TERM LIABILITIES.pptch14- LONG TERM LIABILITIES.ppt
ch14- LONG TERM LIABILITIES.pptmorium2
 
#CFA: Revise entire CFA syllabus 6 days-Equity & Fixed Income
#CFA: Revise entire CFA syllabus 6 days-Equity & Fixed Income#CFA: Revise entire CFA syllabus 6 days-Equity & Fixed Income
#CFA: Revise entire CFA syllabus 6 days-Equity & Fixed Income13 Llama Interactive
 
Econ315 Money and Banking: Learning Unit #09: Interest Rate
Econ315 Money and Banking: Learning Unit #09: Interest RateEcon315 Money and Banking: Learning Unit #09: Interest Rate
Econ315 Money and Banking: Learning Unit #09: Interest Ratesakanor
 
The analysis and valuation of bonds copy
The analysis and valuation of bonds   copyThe analysis and valuation of bonds   copy
The analysis and valuation of bonds copyKristelle Borres
 
Fixed Income Securities Yield Measures.pptx
Fixed Income Securities Yield Measures.pptxFixed Income Securities Yield Measures.pptx
Fixed Income Securities Yield Measures.pptxanurag202001
 
1 Time Value of Money_.pptx .
1 Time Value of Money_.pptx               .1 Time Value of Money_.pptx               .
1 Time Value of Money_.pptx .Athar739197
 
Financial fucntions in ms e xcel
Financial fucntions in ms e xcelFinancial fucntions in ms e xcel
Financial fucntions in ms e xcelDr. Prashant Vats
 
Subscribed 2017 - Workshop: ASC 606 Application For Subscription Companies
Subscribed 2017 - Workshop: ASC 606 Application For Subscription CompaniesSubscribed 2017 - Workshop: ASC 606 Application For Subscription Companies
Subscribed 2017 - Workshop: ASC 606 Application For Subscription CompaniesZuora, Inc.
 
Time Value Of Money F F M
Time  Value Of  Money   F F MTime  Value Of  Money   F F M
Time Value Of Money F F MZoha Qureshi
 
Meeting 5 - Receivables management (Financial Management)
Meeting 5 - Receivables management (Financial Management)Meeting 5 - Receivables management (Financial Management)
Meeting 5 - Receivables management (Financial Management)Albina Gaisina
 
Financial Planning, Time Value of Money, and Working Capital Policies
Financial Planning, Time Value of Money, and Working Capital PoliciesFinancial Planning, Time Value of Money, and Working Capital Policies
Financial Planning, Time Value of Money, and Working Capital PoliciesJudy Ney
 
acctg MBA slide
 acctg MBA slide acctg MBA slide
acctg MBA slidekoko20115
 
Backupoffinancialmaths 110417080452-phpapp02
Backupoffinancialmaths 110417080452-phpapp02Backupoffinancialmaths 110417080452-phpapp02
Backupoffinancialmaths 110417080452-phpapp02Banele Ngomane
 
2. concepts and conventions of accounting mba 1st tri semester
2. concepts and conventions of accounting mba 1st tri semester2. concepts and conventions of accounting mba 1st tri semester
2. concepts and conventions of accounting mba 1st tri semesterKaran Kukreja
 

Similar to QuantLib Bond Analytics Tutorial (20)

Foreign exchange arithmetic
Foreign exchange arithmetic Foreign exchange arithmetic
Foreign exchange arithmetic
 
engineering economics.pptx
engineering economics.pptxengineering economics.pptx
engineering economics.pptx
 
ch14- LONG TERM LIABILITIES.ppt
ch14- LONG TERM LIABILITIES.pptch14- LONG TERM LIABILITIES.ppt
ch14- LONG TERM LIABILITIES.ppt
 
#CFA: Revise entire CFA syllabus 6 days-Equity & Fixed Income
#CFA: Revise entire CFA syllabus 6 days-Equity & Fixed Income#CFA: Revise entire CFA syllabus 6 days-Equity & Fixed Income
#CFA: Revise entire CFA syllabus 6 days-Equity & Fixed Income
 
Econ315 Money and Banking: Learning Unit #09: Interest Rate
Econ315 Money and Banking: Learning Unit #09: Interest RateEcon315 Money and Banking: Learning Unit #09: Interest Rate
Econ315 Money and Banking: Learning Unit #09: Interest Rate
 
The analysis and valuation of bonds copy
The analysis and valuation of bonds   copyThe analysis and valuation of bonds   copy
The analysis and valuation of bonds copy
 
Fixed Income Securities Yield Measures.pptx
Fixed Income Securities Yield Measures.pptxFixed Income Securities Yield Measures.pptx
Fixed Income Securities Yield Measures.pptx
 
Formulas
FormulasFormulas
Formulas
 
1 Time Value of Money_.pptx .
1 Time Value of Money_.pptx               .1 Time Value of Money_.pptx               .
1 Time Value of Money_.pptx .
 
Financial fucntions in ms e xcel
Financial fucntions in ms e xcelFinancial fucntions in ms e xcel
Financial fucntions in ms e xcel
 
Subscribed 2017 - Workshop: ASC 606 Application For Subscription Companies
Subscribed 2017 - Workshop: ASC 606 Application For Subscription CompaniesSubscribed 2017 - Workshop: ASC 606 Application For Subscription Companies
Subscribed 2017 - Workshop: ASC 606 Application For Subscription Companies
 
Time Value Of Money F F M
Time  Value Of  Money   F F MTime  Value Of  Money   F F M
Time Value Of Money F F M
 
Meeting 5 - Receivables management (Financial Management)
Meeting 5 - Receivables management (Financial Management)Meeting 5 - Receivables management (Financial Management)
Meeting 5 - Receivables management (Financial Management)
 
Financial Planning, Time Value of Money, and Working Capital Policies
Financial Planning, Time Value of Money, and Working Capital PoliciesFinancial Planning, Time Value of Money, and Working Capital Policies
Financial Planning, Time Value of Money, and Working Capital Policies
 
acctg MBA slide
 acctg MBA slide acctg MBA slide
acctg MBA slide
 
Valuation bond
Valuation bondValuation bond
Valuation bond
 
Anualidades.
Anualidades.Anualidades.
Anualidades.
 
Backupoffinancialmaths 110417080452-phpapp02
Backupoffinancialmaths 110417080452-phpapp02Backupoffinancialmaths 110417080452-phpapp02
Backupoffinancialmaths 110417080452-phpapp02
 
2. concepts and conventions of accounting mba 1st tri semester
2. concepts and conventions of accounting mba 1st tri semester2. concepts and conventions of accounting mba 1st tri semester
2. concepts and conventions of accounting mba 1st tri semester
 
Principle Of Accounting
Principle Of AccountingPrinciple Of Accounting
Principle Of Accounting
 

Recently uploaded

Benefits & Risk Of Stock Loans
Benefits & Risk Of Stock LoansBenefits & Risk Of Stock Loans
Benefits & Risk Of Stock LoansMartinRowse
 
一比一原版(WashU毕业证书)圣路易斯华盛顿大学毕业证成绩单学位证书
一比一原版(WashU毕业证书)圣路易斯华盛顿大学毕业证成绩单学位证书一比一原版(WashU毕业证书)圣路易斯华盛顿大学毕业证成绩单学位证书
一比一原版(WashU毕业证书)圣路易斯华盛顿大学毕业证成绩单学位证书atedyxc
 
Economic Risk Factor Update: May 2024 [SlideShare]
Economic Risk Factor Update: May 2024 [SlideShare]Economic Risk Factor Update: May 2024 [SlideShare]
Economic Risk Factor Update: May 2024 [SlideShare]Commonwealth
 
amil baba in australia amil baba in canada amil baba in london amil baba in g...
amil baba in australia amil baba in canada amil baba in london amil baba in g...amil baba in australia amil baba in canada amil baba in london amil baba in g...
amil baba in australia amil baba in canada amil baba in london amil baba in g...israjan914
 
NO1 Top Vashikaran Specialist in Uk Black Magic Specialist in Uk Black Magic ...
NO1 Top Vashikaran Specialist in Uk Black Magic Specialist in Uk Black Magic ...NO1 Top Vashikaran Specialist in Uk Black Magic Specialist in Uk Black Magic ...
NO1 Top Vashikaran Specialist in Uk Black Magic Specialist in Uk Black Magic ...Amil baba
 
Managing personal finances wisely for financial stability and
Managing personal finances wisely for financial stability  andManaging personal finances wisely for financial stability  and
Managing personal finances wisely for financial stability andraqibmifysolutions
 
kala jadu for love | world no 1 amil baba | best amil baba in karachi |bangal...
kala jadu for love | world no 1 amil baba | best amil baba in karachi |bangal...kala jadu for love | world no 1 amil baba | best amil baba in karachi |bangal...
kala jadu for love | world no 1 amil baba | best amil baba in karachi |bangal...israjan914
 
NO1 Best kala jadu karne wale ka contact number kala jadu karne wale baba kal...
NO1 Best kala jadu karne wale ka contact number kala jadu karne wale baba kal...NO1 Best kala jadu karne wale ka contact number kala jadu karne wale baba kal...
NO1 Best kala jadu karne wale ka contact number kala jadu karne wale baba kal...Amil baba
 
Retail sector trends for 2024 | European Business Review
Retail sector trends for 2024  | European Business ReviewRetail sector trends for 2024  | European Business Review
Retail sector trends for 2024 | European Business ReviewAntonis Zairis
 
Prezentacja Q1 2024 EN strona www relacji
Prezentacja Q1 2024  EN strona www relacjiPrezentacja Q1 2024  EN strona www relacji
Prezentacja Q1 2024 EN strona www relacjiklaudiafilka
 
FEW OF THE DEVELOPMENTS FOUND IN LESOTHO
FEW OF THE DEVELOPMENTS FOUND IN LESOTHOFEW OF THE DEVELOPMENTS FOUND IN LESOTHO
FEW OF THE DEVELOPMENTS FOUND IN LESOTHOMantsepisengTubatsi
 
20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf
20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf
20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdfAdnet Communications
 
certified amil baba ,black magic specialist in russia and kala jadu expert in...
certified amil baba ,black magic specialist in russia and kala jadu expert in...certified amil baba ,black magic specialist in russia and kala jadu expert in...
certified amil baba ,black magic specialist in russia and kala jadu expert in...israjan914
 
一比一原版(UC Davis毕业证书)加州大学戴维斯分校毕业证成绩单学位证书
一比一原版(UC Davis毕业证书)加州大学戴维斯分校毕业证成绩单学位证书一比一原版(UC Davis毕业证书)加州大学戴维斯分校毕业证成绩单学位证书
一比一原版(UC Davis毕业证书)加州大学戴维斯分校毕业证成绩单学位证书atedyxc
 
Module 1 CCP - Introduction and LMS.pptx
Module 1 CCP  - Introduction and LMS.pptxModule 1 CCP  - Introduction and LMS.pptx
Module 1 CCP - Introduction and LMS.pptxbaharudinbn
 
ACC311_Corporate Income Taxation in the Philippines
ACC311_Corporate Income Taxation  in the PhilippinesACC311_Corporate Income Taxation  in the Philippines
ACC311_Corporate Income Taxation in the PhilippinesAdrinneFlores
 
The Pfandbrief Roundtable 2024 - Covered Bonds
The Pfandbrief Roundtable 2024 - Covered BondsThe Pfandbrief Roundtable 2024 - Covered Bonds
The Pfandbrief Roundtable 2024 - Covered BondsNeil Day
 
一比一原版(SFU毕业证书)西蒙菲莎大学毕业证成绩单学位证书
一比一原版(SFU毕业证书)西蒙菲莎大学毕业证成绩单学位证书一比一原版(SFU毕业证书)西蒙菲莎大学毕业证成绩单学位证书
一比一原版(SFU毕业证书)西蒙菲莎大学毕业证成绩单学位证书atedyxc
 
原版一模一样(bu文凭证书)美国贝翰文大学毕业证文凭证书制作
原版一模一样(bu文凭证书)美国贝翰文大学毕业证文凭证书制作原版一模一样(bu文凭证书)美国贝翰文大学毕业证文凭证书制作
原版一模一样(bu文凭证书)美国贝翰文大学毕业证文凭证书制作uotyyd
 

Recently uploaded (20)

Benefits & Risk Of Stock Loans
Benefits & Risk Of Stock LoansBenefits & Risk Of Stock Loans
Benefits & Risk Of Stock Loans
 
一比一原版(WashU毕业证书)圣路易斯华盛顿大学毕业证成绩单学位证书
一比一原版(WashU毕业证书)圣路易斯华盛顿大学毕业证成绩单学位证书一比一原版(WashU毕业证书)圣路易斯华盛顿大学毕业证成绩单学位证书
一比一原版(WashU毕业证书)圣路易斯华盛顿大学毕业证成绩单学位证书
 
Economic Risk Factor Update: May 2024 [SlideShare]
Economic Risk Factor Update: May 2024 [SlideShare]Economic Risk Factor Update: May 2024 [SlideShare]
Economic Risk Factor Update: May 2024 [SlideShare]
 
amil baba in australia amil baba in canada amil baba in london amil baba in g...
amil baba in australia amil baba in canada amil baba in london amil baba in g...amil baba in australia amil baba in canada amil baba in london amil baba in g...
amil baba in australia amil baba in canada amil baba in london amil baba in g...
 
NO1 Top Vashikaran Specialist in Uk Black Magic Specialist in Uk Black Magic ...
NO1 Top Vashikaran Specialist in Uk Black Magic Specialist in Uk Black Magic ...NO1 Top Vashikaran Specialist in Uk Black Magic Specialist in Uk Black Magic ...
NO1 Top Vashikaran Specialist in Uk Black Magic Specialist in Uk Black Magic ...
 
Managing personal finances wisely for financial stability and
Managing personal finances wisely for financial stability  andManaging personal finances wisely for financial stability  and
Managing personal finances wisely for financial stability and
 
kala jadu for love | world no 1 amil baba | best amil baba in karachi |bangal...
kala jadu for love | world no 1 amil baba | best amil baba in karachi |bangal...kala jadu for love | world no 1 amil baba | best amil baba in karachi |bangal...
kala jadu for love | world no 1 amil baba | best amil baba in karachi |bangal...
 
NO1 Best kala jadu karne wale ka contact number kala jadu karne wale baba kal...
NO1 Best kala jadu karne wale ka contact number kala jadu karne wale baba kal...NO1 Best kala jadu karne wale ka contact number kala jadu karne wale baba kal...
NO1 Best kala jadu karne wale ka contact number kala jadu karne wale baba kal...
 
SAUDI ARABIYA | +966572737505 |Jeddah Get Cytotec pills for Abortion pills
SAUDI ARABIYA | +966572737505 |Jeddah Get Cytotec pills for Abortion pillsSAUDI ARABIYA | +966572737505 |Jeddah Get Cytotec pills for Abortion pills
SAUDI ARABIYA | +966572737505 |Jeddah Get Cytotec pills for Abortion pills
 
Retail sector trends for 2024 | European Business Review
Retail sector trends for 2024  | European Business ReviewRetail sector trends for 2024  | European Business Review
Retail sector trends for 2024 | European Business Review
 
Prezentacja Q1 2024 EN strona www relacji
Prezentacja Q1 2024  EN strona www relacjiPrezentacja Q1 2024  EN strona www relacji
Prezentacja Q1 2024 EN strona www relacji
 
FEW OF THE DEVELOPMENTS FOUND IN LESOTHO
FEW OF THE DEVELOPMENTS FOUND IN LESOTHOFEW OF THE DEVELOPMENTS FOUND IN LESOTHO
FEW OF THE DEVELOPMENTS FOUND IN LESOTHO
 
20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf
20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf
20240514-Calibre-Q1-2024-Conference-Call-Presentation.pdf
 
certified amil baba ,black magic specialist in russia and kala jadu expert in...
certified amil baba ,black magic specialist in russia and kala jadu expert in...certified amil baba ,black magic specialist in russia and kala jadu expert in...
certified amil baba ,black magic specialist in russia and kala jadu expert in...
 
一比一原版(UC Davis毕业证书)加州大学戴维斯分校毕业证成绩单学位证书
一比一原版(UC Davis毕业证书)加州大学戴维斯分校毕业证成绩单学位证书一比一原版(UC Davis毕业证书)加州大学戴维斯分校毕业证成绩单学位证书
一比一原版(UC Davis毕业证书)加州大学戴维斯分校毕业证成绩单学位证书
 
Module 1 CCP - Introduction and LMS.pptx
Module 1 CCP  - Introduction and LMS.pptxModule 1 CCP  - Introduction and LMS.pptx
Module 1 CCP - Introduction and LMS.pptx
 
ACC311_Corporate Income Taxation in the Philippines
ACC311_Corporate Income Taxation  in the PhilippinesACC311_Corporate Income Taxation  in the Philippines
ACC311_Corporate Income Taxation in the Philippines
 
The Pfandbrief Roundtable 2024 - Covered Bonds
The Pfandbrief Roundtable 2024 - Covered BondsThe Pfandbrief Roundtable 2024 - Covered Bonds
The Pfandbrief Roundtable 2024 - Covered Bonds
 
一比一原版(SFU毕业证书)西蒙菲莎大学毕业证成绩单学位证书
一比一原版(SFU毕业证书)西蒙菲莎大学毕业证成绩单学位证书一比一原版(SFU毕业证书)西蒙菲莎大学毕业证成绩单学位证书
一比一原版(SFU毕业证书)西蒙菲莎大学毕业证成绩单学位证书
 
原版一模一样(bu文凭证书)美国贝翰文大学毕业证文凭证书制作
原版一模一样(bu文凭证书)美国贝翰文大学毕业证文凭证书制作原版一模一样(bu文凭证书)美国贝翰文大学毕业证文凭证书制作
原版一模一样(bu文凭证书)美国贝翰文大学毕业证文凭证书制作
 

QuantLib Bond Analytics Tutorial

  • 1. QuantLib for Fixed Income Products -Jun Hong
  • 2. Fixed income refers to any type of investment under which the borrower(issuer) is obliged to make payments of a fixed amount (coupons and face value) on a fixed schedule. Up front, the investor longs the bond and pay 8,500. The sellor has to pay her the coupons by a fixed schedule. At the maturity, the last coupon and the principal are paid.
  • 3. Basic Business Knowledge • Bonds and notes are quoted by clean prices and settled by dirty prices • Dirty price is also called full price or invoice price • Dirty price = clean price + accrued interest • Accrued interest (AI) is the interest that has accumulated since the previous coupon payment date • Why don’t we quote the dirty prices? AI will arise and drop to zero basing on the coupon schedule and that will distort the price • Note that bonds are settled by dirty price and compared by yield to maturity because the coupons are bonds different • US treasury products consists of bills (12m and less), notes (<10 Year), and bonds (10 to 30 Year). In addition we have STRIPS and TIPS. • Bills are zero coupon products quoted by discount rate
  • 4. Major QuantLib Classes for Fixed Income Analytics • Cashflows and Cashflow: fixed income is mainly about cash flows. Cashflows is a tool box for Cashflow handling • Schedule: helps to find out the dates for the cash flows • DayCounter: for day count method. e.g. ACT/ACT • BusinessDayConvention: for cash flow date adjustment • Coupon: coupon is a subclass of Cashflow class • Calendar: help to figure out holidays and business days • InterestRate: has methods for rates related calculation • Bond and FixedRateBond: fixed rate bond is a basic one we need to focus on • We have classes for floaters, zero coupons, and inflation linked bonds (CPIBond) • BondFuctions: helper class for cash flow related calculation • BondHelper: helper class to link bond and curve together • There are examples over QuantLib 1.7test-suitebonds.cpp and QuantLib1.7ExamplesBondsBonds.cpp
  • 5. CashFlow, Coupon, and FixedRateCoupon • CashFlow: it has information about the date and amount of cash flow • Leg: It is a vector of CashFlow typedef std::vector<boost::shared_ptr<CashFlow> > Leg; • Coupon: implements part of the CashFlow interface but it is still abstract. It provides derived classes with methods related to accrued interest calculation. • FixedRateCoupon: • FixedRateLeg: helper class building a sequence of fixed rate coupons
  • 6. Class Calendar.hpp • This class provides methods for determining whether a date is a business day or a holiday for a given market. • It is used for incrementing/decrementing a date of a given number of business days e.g. T+1 • Evaluation date is not that important for most calculations and we care more about the settlement date. • Period class is a time unit we frequently use and it could be year, month, week, or day.
  • 7. Settlement Day Settlement is more important than evaluation day. For example, a bond with different evaluation days but the same settlement day would have the same price if you pass different yield to maturity.
  • 8. BusinessDayConvention.hpp • These conventions specify the methods used to adjust a date in case it is not a business day Method Description Following Choose the first business day after the given holiday. Preceding Choose the first business day before the given holiday Modified Following Choose the first business day after the given holiday unless it belongs to a different month, in which case choose the first business day before the holiday. Modified Preceding Choose the first business day before the given holiday unless it belongs to a different month, in which case choose the first business day after the holiday. Unadjusted Do not adjust Nearest Choose the nearest business day to the given holiday. If both the preceding and following business days are equally far away, default to following business day Half Month Modified Following Choose the first business day after the given holiday unless that day crosses the mid-month (15th) or the end of month, in which case choose the first business day before the holiday
  • 9. Reference Data for a Fixed Income Products • Straight forward concepts like maturity or coupon will not be explained here. • Settlement Date: The is the date on which a trade is cleared. Namely, money and product change hands. • Issue Date: This is the earliest date on which the settlement can occur. • Dated Date: This is the date from which the interest starts to accrue. It can be on, before, or after the issue date. The dated date must be less than two normal coupon periods before the first coupon date. • Last Coupon Date: This is the last coupon date prior to maturity date. Note there is a coupon payment on the maturity date but that is not called the last coupon date.
  • 10. About the Cash Flows • First coupon period, regular coupon period, and last coupon period • The first coupon period and last coupon period could be short, long, or normal. The regular coupon periods are always normal. First Coupon Period Last Coupon Period Regular Coupon Periods
  • 11. About the Irregular First Coupon Period • Normally the dated date is the same as issue date • Short first coupon period • Long first coupon period Pseudo Issue Date Normal Issue Date First Coupon Date Dated Date Normal Issue Date First Coupon Date Dated Date
  • 12. About the Irregular Last Coupon Period • In most case normal maturity date is the same as maturity date • Short first coupon period LCF = (MD – LCD)/(NMD – LCD) • Long first coupon period LCF = 1+(MD – NMD)/(PMD – NMD) Last Coupon Date Normal Maturity Date Pseudo Maturity Date Maturity Date Last Coupon Date Normal Maturity Date Maturity Date
  • 13. Day Count Methods (DCM) • QuantLib has the above DCM under QuntLib-1.7qltimedaycounters folder • ACT/ACT • ACT/365 • ACT(NL)/365: Feb 29 is not counted • ACT/365(366 in a leap year) • ACT/360 • 30/360 • 30/365 and 30E/360 are added to QuantLib yet
  • 14. Some Examples for DCM • ACT/ACT D2-D1 Mar 1 to Mar 31 -> 30 days Mar 1 to Apr 1 -> 31 days • 30/360: each month counts as 30 days Number od days = (Y2-Y1)360+(M2-M1)30+(D2-D1) D2-D1 Mar 1 to Mar 31 -> 30 days Mar 1 to Mar 30 -> 29 days Mar 1 to Apr 1 -> 30 days • 30E/360: the 31st is treated as if it was the 30th D2-D1 Mar 1 to Mar 31 -> 29 days Mar 1 to Mar 30 -> 29 days Mar 1 to Apr 1 -> 30 days
  • 15. Accrued Interest and DCM • Accrued Interest is affected by the day count method Previous Cpn 1/15/2016 Next Cpn 7/15/2016 Settlement 5/31/2016 DCM Jan 15 to May 31 Jan 15 to Jul 15 AIF Act/Act 137 182 137/182 Act/365 137 365/2 137/182.5 Act(NL)/365 136 (Feb 29 not counted) 365/2 136/182.5 Act/360 137 360/2 137/180 30/360 136: (5-1)30+31-15 360/2 136/180 30/365 136 365/2 136/182.5 30E/360 136: (5-1)30+30-15 360/2 135/180
  • 16. Ex-Dividend Trading • Exist in some countries such as Australia and South Afarica • Happens when the settlement date is on or after ex-dividend date and before the next coupon date
  • 17. Schedule.hpp • This class is used to generate cash flow schedule. Fixed income is all about cash flows and discounting. • The date from the first to the last coupon period is very predictable except the end of month adjustment. The first and last coupon period could be long or short. That is why the first coupon date and the last coupon date are important. Issue date and maturity dates help on defining the first and last coupon periods. • End of month adjustment: • If the • QuantLib terminologies in this class may not match the bond products that well and here is a few I noticed … • effectiveDate: dated date • terminationDate: maturity date • firstDate: first coupon date • nextToLastDate: last coupon date
  • 18. CashFlows.hpp • Note CashFlows is different from CashFlow and it is a tool box for Cashflow handling • It provides methods for cash flow iteration, accrued interest, net present value (yield to price), price to yield conversion, dv01, duration, modified duration, convexity, z-spread, and par rates calculations. • Net present value (npv) could also be done via a curve discounting • Fixed income pricing is all about discount the cash flows using a curve. • Price and Yield conversion doesn’t depend on a yield curve and a formula is sufficient.
  • 19. Class InterestRate.hpp • This class encapsulates the interest rate compounding algebra. • It manages day count conventions, frequency, compounding conventions, and conversion between different conventions. • It handles compound (discount) factor calculations, and implied and equivalent rate calculations. • Supports simple, compounded, continuous, simple then compounded methods to calculate discount factor Simple: 1+(r/f)*fraction Compounded: (1+r/f)^(n+ fraction) Continuous: e^(rt) Simple then compounded: use simple for the first period and compounded for the rest of cash flows fraction = number of days / period length
  • 20. When Settlement Date is not in the Last Coupon Period 𝐂𝐥𝐞𝐚𝐧 𝐏𝐫𝐢𝐜𝐞 = 𝟏 (𝟏 + 𝒀 𝒇 ) 𝑫𝑭 × { 𝒄 𝒇 + 𝒄 𝒀 𝟏 − 𝟏 𝟏 + 𝒀 𝒇 𝐧 + (𝐏𝐚𝐫 + 𝒄 𝒇 × 𝑳𝑪𝑭) × 𝟏 𝟏 + 𝒀 𝒇 𝐧+𝐋𝐃𝐅} − 𝒄 𝒇 × 𝑨𝑰𝑭 Y: yield to maturity f: frequency of coupon. 2 for semiannual c: coupon Par: redemption LCF: last coupon factor is used to calculate the cpn on maturity date LDF: used to discount cash flow at the maturity to last coupon date n: number of coupon remaining – 2 AIF: accrued interest factor
  • 21. Price Yield Formula Explained 𝐂𝐥𝐞𝐚𝐧 𝐏𝐫𝐢𝐜𝐞 = 𝟏 (𝟏 + 𝒀 𝒇 ) 𝑫𝑭 × { 𝒄 𝒇 + 𝒄 𝒀 𝟏 − 𝟏 𝟏 + 𝒀 𝒇 𝐧 + (𝐏𝐚𝐫 + 𝒄 𝒇 × 𝑳𝑪𝑭) × 𝟏 𝟏 + 𝒀 𝒇 𝐧+𝐋𝐃𝐅} − 𝒄 𝒇 × 𝑨𝑰𝑭 𝐂𝐥𝐞𝐚𝐧 𝐏𝐫𝐢𝐜𝐞 = 𝑫𝒊𝒔𝒄𝒐𝒖𝒏𝒕 𝒇𝒓𝒐𝒎 𝑪 𝒕𝒐 𝑩 × 𝑪𝒑𝒏 𝒂𝒕 𝑪 + 𝑪𝒑𝒏 𝒇𝒓𝒐𝒎 𝑫 𝒕𝒐 𝑬 + 𝑷𝒂𝒓 𝒂𝒏𝒅 𝑳𝒂𝒔𝒕 𝑪𝒑𝒏 − 𝑨𝑰
  • 22. When Settlement Date is in the Last Coupon Period It is quite common to use simple interest rate when only one period is left
  • 23. Bond Inheritance Tree The current bond tree Bond interface defines methods such as accrued interest not meaningful for zero coupon bond. In the future, it makes more sense to have a tree like this. CPIBond is essentially a floating rate via adjusting the principal. We might want to put it together with floaters. Bond ZeroCouponBond FloatingRateBond FixedRateBond CPIBond CouponBond ZeroCouponBond FloatingRateBond FixedRateBondCPIBond Bond
  • 24. Class Bond.hpp • Constructor • accruedAmount(): calculate the accrued interest • cleanPrice() and yield() methods: price and yield conversion • Provide access to cashflow
  • 25. It is quite natural to use schedule to specify the cash flow dates and pass the settlement date, face value, coupon rate, DCM, payment convention, notional, and issue date to build a bond. Class FixedRateBond.cpp – Construct a Bond
  • 26. Some thoughts to share • Reading the code without any background knowledge is doable but time consuming. That is why I prepared this document. • Product knowledge is indispensable and there a lot of books and web sites for that. Learning product knowledge by reading the QuantLib code is not productive. I found myself in most case have a big picture and end up finding the practical details in the code. • It would be helpful to use a spread sheet to work out the details and then implement it in QuantLib. It is indirect but effective.
  • 27. Here is a Spread Sheet Example for Chinese Government Bond
  • 28. To be continued … • I am going to write about index lined bond like TIPS • If you see any error in this document, please email me at jhong111@yahoo.com and I will correct it accordingly