bond examples fabozzi part2

Upload: mauricio-bedoya

Post on 03-Jun-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Bond Examples Fabozzi Part2

    1/20

    Fixed Income Mathematics in QuantlibPart II

    Mauricio Bedoya

    [email protected]

    February 2014

    In this blog, we will replicate Exhibit 24.2 and create two additional classes: FixedPassThroughand AccrualCMO. The FixedPassThrough class will create the cash flows that allow to makepayment in the AccrualCMO. In other words, FixedPassThrough works as the collateral ofAccrualCMO structure. Before we continue, I have to give some bad news. Exhibits 24.3 and24.5 are wrong in the book. Contrast the last paragraph of page 447 with bond class A principalpayment.

    Something that I forget to mentioned in the previous blogs, is that I didnt assert proper inputvaluation. For example, if you provide a negative amount to class FixedRateMortgagePSA, the

    program should prompt an error and this is not the case. I assume that you provide reasonableinputs. At the same time, previous and current files arent part of QuantLib. Once I check thateverything works correctly, I will sent them to QuantLib to proper assessment.

    1. Fixed Passthrough (page 474)

    FixedPassThrough will be inherited from FixedRateMortgagePSA. The .hpp and .cpp files ofFixedPassThrowugh are:

    1

  • 8/12/2019 Bond Examples Fabozzi Part2

    2/20

    1 / mode: c++; tabw id th : 4 ; i n de n ttabsmode : n i l ; cb a s i c o f f s e t : 4 /

    3 /C o p y r i gh t (C) 2 0 14 M a u r i c i o B ed oy a

    5

    T hi s f i l e i s n ot y et p a rt o f QuantLib , a f r e e s o f tw a r e / o p e ns o ur ce l i b r a r y7 f o r f i n a n c i a l q u a nt i t a t iv e a n a ly s t s and d e v e lo p er s h ttp : / / q u a n tl i b . o r g /

    /9

    # i f n d e f q u a n t l i b f i x e d p a s s t h r o u g h h p p11 #d e f i n e q u a n t l i b f i x e d p a s s t h r o u g h h p p

    13 #i n c l u d e fix edratemortgagePS A . hpp# i n c l u d e

    15 #i n c l u d e # i n c l u d e

    17

    #i n c l u d e

    19 namespace QuantLib {

    21 c l a s s FixedPassThrough :p u b l i c FixedRateMortgagePSA {p u b l i c:

    23 FixedPassThrough(c o n s t Date& issue Date , c o n s t C a l e n da r& c a l e n d a r , c o n s tReal& amount , c o n s t I n t e r e s tR a te & p a s sth r ow g h Ra te , c o n s t InterestRate& NetWAC, c o n s t Re al& WAM, Rate& f e e , c o n s t In te ge r& yearPayments , c o n s t Real& PSA,c o n s t I n t e g e r & s e a s o n e d = 0 ) ;

    v i r t u a l FixedPassThrough () ;25 //@{

    / Others /27 L eg N e t I n t e r e s t ( ) ;

    29 //@}p r i v a t e:

    31 R ea l t e rm ;I n t e g e r y ea rP ay me nt s , s e a s o n ed ;

    33 I n t e r e s tR a te p a s s th r o u g h R a te , NetWAC ;/ H e l p e r s /

    35 Time t = (1 . 0 / y e a rP a y me n ts ) ;Real compoundFactor = passt hroug hRate . compoundFactor( t ) ;

    37 In te ge r numberOfPayments = ( term yearPayments s e a s o n ed ) ;

    39 } ;}

    41

    # e n d i f / d e f i n e d ( h h F i l e ) /

    2

  • 8/12/2019 Bond Examples Fabozzi Part2

    3/20

    / mode: c++; tabw id th : 4 ; i n de n ttabsmode : n i l ; cb a s i c o f f s e t : 4 /2

    /4 C o p y r i gh t (C) 2 0 14 M a u r i c i o B e do ya

    6 T hi s f i l e i s n ot y et p a rt o f QuantLib , a f r e e s o f tw a r e / o p e ns o ur ce l i b r a r yf o r f i n a n c i a l q u a nt i t a t iv e a n a ly s t s and d e ve l op e rs h ttp : / / q u a n tl i b . o r g /

    8 /

    10 #i n c l u d e f i x e d p a s s t h r o u g h . hpp

    12 namespace QuantLib {

    14 FixedPassThrough : : FixedPassThrough (c o n s t Date& issue Date , c o n s t Calendar&c a l e n d a r , c o n s t Real& amount , c o n s t I n t e r e s tR a te & p a s s th r o u gh R a te , c o n s tInterestRate& NetWAC, c o n s t Re al& WAM, Rate& f ee , c o n s t Integer& yearPayments

    , c o n s t Real& PSA, c o n s t In te ge r& seaso ned ) : FixedRateMortgagePSA( issue Date ,ca le nd ar , amount , NetWAC, fe e , WAM, yearPayments , PSA, se as on ed ) ,pas sth rou ghR ate ( pass thro ughR ate ) , NetWAC (NetWAC) , yearPayment s (yearPayments) , term (WAM) , se as on ed ( sea son ed ) {}

    16 FixedPassThrough : : FixedPassThrough () {}

    18 //@{/ Others /

    20

    Leg FixedPassThrough : : NetI nt er es t ()22 {

    Leg i n t e r e s t ;24 f o r (i n t i = 0 ; i < numberOfPayments ; i++)

    {26 b o o s t : : s h a r e d p tr I ( new SimpleCashFlow(t h i s >

    FixedRateMortgagePSA : : Beg ini ngB ala nce () [ i ]>amount() (compoundFactor 1), ( t h i s) . FixedRateMortgagePSA : : Be gin ing Bal anc e () [ i ]> dat e () ) ) ;

    i n te r e s t . p u s h b a c k ( I ) ;28 }

    30 r e t u r n i n t e r e s t ;}

    32 }

    The implementation in main, to replicar Exhibit 24.2:

    3

  • 8/12/2019 Bond Examples Fabozzi Part2

    4/20

    /2 F i x ed I n co me M a th e ma tic s F ou r E d i ti o n

    p ag ( 4 7 4 )4 A na ly zi ng s e c u r i t i z e d p ro d uc t s .

    /6 #i n c l u d e

    # i n c l u d e 8 #i n c l u d e

    # i n c l u d e 10 #i n c l u d e

    # i n c l u d e f i x e d p a s s t h r o u g h . hpp 12

    u s i n g n am e sp a ce QuantLib ;14 u s i n g n am e sp a ce std ;

    u s i n g n am e sp a ce b o o s t : : a s s i g n ;16

    b o o s t : : fo rm at FORMATER1 ( %20d % 1 2. 10 d % 1 2. 3 d % 1 2. 8 d % 1 2. 8d % 1 2. 8 d %12 s % 12 s % 12s ) ;18

    i n t main()20 {

    t r y {22 R ate B on dR ate = 0 . 0 7 5 ;

    Rate WAC = 0. 08 12 5;24 Rate f e e = 0 . 0 ;

    DayCounter DC= Act ua lAc tu al ( Act ua lAc tu al : : ISDA) ;26 C a le n da r c a l e n d a r = N u l l Ca l e n da r ( ) ;

    Compounding compounded = Sim ple ;28 F r eq u e nc y f r e q u e n c y = A nn ua l ;

    30 In te re st Ra te bondRate( BondRate , DC, compounded , freq uen cy ) ;In te re st Ra te netWAC(WAC, DC, compounded , fr eq ue nc y ) ;

    32 D ate i s s u e (1 , J a n , 2 0 0 0 ) ;i s s u e = c a l e n d a r . a d j u s t ( i s s u e ) ;

    34 I n t e g e r Y ea rP ay me nts = 1 2 ;I n t e g e r S ea so ne d = 3 ;

    36 R e a l R e ma i ni n g Ye a rs = 3 0 ;FixedPassThrough FPT( is su e , calen dar , 400000000 , bondRate , netWAC,

    RemainingYears , fee , YearPayments , 1. 65 , Seasoned ) ;38

    c o u t amount() ;

    NI = FPT. Ne tI nt er es t () [ i ]>amount() ;46 SP = FPT. FixedRateMortgagePSA : : Proy ecte dPri ncip alPa ymen t () [ i ]>

    amount() ;

    4

  • 8/12/2019 Bond Examples Fabozzi Part2

    5/20

    PREP = FPT. FixedRateMortgagePSA : : Pr inc ipa lRe pay men t () [ i ]>amount() ;2 TP = SP + PREP;

    TCF = NI + TP;4

    cout date ()

    6 % BB %SMM %MP % NI % SP %PREP % TP % TCF

  • 8/12/2019 Bond Examples Fabozzi Part2

    6/20

    std : : vector type () c o n s t;2 std : : vecto r Balance () c o n s t;

    std : : vector P r i n c i p a l ( ) c o n s t;4 std : : vecto r I n t e r e s t ( ) c o n s t;

    6 / Others /Real WAM( ) c o n s t;

    8 std : : vecto r VectorWAM ( ) c o n s t;Re al GrossWAC( ) c o n s t;

    10 R e a l T o ta l O u ts ta n d i n g () c o n s t;R e al A c c r u e I n t e r e s t ( ) ;

    12 v o i d ParAmountUpdate() ;v o i d GenerateCashFlow () ;

    14

    //@}16 p r i v a t e:

    FixedPassThrough PassThrough ;18 mutable std : : vector ParAmount ;

    std : : vector ParAmountCopy = ParAmount ;20 std : : vecto r I n t e r e s t R a t e H e l p e r ( ) ;

    std : : vector CouponRate ;22 std : : vecto r t y p e ;

    std : : vector Months ;24 std : : vecto r Bal an ce , P ri n ci p al , I n t e r e s t ;

    26 } ;

    28 / I n l i n e f u n ct i o n s /i n l i n e R e a l T o t al O u t st a n d in g (c o n s t std : : vector >& M o r tg a g e s )30 {

    R ea l T ot a l = 0 ;32 f o r (i n t i = 0 ; i < Mortgages . s i ze () ; i++) {

    Tota l += Mortgages [ i]>amount() ;34 }

    36 r e t u r n Total ;}

    38

    i n l i n e Real WAM(c o n s t std : : vector &M or tga g es , b o o s t : : s h a r e d p tr & T r a n c h e s )

    40 {Real wam;

    42 std : : vecto r b a l a n c e = T r a n c h e s>Balance () ;f o r (i n t i = 0 ; i < Mortgages . s i ze () ; i++)

    44 {

    46 wam += ( Mortg ages [ i ]>a mo un t() / T o ta l O u ts ta n d i n g ( M o rtg a ge s ) ) (1 +bala nce [ i ] . s i ze ( ) ) ;

    }48

    r e t u r n wam;50 }

    6

  • 8/12/2019 Bond Examples Fabozzi Part2

    7/20

    i n l i n e Re al GrossWAC(c o n s t std : : vect or >& M o r tg a g e s )

    2 {R e a l wac ;

    4 f o r(i n t i = 0; i < Mortgages . s i ze () ; i++){

    6 wac += ( Mortgages [ i ]>a mo un t() / T o ta l O u ts ta n d i n g ( M o rtg a ge s ) ) Mortgages [ i ]> r a t e () ;

    }8

    r e t u r n wac;10 }

    12 i n l i n e R eal NetWAC(c o n s t std : : vector & M o r tg a g e s ){

    14

    / f e e must i n c lu d e : s e r v i c i n g f ee , t r u s t e e f e e and payment f o r c r e d i ts u p p o r t /Real netwac ;

    16 f o r (i n t i = 0 ; i < Mortgages . s i ze () ; i++){

    18 netwac += ( Mortgages [ i ]>a mo un t() / T o ta l O u ts ta n d i n g ( M o rtg a ge s ) ) (Mortgages [ i ]> r a t e ( ) Mortgages [ i]> fe e () ) ;

    }20

    r e t u r n netwac ;22 }

    24 }

    # e n d i f / d e fi n e d ( h h A cc ru al CM O ) /

    Im only going to concentrate in extension and contraction risk. As PSA increase, the averagelife of each bond in the structure reduce, but no in equal proportion. Just play with the PSAor create an additional Accrue type bond and evaluate the behaviour.

    1 /F i x ed I n co me M a th e ma tic s F ou r E d i ti o n

    3 p ag ( 4 7 4 )

    A na ly zi ng s e c u r i t i z e d p ro d uc t s .5 /

    # i n c l u d e 7 #i n c l u d e

    # i n c l u d e 9 #i n c l u d e

    # i n c l u d e 11 #i n c l u d e f i x e d p a s s t h r o u g h . hpp

    # i n c l u d e AccrualCMO . hpp13

    u s i n g n am e sp a ce QuantLib ;15 u s i n g n am e sp a ce std ;

    7

  • 8/12/2019 Bond Examples Fabozzi Part2

    8/20

    1 u s i n g n am e sp a ce b o o s t : : a s s i g n ;

    3 b o o s t : : fo rm at FORMATER1 ( %20d % 1 2. 10 d % 1 2. 3 d % 1 2. 8 d % 1 2. 8d % 1 2. 8 d %12 s % 12 s % 12s ) ;

    b o o s t5 : : fo rmat FORMATER2 ( %10.4d % 1 0. 4d % 1 0. 4 d % 1 0. 4 d % 10.4d ) ;

    i n t main()7 {

    t r y {9 R ate B on dR ate = 0 . 0 7 5 ;

    Rate WAC = 0. 08 12 5;11 Rate f e e = 0 . 0 ;

    DayCounter DC= Act ua lAc tu al ( Act ua lAc tu al : : ISDA) ;13 C a le n da r c a l e n d a r = N u l l Ca l e n da r ( ) ;

    Compounding compounded = Sim ple ;15 F r eq u e nc y f r e q u e n c y = A nn ua l ;

    17 In te re st Ra te bondRate( BondRate , DC, compounded , freq uen cy ) ;In te re st Ra te netWAC(WAC, DC, compounded , fr eq ue nc y ) ;

    19 D ate i s s u e (1 , J a n , 2 0 0 0 ) ;i s s u e = c a l e n d a r . a d j u s t ( i s s u e ) ;

    21 I n t e g e r Y ea rP ay me nts = 1 2 ;I n t e g e r S ea so ne d = 3 ;

    23 v e c to r PSA;PSA += 0. 5 ,1 ,1 .6 5 ,2 ,3 ,4 ,5 ;

    25 R e a l R e ma i ni n g Ye a rs = 3 0 ;

    27 c o u t

  • 8/12/2019 Bond Examples Fabozzi Part2

    9/20

    1 c a tc h ( s td : : e x c e p ti o n & e ) {c e r r

  • 8/12/2019 Bond Examples Fabozzi Part2

    10/20

    1 #i n c l u d e f i x e d p a s s t h r o u g h . hpp

    3 namespace QuantLib {

    5 c l a s s PacBonds{p u b l i c:

    7 PacBonds(c o n s t std : : vector & ParAmount , c o n s t std : : vect or & CouponRate , c o n s t std : : vector & type , c o n s t Real&capPSA , c o n s t Real& floorPSA , c o n s t FixedPassThrough& PassThrough) ;

    v i r t u a l PacBonds() ;9

    //@{11 / I n s p e c t o r s /

    std : : vector ParAmount() c o n s t;13 std : : vecto r CouponRate() c o n s t;

    std : : vector Type() c o n s t;15

    std : : vecto r

    Balance () c o n s t;std : : vector P r i n c i p a l ( ) c o n s t;17 std : : vecto r I n t e r e s t ( ) c o n s t;

    19 / Others /std : : vector PAC AverageLife () c o n s t;

    21 R e al S u p p o r t A v e r a g e L i f e ( ) c o n s t;Re al GrossWAC( ) c o n s t;

    23 R e a l T o ta l O u ts ta n d i n g () c o n s t;

    25 //@}

    27 p r i v a t e:

    //PAC In for ma ti on29 mutable std : : vector ParAmount ;

    std : : vector ParAmountCopy = ParAmount ;31 std : : vecto r CouponRate ;

    std : : vector t y p e ;33 R e al capPSA , f l o o r PS A ;

    Real PSA ;35 FixedPassThrough PassThrough ;

    std : : vector Bal an ce , P ri n ci p al , I n t e r e s t ;37 std : : vecto r S up po rt Ba la nc e , S u p po r t Pr i n ci p a l , S u p p o r t I n t er e s t ;

    39 //@{

    / / H e l p er s41 v o i d SupportBalanceUpdate(c o n s t Real& amount) ;

    R e a l S u p p o r tBa l a n c e () ;43 std : : vecto r I n t e r e s t R a t e H e l p e r ( ) ;

    v o i d GenerateCashFlow () ;45 //@}

    } ;47 }

    49 #e n d i f / d e f i n e d ( q u an tli b P A CB o nd s h p p ) /

    10

  • 8/12/2019 Bond Examples Fabozzi Part2

    11/20

    1 / mode: c++; tabw id th : 4 ; i n de n ttabsmode : n i l ; cb a s i c o f f s e t : 4 /

    3 /C o p y r i gh t (C) 2 0 14 M a u r i c i o B ed oy a

    5

    T hi s f i l e i s n ot y et p a rt o f QuantLib , a f r e e s o f tw a r e / o p e ns o ur ce l i b r a r y7 f o r f i n a n c i a l q u a nt i t a t iv e a n a ly s t s and d e v e lo p er s h ttp : / / q u a n tl i b . o r g /

    9 QuantLib i s f r e e s o f t wa r e : you c an r e d i s t r i b u t e i t and / or m od if y i tu nd er t he t er ms o f t he QuantLib l i c e n s e . You s h o ul d hav e r e c e i v e d a

    11 copy o f t he l i c e n s e a lo ng wi th t h i s program ; i f not , p l e as e e ma il. The l i c e n s e i s a l s o a v ai l ab l e o nl i n e at

    13 .

    15 T hi s p r og ram i s d i s t r i b u t e d i n t h e h op e t h a t i t w i l l b e u s e f u l , b ut WITHOUTANY WARRANTY; wi th ou t ev en th e i m p l i ed wa rr an ty o f MERCHANTABILITY or FITNESS

    17

    FOR A PARTICULAR PURPOSE. See the l i c e n s e f or more d e t a i l s ./19

    # i n c l u d e PACBonds . hpp21

    namespace QuantLib {23 PacBonds : : PacBonds(c o n s t std : : vector & ParAmount , c o n s t std : : vector & CouponRate , c o n s t std : : vector & type , c o n s t Real&capPSA , c o n s t Real& floorPSA , c o n s t Fi xedPass Through& PassThrough ) : ParAmount(ParAmount) , CouponRate (CouponRate) , typ e ( type ) , capPSA ( capPSA) , f loorPS A( f l o o rP S A ) , P a ss T hr o ug h ( P as sT hr ou gh ){

    25 QL REQUIRE( ( Pas sTh rou gh . FixedRateMo rtgagePSA : : amount ( ) ==

    TotalOut standing () ) , Er ror : ParAmount and PassThrough amount d i f f e r . ) ;QL REQUIRE( ( capPSA >= 0 | | f loorPSA >= 0 | | capPSA > f loorPSA) , Er ror :

    PSA v a l u e s mu st b e p o s i t i v e . ) ;27

    GenerateCashFlow () ;29 }

    31 PacBonds : : PacBonds ( ) {}

    33 //@{/ I n s p e c t o r s /

    35 std : : vecto r PacBonds : : ParAmount() c o n s t { r e t u r n ParAmountCopy ; }

    std : : vector PacBonds : : CouponRate ( ) c o n s t { r e t u r n CouponRate ; }37 std : : vecto r PacBonds : : Type( ) c o n s t { r e t u r n t y p e ; }

    std : : vector PacBonds : : Bal anc e ( ) c o n s t { r e t u r n B a l a nc e ; }39 std : : vecto r PacBonds : : Pr in ci pa l () c o n s t { r e t u r n

    P r in c i pa l ; }std : : vector PacBonds : : I nt er es t () c o n s t { r e t u r n I n t e r e s t

    ; }

    11

  • 8/12/2019 Bond Examples Fabozzi Part2

    12/20

    / Others /2 std : : vecto r PacBonds : : PAC AverageL ife ( ) c o n s t

    {4 std : : vecto r l i f e ;

    6 f o r (i n t i = 0 ; i < P r i n c i p a l . s i z e ( ) ; i ++){

    8 R ea l M = 0 ;f o r (i n t j = 0 ; j < P r i n c i p a l [ i ] . s i z e ( ) ; j ++)

    10 {M += (( j + 1 ) P r i n c i p a l [ i ] [ j ] ) / 1 2 ;

    12 }

    14 l i f e . pus h bac k (M / ParAmountCopy [ i ] ) ;}

    16

    r e t u r n l i f e ;18 }

    20 Real PacBonds : : Supp ort A vera geLi fe () c o n s t{

    22 i n t support = ParAmountCopy . s i ze () 1 ;R e al M = 0 ;

    24 f o r (i n t j = 0; j < S u p p o r t P r i n c i p a l . s i z e ( ) ; j ++){

    26 M += (( j + 1 ) S u p p o r t P ri n c i p al [ j ] ) / 1 2 ;}

    28

    r e t u r n (M / ParAmountCopy [ sup port ]) ;30 }

    32 Rea l PacBonds : : GrossWAC( ) c o n s t{

    34 R e al wac = 0 ;R e a l T o ta l = T o ta l O u ts ta n d i n g () ;

    36 f o r (i n t i = 0 ; i < ParAmount . s iz e () ; i++){

    38 wac += (ParAmount [ i ] / Total ) CouponRate [ i ] ;}

    40

    r e t u r n wac;

    42 }

    44 Real PacBonds : : Tota lOut stan ding () c o n s t{

    46 R ea l T ot a l = 0 ;f o r (i n t i = 0 ; i < ParAmount . s iz e () ; i++)

    48 {Tot al += ParAmount [ i ] ;

    50 }

    52 r e t u r n Total ;}

    12

  • 8/12/2019 Bond Examples Fabozzi Part2

    13/20

    1 Real PacBonds : : Supp ortBal ance (){

    3 R eal t o t a l = 0 ;f o r (i n t i = 0 ; i < ParAmount . s iz e () ; i++)

    5 {t o t a l += I n t e r e s t R a t e H e l p e r ( ) [ i ] ParAmount [ i ] ;

    7 }

    9 r e t u r n t o t a l ;}

    11

    v o i d PacBonds : : SupportBalanceU pdate (c o n s t Real& amount)13 {

    f o r (i n t i = 0 ; i < ParAmount . s iz e () ; i++)15 {

    ParAmount [ i ] = I n t e r e s t R a t e H e l p e r ( ) [ i ] amount ;17

    }}19 //@}

    21 //@{ H el p er s d e f i n ed p r i v a t e std : : vector PacBonds : : Int ere st Rat eHe lp er ()

    23 {std : : vector h e l p e r ;

    25 f o r (i n t i = 0 ; i < ParAmount . s iz e () ; i++){

    27 i f ( typ e [ i ]== S u p p o r t){

    29 he lp er . push back (1 ) ;

    }31 e l s e

    {33 he lp er . push back (0 ) ;

    }35 }

    37 r e t u r n h e l p e r ;}

    39

    v o i d PacBonds : : GenerateCash Flow ( )41 {

    i n t N = PassThrough . FixedRateMortgagePSA : : Proy ecte dPri nci palP aym ent () .s i z e ( ) ;

    43 // S et v e ct o r s s i z estd : : vector b e g i n i n g b a l a n c e (N) , p r i n c i p a l (N) , i n t e r e s t (N) ;

    45 S u p p o r t P r i n c i p a l . r e s i z e (N) , S u pp o rt B al a nc e . r e s i z e (N) , S u p p o r t I n t e r e s t. r e s i z e (N) ;

    47 R ea l e x c e s s ; // Excess amount over PAC /S u pp o rt b a l a n c e

    i n t j = 0 ; / / S t a r t C ou nt er49 i n t s u p p o r t = P ar Am ou nt . s i z e ()1; // I d e n t i f y S up po rt v e c t or

    ONLY.

    13

  • 8/12/2019 Bond Examples Fabozzi Part2

    14/20

    1 f o r (i n t i = 0 ; i < ParAmount . si z e () ; ++i ){

    3 s td : : f i l l ( b e g i n i n g b a l a n c e . b e g i n () , b e g i n i n g b a l a n c e . e nd () , 0 ) ;s t d : : f i l l ( p r i n c i p a l . b e g i n ( ) , p r i n c i p a l . e nd ( ) , 0 ) ;

    5 s t d : : f i l l ( i n t e r e s t . b e g i n ( ) , i n t e r e s t . e nd ( ) , 0 ) ;

    7 w h i l e (ParAmount [ i ] > 0 . 0 0 0 1 ){

    9 //PSA Valu ePassThrough . setPSA( PassThrough . getPSA( ) ) ;

    11 Real PSA PrincipalPayment = PassThrough . FixedRateMortgagePSA : :Proyected Principal Payment () [ j ]>amount() +

    PassThrough . FixedRateMortgagePSA : : Princi palRe paymen t () [ j ]>amount() ;

    13 / / F l o o r V al uePassThrough . setPSA( floorPS A ) ;

    15

    R e a l F l o o r P r i n c i p a l = P a ss T hr o ug h . F ix ed Ra te Mo rtga ge PS A : :Proyected Principal Payment () [ j ]>amount() +PassThrough . FixedRateMortgagePSA : : Princi palRe paymen t () [ j ]>

    amount() ;17 //Cap Value

    PassThrough . setPSA( capPSA ) ;19 Real Cap Prin cip al = PassThrough . FixedRateMortgagePSA : :

    Proyected Principal Payment () [ j ]>amount( ) +PassThrough . FixedRateMortgagePSA : :PrincipalRepayment () [ j ]>amount() ;

    21 R ea l P r i nc i p al P a ym e n t = 0 ;R ea l A bs or b = 0 ;

    23

    /25 S up p or t S e c t i o n

    /27 //

    i f ( S u p p o r tBa l a n c e () > 0 )29 {

    i f( PassThrough . getPSA( ) < f l o o r P S A )31 {

    PrincipalPayment = PSA PrincipalPayment ;33 }

    e l s e35 {

    P r i nc i p al P ay m e nt = ( C a p P r i n c i p a l >= F l o o r P r i n c i p a l ) ?F l o o r P r i n c i p a l : C a p P r i n ci p a l ;

    37 }

    39 i f( i < suppor t ){

    41 / / To a b s o r bAbsorb = PSA PrincipalPayment P r i n c i p a l P a y m e n t +

    e x c e s s ;43 }

    14

  • 8/12/2019 Bond Examples Fabozzi Part2

    15/20

    1 e l s e{

    3 / / To a b s o r bA bs or b = P S A P r i n ci p al P ay m e nt + e x c e s s ;

    5 }e x c e s s = 0 ;

    7

    i f( S u p p o r tBa l a n c e () > Absorb)9 {

    / / U pd ate s u p p o r t11 Suppor tBalanc e [ j ] = ParAmount [ support ] ;

    S u p p o r t P r i n c i p a l [ j ] = A bs or b ;13 S u p p o r tI n te r e s t [ j ] = P ar Am ou nt [ s u p p o r t ] (CouponRate

    [ support ] . compoundFactor( 1. 0/ 12 ) 1 ) ;SupportBalanceUpdate( Absorb) ;

    15 }

    e l s e17 {

    / / A b so rb s u p p o rt b a l a n c e19 Absorb = SupportBalance () ;

    Suppor tBalanc e [ j ] = ParAmount [ support ] ;21 S u p p o r t P r i n c i p a l [ j ] = A bs or b ;

    S u p p o r tI n te r e s t [ j ] = P ar Am ou nt [ s u p p o r t ] (CouponRate[ support ] . compoundFactor( 1. 0/ 12 ) 1 ) ;

    23 e x c e s s = P S A P r in c ip a l Pa y m en t PrincipalPayment SupportBalance () ;

    SupportBalanceUpdate( Absorb) ;25 }

    }27

    /29 PAC s e c t i o n

    /31 e l s e

    {33 PrincipalPayment = PSA PrincipalPayment ;

    }35

    i f( i < suppor t )37 {

    / / P ac i n f o r m a t i on

    39 beg ini ngb ala nce [ j ] = ParAmount [ i ] ;i n te r e s t [ j ] = Pa rA mo un t [ i ] ( CouponRate [ i ] . compoundFactor

    ( 1 . 0 / 1 2 ) 1 ) ;41

    i f(ParAmount [ i ] > P r i n c i p a l P a y m e n t)43 {

    // Update PAC45 p r i n c i p a l [ j ] = P r i nc i p al P a ym e n t + e x c e s s ;

    ParAmount [ i ] = ( P r i nc i p al P a ym e n t + e x c e s s ) ;47 e x ce s s = 0 ;

    }

    15

  • 8/12/2019 Bond Examples Fabozzi Part2

    16/20

    e l s e2 {

    // Absorb PAC bala nce4 p r i n c i p a l [ j ] = P ar Am ou nt [ i ] ;

    e x c e s s = P r i n c i p a l P a y m e n t ParAmount [ i ] ;6 ParAmount [ i ] = ParAmount [ i ] ;

    }8 }

    j ++;10 }

    /12 Pac b al an ce , p r i n c i p a l and i n t e r e s t

    /14 i f( i < support )

    {16 B a l a n c e . p u sh b a ck ( b e g i n i n g b a l a n c e ) ;

    P r i n c i p a l . p u sh b ac k ( p r i n c i p a l ) ;18 I n t e r e s t . p us h b ac k ( i n t e r e s t ) ;

    }20

    }22 }

    //@}24 }

    Code to replicate table in page 489.

    /2 F i x ed I n co me M a th e ma tic s F ou r E d i ti o n

    p ag ( 4 8 9 )4 A na ly zi ng s e c u r i t i z e d p ro d uc t s .

    /6 #i n c l u d e

    # i n c l u d e 8 #i n c l u d e

    # i n c l u d e 10 #i n c l u d e

    # i n c l u d e 12 #i n c l u d e f i x e d p a s s t h r o u g h . hpp

    # i n c l u d e AccrualCMO . hpp14 #i n c l u d e PACBonds . hpp

    16 u s i n g n am e sp a ce QuantLib ;u s i n g n am e sp a ce std ;

    18 u s i n g n am e sp a ce b o o s t : : a s s i g n ;

    20 b o o s t : : fo rm at FORMATER2 ( %10.4d % 1 0. 4 d % 10.4d ) ;

    16

  • 8/12/2019 Bond Examples Fabozzi Part2

    17/20

    i n t main()2 {

    t r y {4 R ate B on dR ate = 0 . 0 7 5 ;

    Rate WAC = 0. 08 12 5;6 Rate f e e = 0 . 0 ;

    DayCounter DC= Act ua lAc tu al ( Act ua lAc tu al : : ISDA) ;8 C a le n da r c a l e n d a r = N u l l Ca l e n da r ( ) ;

    Compounding compounded = Sim ple ;10 F r eq u e nc y f r e q u e n c y = A nn ua l ;

    12 In te re st Ra te bondRate( BondRate , DC, compounded , freq uen cy ) ;In te re st Ra te netWAC(WAC, DC, compounded , fr eq ue nc y ) ;

    14 D ate i s s u e (1 , J a n , 2 0 0 0 ) ;i s s u e = c a l e n d a r . a d j u s t ( i s s u e ) ;

    16 I n t e g e r Y ea rP ay me nts = 1 2 ;

    I n t e g e r S ea so ne d = 3 ;18 R e a l R e ma i ni n g Ye a rs = 3 0 ;

    20 std : : vecto r ParAmount ;ParAmount += 243800000 , 15620 0000;

    22 std : : vecto r CouponRate ;f o r(i n t i = 0; i < ParAmount. si z e () ; i++)

    24 {In te re st Ra te r (0 .0 75 ,DC, compounded , freq uen cy ) ;

    26 CouponRate += r ;}

    28 std : : vecto r type ;type += PAC1, Support;

    30

    std : : vector PSA;32 R e al Cap , F l o o r ;

    PSA += 0 . 0 , 0 . 5 , 0 . 9 , 1 . 0 , 1 . 5 , 1 . 6 5 , 2 . 0 , 2 . 5 , 3 . 0 , 3 . 5 , 4 . 0 , 4 . 5 , 5 . 0 ,7 . 0 ;

    34 Cap = 3 . 0 ;F lo or = 0 . 9 ;

    36

    c o u t

  • 8/12/2019 Bond Examples Fabozzi Part2

    18/20

    1 cout

  • 8/12/2019 Bond Examples Fabozzi Part2

    19/20

    t r y {2 R ate B on dR ate = 0 . 0 7 5 ;

    Rate WAC = 0. 09 5;4 Rate f e e = 0 . 0 0 5 ;

    DayCounter DC= Act ua lAc tu al ( Act ua lAc tu al : : ISDA) ;6 C a le n da r c a l e n d a r = N u l l Ca l e n da r ( ) ;

    Compounding compounded = Sim ple ;8 F r eq u e nc y f r e q u e n c y = A nn ua l ;

    10 In te re st Ra te bondRate( BondRate , DC, compounded , freq uen cy ) ;In te re st Ra te netWAC(WAC, DC, compounded , fr eq ue nc y ) ;

    12 D ate i s s u e (1 , J a n , 2 0 0 0 ) ;i s s u e = c a l e n d a r . a d j u s t ( i s s u e ) ;

    14 I n t e g e r Y ea rP ay me nts = 1 2 ;I n t e g e r S ea so ne d = 0 ;

    16 R e a l R e ma i ni n g Ye a rs = 3 0 ;

    18 // PassThroughFixedPassThrough FPT( is su e , calen dar , 100000 , bondRate , netWAC,

    RemainingYears , fee , YearPayments , 1. 0 , Seasoned ) ;20 / / Y i e l d Cu r v e

    Ra te y i e l d = 0 . 0 9 8 9 5 6 4 ;22 I n t e r e s tR a te Y i e l d ( y i e l d , DC, co mp ou nd ed , f r e q u e n c y ) ;

    24 Real NPV Passthrough = CashFlows : : npv(FPT. TotalCashFlow () , Yield , tr u e,i s s u e , i s s u e ) ; //Passthrough

    Real NPV IO = CashFlows : : npv(FPT. FixedRateMortgagePSA : : Ne t In t er es t ( ) ,Yield , tr u e , i s su e , i s s u e ) ; //IO

    26 Real NPV PO = CashFlows : : npv(FPT. FixedRateMortgagePSA : : To ta l Pr i nc ip al ( ) ,

    Yield , tr u e , i s su e , i s s u e ) ; //PO

    28 c o u t

  • 8/12/2019 Bond Examples Fabozzi Part2

    20/20

    In this case, duration and convexity approach differs from book. To estimate effective convexityand duration, FixedPassThrough class increase (reduce) the yield1.

    Clases may have suffer changes, during the development. You can found them in the blog as

    c++ files. I will send these to QuantLib in June 2014. Next blog will implement option pricingexamples and exercises found in Jhon C. Hull book: Option, Futures and Other Derivativessixth edition.

    1In the book, they increase (reduce) BEY.