QuantLib example : Pricing Callable Bonds
The QuantLib example "CallableBonds.cpp" the Mathematica way.
Pricing a callable fixed rate bond using Hull White model w/ reversion parameter = 0.03
BAC4.65 09/15/12 ISIN: US06060WBJ36
roughly five year tenor, quarterly coupon and call dates
reference date is : October 16th, 2007
Getting started
Loading QuantLib into Mathematica.
In[1]:=
Setting the evaluation date. All calculation are done with respect to this date.
In[2]:=
Out[2]=
Setting up the yield curve
The standard setting for a flat forward curve is
In[3]:=
Out[3]=
To change the day counting method to the requested one use the possiblity to change this via options. The possible values for DayCounter can be retrieved with the function GetEnumerationType.
In[4]:=
Out[4]=
The possible values for the enumeration type “Frequency” can also retrieved
In[5]:=
Out[5]=
In[6]:=
Building up the payment schedule for the callable bond
For building up payment schedule the function Schedule is provided by QuantLib
In[7]:=
As always the ObjectId is optional when an quantLib object is created. When an object should be updated providing the right object id (object name) is required.
To build up the schedule at minimum a termination date and a tenor is required.
In[8]:=
Out[8]=
In[9]:=
Out[11]=
Defining the callability
In[12]:=
Out[16]=
In[17]:=
Out[17]=
Setting up a Hull/White model
In[18]:=
In[19]:=
Out[19]=
In[21]:=
Out[21]=
Defining the pricing engine
In[22]:=
Out[23]=
Pricing
In[24]:=
Out[24]=
In[25]:=
Out[26]//TableForm=
10.*10^^-6 % | 96.5315 | 5.431 % |
1. % | 95.6944 | 5.62841 % |
3. % | 92.3609 | 6.43337 % |
6. % | 87.13 | 7.76167 % |
12. % | 77.3885 | 10.4819 % |
There is a slight difference to the values calculated in the QuantLib example. So probably some calendar settings or payment conventions were not correctly captured. To further explore the difference a look at the flows might be helpful:
In[27]:=
Out[27]//TableForm=
Payment Date | Amount | Nominal | Accrual Start Date | Accrual End Date | Accrual Days | Index | Fixing Days | Fixing Dates | Day Counter | Accrual Period | Effective Rate | Floor | Gearing | Index Fixing | Conv. Adj. | Spread | Cap | Call Digital Payoff | Put Digital Payoff |
Sat 15 Dec 2007 | 0.764384 | 100. | Tue 16 Oct 2007 | Sat 15 Dec 2007 | 60 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.164384 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Sat 15 Mar 2008 | 1.15932 | 100. | Sat 15 Dec 2007 | Sat 15 Mar 2008 | 91 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.249315 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Sun 15 Jun 2008 | 1.17205 | 100. | Sat 15 Mar 2008 | Sun 15 Jun 2008 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Mon 15 Sep 2008 | 1.17205 | 100. | Sun 15 Jun 2008 | Mon 15 Sep 2008 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Mon 15 Dec 2008 | 1.15932 | 100. | Mon 15 Sep 2008 | Mon 15 Dec 2008 | 91 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.249315 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Sun 15 Mar 2009 | 1.14658 | 100. | Mon 15 Dec 2008 | Sun 15 Mar 2009 | 90 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.246575 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Mon 15 Jun 2009 | 1.17205 | 100. | Sun 15 Mar 2009 | Mon 15 Jun 2009 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Tue 15 Sep 2009 | 1.17205 | 100. | Mon 15 Jun 2009 | Tue 15 Sep 2009 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Tue 15 Dec 2009 | 1.15932 | 100. | Tue 15 Sep 2009 | Tue 15 Dec 2009 | 91 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.249315 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Mon 15 Mar 2010 | 1.14658 | 100. | Tue 15 Dec 2009 | Mon 15 Mar 2010 | 90 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.246575 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Tue 15 Jun 2010 | 1.17205 | 100. | Mon 15 Mar 2010 | Tue 15 Jun 2010 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Wed 15 Sep 2010 | 1.17205 | 100. | Tue 15 Jun 2010 | Wed 15 Sep 2010 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Wed 15 Dec 2010 | 1.15932 | 100. | Wed 15 Sep 2010 | Wed 15 Dec 2010 | 91 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.249315 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Tue 15 Mar 2011 | 1.14658 | 100. | Wed 15 Dec 2010 | Tue 15 Mar 2011 | 90 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.246575 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Wed 15 Jun 2011 | 1.17205 | 100. | Tue 15 Mar 2011 | Wed 15 Jun 2011 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Thu 15 Sep 2011 | 1.17205 | 100. | Wed 15 Jun 2011 | Thu 15 Sep 2011 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Thu 15 Dec 2011 | 1.15932 | 100. | Thu 15 Sep 2011 | Thu 15 Dec 2011 | 91 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.249315 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Thu 15 Mar 2012 | 1.15932 | 100. | Thu 15 Dec 2011 | Thu 15 Mar 2012 | 91 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.249315 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Fri 15 Jun 2012 | 1.17205 | 100. | Thu 15 Mar 2012 | Fri 15 Jun 2012 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Sat 15 Sep 2012 | 1.17205 | 100. | Fri 15 Jun 2012 | Sat 15 Sep 2012 | 92 | #N/A | #N/A | #N/A | Actual/365 (Fixed) | 0.252055 | 0.0465 | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |
Sat 15 Sep 2012 | 100. | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A | #N/A |