Derivatives Expert 
at the
Worldwide Mathematica Conference, June 1998

Sinan Gabel Khatib
Innova Financial Solutions
www.ifs.dk

Introduction

Long term project & just released

"A system for doing financial analysis"

Covers much more than just derivatives

At present approximately 13000 lines of Mathematica code & growing

500 page on-line notebook documentation

Covers the following areas broadly & deeply

1. Calendar Tools
 2. Utility Tools

 3. Discounting Tools
 4. TermStructure Tools

 5. Cash Flow Tools
 6. Pricing Tools
 7. Static Risk Tools

 8. Bonds
 9. Mortgage Backed Obligations
10. Floaters
11. Forwards
12. Swaps

13. Options

Abstract

Derivatives Expert is a modularly built program for doing financial analysis and engineering with respect to many exchange and over-the-counter traded securities and derivatives. Derivatives Expert is written entirely in Mathematica and can therefore utilize all of the advantages of Mathematica. It will be shown how easy and clear it is to do relatively advanced financial analysis with Derivatives Expert. The presentation will take into account that not all in the audience may have prior knowledge of financial analysis and will therefore focus on showing a few features that are easy to follow - but which still are able to underline the advantages of using Derivatives Expert in finance. 

Terminology will be explained as we go along. The cash flows, repayments, outstanding principals, and coupons will be calculated with respect to a number of different bonds, specifically annuity, bullet, console, serial, and "zero." In addition, a number of simple pricing and risk-estimation functions will be applied. To make things a little more fun we will recalculate some of the examples by incorporating restrictions with respect to business days and show the consequences of using different day counting conventions and different discounting conventions. If time permits, we can show how this applies with respect to mortgage-backed instruments where additional elements come into play. However, Derivatives Expert is a large package, and we can show only a few of its many features.

Outline of demonstration

Mainly package number 8 (total of 19) of Derivatives Expert

Calculation of cash flows, repayments, outstanding principals and coupons

Different bonds, specifically: annuity, bullet, consol, serial, and "zero."

Simple pricing and risk-estimation functions

Business days, day counting conventions and discounting methods

ExitCoupon and ExitRepayment

Other interest related instruments in D.E.: 
MBO's, Swaps, FRA's etc.

Demonstration

Opening the Bonds package

<< "DerivativesExpert`Bonds`"

Off[General::"spell1",  General::"spell"]

<< Graphics`Graphics`

Examples

General input format

1. Bullet[ principal, coupon, effectivedate, maturitydate, settlementdays, opts]

2. Function[ Object[arg11, arg12, ..., opt11, opt12 ...], arg21, arg22, ..., opt21, opt22]

A few cash flow related examples

bullet1 =  
      Bullet[ USD 100,  6.5,  {1998, 6,  21},  {2007, 11,  10}, 
         {{11, 10}} ];

Coupon[ bullet1]  //  MatrixForm

Repayment[ bullet1]  //  MatrixForm

OutstandingPrincipal[ bullet1]  //  MatrixForm

CashFlow[ bullet1]  //  MatrixForm

bul  =  
      Map[ Last[#]&,  
          CashFlow[ 
            Bullet[ USD 100,  6.5,  {1998, 6,  21},  {2007, 11,  10}, 
               {{11, 10}} ]]]  /.  USD  ->  1

ser  =  
      Map[ Last[#]&,  
          CashFlow[ 
            Serial[ USD 100,  6.5,  {1998, 6,  21},  {2007, 11,  10}, 
               {{11, 10}} ]]]  /.  USD  ->  1

ann  =  
      Map[ Last[#]&,  
          CashFlow[ 
            Annuity[ USD 100,  6.5,  {1998, 6,  21},  {2007, 11,  10}, 
               {{11, 10}} ]]]  /.  USD  ->  1

BarChart[ bul,  ser,  ann ,  PlotLabel  ->  "Cash Flows",  
      PlotRange  ->  All ]

BarChart[ bul,  ser,  ann ,  PlotLabel  ->  "Cash Flows",  
      PlotRange ->  {-5, 20} ]

Comment on Zero, Consol and "any cash flow"!

A few pricing and risk valuation examples

termstr1[t_]  :=  6  +  1/4*Sqrt[t];

Plot[termstr1[ t],  {t,  0, 10}]

PresentValue[ bullet1,  termstr1]  //  N //  MatrixForm

ImplicitYield[ bullet1  /.  USD  ->  1,  98.4564]

Duration[ bullet1,  6.71967,  DurationMethod  ->  ModifiedMacaulay]

A second term structure

termstr2[t_]  :=  7  -  1/16*Sqrt[t];

Plot[{termstr1[ t],  termstr2[t]},  {t,  0, 10}]

TermStructureRisk[ bullet1,  termstr1,  termstr2]  //  N //  
      MatrixForm

Business days, day counting conventions and discounting methods

E.g.

Options[ PresentValue]  //  TableForm

The relevant optionals.

ToWorkdaysQ -> No
DirectionLocal -> Forwards
SaturdayWorkdayQ -> No
HolidaysSpecific -> None
HolidaysGeneral -> None
HolidayList -> None

The holidays that the system knows.

SymbolsHolidays

\(CashFlow[\ 
        Bullet[\ USD\ 100, \ 6.5, \ {1998, 6, \ 21}, \ {2007, 11, \ 10}, 
          \ {{11, 10}}\ , \ 
DirectionLocal -> Backwards, \ 

          ToWorkdaysQ\  -> \ Yes, 

          HolidayList 
            -> {NewYearsDay, MartinLutherKingDay, PalmSunday, 
              ChristmasDay, NewYear}, 
HolidaysGeneral\  -> \ {{11, 10}}, 

          HolidaysSpecific\  -> \ {{1998, 6, 23}}]]\  // MatrixForm\)

LengthMonth -> Actual
LengthYear1 -> Actual
LengthYear2 -> Actual 
MethodDaycount -> NonAdditive

\(\(PresentValue[\ 
          Bullet[\ USD\ 100, \ 6.5, \ {1998, 6, \ 21}, \ {2007, 11, \ 10}, 
            \ {{11, 10}}\ , \ 
DirectionLocal -> Forwards, \ 

            ToWorkdaysQ\  -> \ Yes, 

            HolidayList 
              -> {NewYearsDay, MartinLutherKingDay, PalmSunday, 
                ChristmasDay, NewYear}, 
HolidaysGeneral\  -> \ {{11, 10}}, 
            
HolidaysSpecific\  -> \ {{1998, 6, 23}}, 
	
            LengthMonth\  -> \ 30, 
	LengthYear1\  -> \ 360, 
	
            LengthYear2\  -> \ 360, 
	MethodDaycount\  -> \ US], \ termstr1]
          \  // N\)\  // MatrixForm\)

Compounding -> {Exponential, 1}

\(\(PresentValue[\ 
          Bullet[\ USD\ 100, \ 6.5, \ {1998, 6, \ 21}, \ {2007, 11, \ 10}, 
            \ {{11, 10}}\ , \ 
DirectionLocal -> Forwards, \ 

            ToWorkdaysQ\  -> \ Yes, 

            HolidayList 
              -> {NewYearsDay, MartinLutherKingDay, PalmSunday, 
                ChristmasDay, NewYear}, 
HolidaysGeneral\  -> \ {{11, 10}}, 
            
HolidaysSpecific\  -> \ {{1998, 6, 23}}, 
	
            LengthMonth\  -> \ 30, 
	LengthYear1\  -> \ 360, 
	
            LengthYear2\  -> \ 360, 
	MethodDaycount\  -> \ US], \ 
          termstr1, 
	Compounding\  -> \ Continuous]\  // N\)\  // 
      MatrixForm\)

ExitCoupon and ExitRepayment

ExitCoupon -> 0
ExitRepayment -> 0

Change to a serial bond type to better see the influence of ExitCoupon and ExitRepayment.

\(\(PresentValue[\ 
          Serial[\ USD\ 100, \ 6.5, \ {1998, 6, \ 21}, \ {2007, 11, \ 10}, 
            \ {{11, 10}}\ , \ 
DirectionLocal -> Forwards, \ 

            ToWorkdaysQ\  -> \ Yes, 

            HolidayList 
              -> {NewYearsDay, MartinLutherKingDay, PalmSunday, 
                ChristmasDay, NewYear}, 
HolidaysGeneral\  -> \ {{11, 10}}, 
            
HolidaysSpecific\  -> \ {{1998, 6, 23}}, 
	
            LengthMonth\  -> \ 30, 
	LengthYear1\  -> \ 360, 
	
            LengthYear2\  -> \ 360, 
	MethodDaycount\  -> \ US, \ 
	
            ExitCoupon\  -> \ 0	], \ termstr1, 
	
          Compounding\  -> \ {Linear, \ 1}]\  // N\)\  // MatrixForm\)

\(\(PresentValue[\ 
          Serial[\ USD\ 100, \ 6.5, \ {1998, 6, \ 21}, \ {2007, 11, \ 10}, 
            \ {{11, 10}}\ , \ 
DirectionLocal -> Forwards, \ 

            ToWorkdaysQ\  -> \ Yes, 

            HolidayList 
              -> {NewYearsDay, MartinLutherKingDay, PalmSunday, 
                ChristmasDay, NewYear}, 
HolidaysGeneral\  -> \ {{11, 10}}, 
            
HolidaysSpecific\  -> \ {{1998, 6, 23}}, 
	
            LengthMonth\  -> \ 30, 
	LengthYear1\  -> \ 360, 
	
            LengthYear2\  -> \ 360, 
	MethodDaycount\  -> \ US, \ 
	
            ExitCoupon\  -> \ 180	], \ termstr1, 
	
          Compounding\  -> \ {Linear, \ 1}]\  // N\)\  // MatrixForm\)

\(\(PresentValue[\ 
          Serial[\ USD\ 100, \ 6.5, \ {1998, 6, \ 21}, \ {2007, 11, \ 10}, 
            \ {{11, 10}}\ , \ 
DirectionLocal -> Forwards, \ 

            ToWorkdaysQ\  -> \ Yes, 

            HolidayList 
              -> {NewYearsDay, MartinLutherKingDay, PalmSunday, 
                ChristmasDay, NewYear}, 
HolidaysGeneral\  -> \ {{11, 10}}, 
            
HolidaysSpecific\  -> \ {{1998, 6, 23}}, 
	
            LengthMonth\  -> \ 30, 
	LengthYear1\  -> \ 360, 
	
            LengthYear2\  -> \ 360, 
	MethodDaycount\  -> \ US, \ 
	
            ExitCoupon\  -> \ 180, 
	ExitRepayment\  -> \ 180	], \ 
          termstr1, 
	Compounding\  -> \ {Linear, \ 1}]\  // N\)\  // 
      MatrixForm\)

\(Repayment[\ 
        Serial[\ USD\ 100, \ 6.5, \ {1998, 6, \ 21}, \ {2007, 11, \ 10}, 
          \ {{11, 10}}\ , \ 
DirectionLocal -> Forwards, \ 

          ToWorkdaysQ\  -> \ Yes, 

          HolidayList 
            -> {NewYearsDay, MartinLutherKingDay, PalmSunday, 
              ChristmasDay, NewYear}, 
HolidaysGeneral\  -> \ {{11, 10}}, 

          HolidaysSpecific\  -> \ {{1998, 6, 23}}, 
	LengthMonth\  -> \ 30, 
          
	LengthYear1\  -> \ 360, 
	LengthYear2\  -> \ 360, 
	
          MethodDaycount\  -> \ US, \ 
	ExitCoupon\  -> \ 180, 
	
          ExitRepayment\  -> \ 180	]]\  // MatrixForm\)

\(Coupon[\ 
        Serial[\ USD\ 100, \ 6.5, \ {1998, 6, \ 21}, \ {2007, 11, \ 10}, 
          \ {{11, 10}}\ , \ 
DirectionLocal -> Forwards, \ 

          ToWorkdaysQ\  -> \ Yes, 

          HolidayList 
            -> {NewYearsDay, MartinLutherKingDay, PalmSunday, 
              ChristmasDay, NewYear}, 
HolidaysGeneral\  -> \ {{11, 10}}, 

          HolidaysSpecific\  -> \ {{1998, 6, 23}}, 
	LengthMonth\  -> \ 30, 
          
	LengthYear1\  -> \ 360, 
	LengthYear2\  -> \ 360, 
	
          MethodDaycount\  -> \ US, \ 
	ExitCoupon\  -> \ 180, 
	
          ExitRepayment\  -> \ 180	]]\  // MatrixForm\)