MATLAB Financial Derivatives Toolbox User's Guide

Transcription

Financial DerivativesToolboxFor Use with MATLAB ComputationVisualizationProgrammingUser’s GuideVersion 2

How to Contact The Newsgroupinfo@mathworks.comTechnical supportProduct enhancement suggestionsBug reportsDocumentation error reportsOrder status, license renewals, passcodesSales, pricing, and general information508-647-7000Phone508-647-7001FaxThe MathWorks, Inc.3 Apple Hill DriveNatick, MA athworks.comFor contact information about worldwide offices, see the MathWorks Web site.Financial Derivatives Toolbox User’s Guide COPYRIGHT 2000 - 2001 by The MathWorks, Inc.The software described in this document is furnished under a license agreement. The software may be usedor copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc.FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation byor for the federal government of the United States. By accepting delivery of the Program, the governmenthereby agrees that this software qualifies as "commercial" computer software within the meaning of FARPart 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part252.227-7014. The terms and conditions of The MathWorks, Inc. Software License Agreement shall pertainto the government’s use and disclosure of the Program and Documentation, and shall supersede anyconflicting contractual terms or conditions. If this license fails to meet the government’s minimum needs oris inconsistent in any respect with federal procurement law, the government agrees to return the Programand Documentation, unused, to MathWorks.MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, andTarget Language Compiler is a trademark of The MathWorks, Inc.Other product or brand names are trademarks or registered trademarks of their respective holders.Printing History: June 2000Sept. 2001First printingSecond printingNew for Version 1 (Release 12)Updated for Version 2 (Release 12.1)

ContentsPrefaceAbout This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xOrganization of the Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . xTypographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiRelated Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiiBackground Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Black-Derman-Toy (BDT) Modeling . . . . . . . . . . . . . . . . . . . . . .Heath-Jarrow-Morton (HJM) Modeling . . . . . . . . . . . . . . . . . . .Financial Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xivxivxivxivGetting Started1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Interest Rate Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Financial Instruments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Hedging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-21-21-21-41-5Creating and Managing Instrument Portfolios . . . . . . . . . . 1-6Portfolio Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6Portfolio Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9i

Using Financial Derivatives2Interest Rate Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3Interest Rates vs. Discount Factors . . . . . . . . . . . . . . . . . . . . . . 2-3Interest Rate Term Conversions . . . . . . . . . . . . . . . . . . . . . . . . . 2-8Interest Rate Term Structure . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12Pricing and Sensitivity fromInterest Rate Term Structure . . . . . . . . . . . . . . . . . . . . . . . . . 2-17Pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18Sensitivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20Heath-Jarrow-Morton (HJM) Model . . . . . . . . . . . . . . . . . . . 2-22Building an HJM Forward Rate Tree . . . . . . . . . . . . . . . . . . . . 2-22Using HJM Trees in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . 2-28Pricing and Sensitivity from HJM . . . . . . . . . . . . . . . . . . . . .Pricing and the Price Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using treeviewer to View Instrument Prices Through Time .HJM Pricing Options Structure . . . . . . . . . . . . . . . . . . . . . . . .Calculating Prices and Sensitivities . . . . . . . . . . . . . . . . . . . . .2-352-352-402-442-50Black-Derman-Toy Model (BDT) . . . . . . . . . . . . . . . . . . . . . . . 2-53Building a BDT Interest Rate Tree . . . . . . . . . . . . . . . . . . . . . . 2-53Using BDT Trees in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . 2-58Pricing and Sensitivity from BDT . . . . . . . . . . . . . . . . . . . . .Pricing and the Price Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . .BDT Pricing Options Structure . . . . . . . . . . . . . . . . . . . . . . . . .Calculating Prices and Sensitivities . . . . . . . . . . . . . . . . . . . . .iiContents2-632-632-712-71

Hedging Portfolios3Hedging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2Hedging Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3Hedging with hedgeopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3Self-Financing Hedges (hedgeslf) . . . . . . . . . . . . . . . . . . . . . . 3-12Specifying Constraints with ConSet . . . . . . . . . . . . . . . . . . . 3-16Setting Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16Portfolio Rebalancing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18Hedging with Constrained Portfolios . . . . . . . . . . . . . . . . . .Example: Fully Hedged Portfolio . . . . . . . . . . . . . . . . . . . . . . .Example: Minimize Portfolio Sensitivities . . . . . . . . . . . . . . . .Example: Under-Determined System . . . . . . . . . . . . . . . . . . . .Portfolio Constraints with hedgeslf . . . . . . . . . . . . . . . . . . . . .3-213-213-233-253-26Function Reference4Functions by Category . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Alphabetical List of Functionsbdtprice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9bdtsens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12bdttimespec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15bdttree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17bdtvolspec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19bondbybdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20bondbyhjm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23bondbyzero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26bushpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29bushshape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-31capbybdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34iii

capbyhjm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-37cfbybdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-39cfbyhjm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-41cfbyzero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-43classfin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-45date2time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-47datedisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-49derivget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-50derivset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-51disc2rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-53fixedbybdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-55fixedbyhjm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-57fixedbyzero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-59floatbybdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-61floatbyhjm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-63floatbyzero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-65floorbybdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-67floorbyhjm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-70hedgeopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-72hedgeslf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-75hjmprice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-79hjmsens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-82hjmtimespec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-85hjmtree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-87hjmvolspec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-89instadd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-92instaddfield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-94instbond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-98instcap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-100instcf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-102instdelete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-104instdisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-106instfields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-108instfind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-111instfixed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-114instfloat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-116instfloor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-118instget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-120instgetcell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-124instlength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-129ivContents

instoptbnd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .instselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .instsetfield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .instswap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .insttypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .intenvget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .intenvprice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .intenvsens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .intenvset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .isafin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .mkbush . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .mktree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .mmktbybdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .mmktbyhjm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .optbndbybdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .optbndbyhjm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .rate2disc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .ratetimes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .swapbybdt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .swapbyhjm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .swapbyzero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .treepath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .treeshape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .treeviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94-1844-1874-1894-191GlossaryAv

viContents

PrefaceAbout This Book . . . . . . . . . . . . . . . . . . . xOrganization of the Document . . . . . . . . . . . . . . xTypographical Conventions . . . . . . . . . . . . . . xiRelated Products . . . . . . . . . . . . . . . . . . .xiiBackground Reading . . . . . . .Black-Derman-Toy (BDT) Modeling . .Heath-Jarrow-Morton (HJM) Modeling .Financial Derivatives . . . . . . . .xivxivxivxiv

PrefaceAbout This BookThis book describes the Financial Derivatives Toolbox for MATLAB , acollection of tools for analyzing individual financial derivative instruments andportfolios of instruments.Organization of the DocumentxChapterDescription“Getting Started”Describes interest rate models, bushy andrecombinent trees, instrument types, andinstrument portfolio construction.“Using FinancialDerivatives”Describes techniques for computing prices andsensitivities based upon the interest rate termstructure, the Heath-Jarrow-Morton (HJM) modelof forward rates, and the Black-Derman-Toy (BDT)interest rate model.“Hedging Portfolios”Describes functions that minimize the cost ofhedging a portfolio given a set of targetsensitivities, or minimize portfolio sensitivities fora given set of maximum target costs.“FunctionReference”Describes the functions used for interest rateenvironment computations, instrument portfolioconstruction and manipulation, and forHeath-Jarrow-Morton and Black-Derman-Toymodeling.

Typographical ConventionsTypographical ConventionsThis manual uses some or all of these conventions.ItemConvention UsedExampleExample codeMonospace fontTo assign the value 5 to A,enterA 5Function names/syntaxMonospace fontThe cos function finds thecosine of each array element.Syntax line example isMLGetVar ML var nameKeysBoldface with an initial capitalletterPress the Enter key.Literal strings (in syntaxdescriptions in referencechapters)Monospace bold for literalsf freqspace(n,'whole')MathematicalexpressionsItalics for variablesThis vector represents thepolynomialMATLAB outputStandard text font for functions,operators, and constantsMonospace fontp x2 2x 3MATLAB responds withA 5Menu titles, menu items,dialog boxes, and controlsBoldface with an initial capitalletterChoose the File menu.New termsItalicsAn array is an orderedcollection of information.Omitted input arguments(.) ellipsis denotes all of theinput/output arguments frompreceding syntaxes.[c,ia,ib] union(.)String variables (from afinite list)Monospace italicssysc d2c(sysd,'method')xi

PrefaceRelated ProductsThe MathWorks provides several products relevant to the tasks you canperform with the Financial Derivatives Toolbox.For more information about any of these products, see either: The online documentation for that product, if it is installed or if you arereading the documentation from the CD The MathWorks Web site, at http://www.mathworks.com; see the “products”section.Note The toolboxes listed below all include functions that extend thecapabilities of MATLAB.xiiProductDescriptionDatabase ToolboxTool for connecting to, and interacting with,most ODBC/JDBC databases from withinMATLABDatafeed ToolboxMATLAB functions for integrating thenumerical, computational, and graphicalcapabilities of MATLAB with financial dataprovidersExcel LinkTool that integrates MATLAB capabilities withMicrosoft Excel for WindowsFinancial Time SeriesToolboxTool for analyzing time series data in thefinancial marketsFinancial ToolboxMATLAB functions for quantitative financialmodeling and analytic prototyping

Related ProductsProductDescriptionGARCH ToolboxMATLAB functions for univariate GeneralizedAutoregressive Conditional Heteroskedasticity(GARCH) volatility modelingMATLABIntegrated technical computing environmentthat combines numeric computation, advancedgraphics and visualization, and a high-levelprogramming languageMATLAB CompilerCompiler for automatically convertingMATLAB M-files to C and C codeMATLAB ReportGeneratorTool for documenting information in MATLABin multiple output formatsMATLAB RuntimeServerMATLAB environment in which you can takean existing MATLAB application and turn itinto a stand-alone product that is easy andcost-effective to package and distribute. Usersaccess only the features that you provide viayour application’s graphical user interface(GUI). They do not have access to your code orthe MATLAB command line.Optimization ToolboxTool for general and large-scale optimization ofnonlinear problems, as well as for linearprogramming, quadratic programming,nonlinear least squares, and solving nonlinearequationsSpline ToolboxTool for the construction and use of piecewisepolynomial functionsStatistics ToolboxTool for analyzing historical data, modelingsystems, developing statistical algorithms, andlearning and teaching statisticsxiii

PrefaceBackground ReadingBlack-Derman-Toy (BDT) ModelingA description of the Black-Derman-Toy interest rate model can be found in:Black, Fischer, Emanuel Derman, and William Toy, “A One Factor Model ofInterest Rates and its Application to Treasury Bond Options,” FinancialAnalysts Journal, January - February 1990.Heath-Jarrow-Morton (HJM) ModelingAn introduction to Heath-Jarrow-Morton modeling, used extensively in theFinancial Derivatives Toolbox, can be found in:Jarrow, Robert A., Modelling Fixed Income Securities and Interest RateOptions, McGraw-Hill, 1996, ISBN 0-07-912253-1.Financial DerivativesInformation on the creation of financial derivatives and their role in themarketplace can be found in numerous sources. Among those consulted in thedevelopment of the Financial Derivatives toolbox are:Chance, Don. M., An Introduction to Derivatives, The Dryden Press, 1998,ISBN 0-030-024483-8Fabozzi, Frank J., Treasury Securities and Derivatives, Frank J. FabozziAssociates, 1998, ISBN 1-883249-23-6Hull, John C., Options, Futures, and Other Derivatives, Prentice-Hall, 1997,ISBN 0-13-186479-3Wilmott, Paul, Derivatives: The Theory and Practice of Financial Engineering,John Wiley and Sons, 1998, ISBN 0-471-983-89-6xiv

1Getting StartedIntroduction . . . .Interest Rate Models .Trees . . . . . . .Financial InstrumentsHedging . . . . . .1-21-21-21-41-5Creating and Managing Instrument Portfolios . . . . 1-6Portfolio Creation . . . . . . . . . . . . . . . . . . 1-6Portfolio Management . . . . . . . . . . . . . . . . 1-9

1Getting StartedIntroductionThe Financial Derivatives Toolbox extends the Financial Toolbox in the areasof fixed income derivatives and of securities contingent upon interest rates. Thetoolbox provides components for analyzing individual financial derivativeinstruments and portfolios. Specifically, it provides the necessary functions forcalculating prices and sensitivities, for hedging, and for visualizing results.Interest Rate ModelsThe Financial Derivatives Toolbox computes pricing and sensitivities ofinterest rate contingent claims based upon: The interest rate term structure (sets of zero coupon bonds) The Heath-Jarrow-Morton (HJM) model of the interest rate term structure.This model considers a given initial term structure of interest rates and aspecification of the volatility of forward rates to build a tree representing theevolution of the interest rates, based upon a statistical process. The Black-Derman-Toy (BDT) model for pricing interest rate derivatives. Inthe BDT model all security prices and rates depend upon the short rate(annualized one-period interest rate). The model uses long rates and theirvolatilities to construct a tree of possible future short rates. It thendetermines the value of interest rate sensitive securities from this tree.For information, see: “Pricing and Sensitivity from Interest Rate Term Structure” on page 2-17 fora discussion of price and sensitivity based upon portfolios of zero couponbonds. “Pricing and Sensitivity from HJM” on page 2-35 for a discussion of price andsensitivity based upon the HJM model. “Pricing and Sensitivity from BDT” on page 2-63 for a discussion of price andsensitivity based upon the BDT model.TreesThe Heath-Jarrow-Morton model works with a type of interest rate tree calleda bushy tree. A bushy tree is a tree in which the number of branches increasesexponentially relative to observation times; branches never recombine.1-2

IntroductionThe Black-Derman-Toy model, on the other hand, works with a recombiningtree. A recombining tree is the opposite of a bushy tree. A recombining tree hasbranches that recombine over time. From any given node, the node reached bytaking the path up-down is the same node reached by taking the path down-up.A bushy and a recombining tree are illustrated below.Bushy TreeRecombining TreeThis toolbox provides the data file deriv.mat that contains two trees, HJMTree,a bushy tree, and BDTTree, a recombining tree. The toolbox also provides thetreeviewer function, which graphically displays the shape and data of price,interest rate, and cash flow trees. Viewed with treeviewer, the bushy shape ofan HJM tree and the recombining shape of a BDT tree are apparent.1-3

1Getting StartedHJMTree (bushy)BDTTree (recombining)Financial InstrumentsThe toolbox provides a set of functions that perform computations uponportfolios containing up to seven types of financial instruments.Bond. A long-term debt security with preset interest rate and maturity, bywhich the principal and interest must be paid.Bond Options. Puts and calls on portfolios of bonds.Fixed Rate Note. A long-term debt security with preset interest rate andmaturity, by which the interest must be paid. The principal may or may not bepaid at maturity. In this version of the Financial Derivatives Toolbox, theprincipal is always paid at maturity.Floating Rate Note. A security similar to a bond, but in which the note’s interestrate is reset periodically, relative to a reference index rate, to reflectfluctuations in market interest rates.Cap. A contract which includes a guarantee that sets the maximum interestrate to be paid by the holder, based upon an otherwise floating interest rate.Floor. A contract which includes a guarantee setting the minimum interest rateto be received by the holder, based upon an otherwise floating interest rate.1-4

IntroductionSwap. A contract between two parties obligating the parties to exchange futurecash flows. This version of the Financial Derivatives Toolbox handles only thevanilla swap, which is composed of a floating rate leg and a fixed rate leg.Additionally, the toolbox provides functions for the creation and pricing ofarbitrary cash flow instruments based upon zero coupon bonds or upon the BDTor HJM models.HedgingThe Financial Derivatives Toolbox also includes hedging functionality,allowing the rebalancing of portfolios to reach target costs or targetsensitivities, which may be set to zero for a neutral-sensitivity portfolio.Optionally, the rebalancing process can be self-financing or directed by a set ofuser-supplied constraints. For information, see: “Hedging” on page 3-2 for a discussion of the hedging process. “hedgeopt” on page 4-72 for a description of the function that allocates anoptimal hedge. “hedgeslf” on page 4-75 for a description of the function that allocates aself-financing hedge.1-5

1Getting StartedCreating and Managing Instrument PortfoliosThe Financial Derivatives Toolbox provides components for analyzingindividual derivative instruments and portfolios containing several types offinancial instruments. The toolbox provides functionality that supports thecreation and management of these instruments: Bonds Bond Options Fixed Rate Notes Floating Rate Notes Caps Floors SwapsAdditionally, the toolbox provides functions for the creation of arbitrary cashflow instruments.The toolbox also provides pricing and sensitivity routines for theseinstruments. (See “Pricing and Sensitivity from Interest Rate Term Structure”on page 2-17, “Pricing and Sensitivity from HJM” on page 2-35, or “Pricing andSensitivity from BDT” on page 2-63 for information.)Portfolio CreationThe instadd function creates a set of instruments (portfolio) or addsinstruments to an existing instrument collection. The TypeString argumentspecifies the type of the investment instrument: 'Bond', 'OptBond','CashFlow', 'Fixed', 'Float', 'Cap', 'Floor', or 'Swap'. The inputarguments following TypeString are specific to the type of investmentinstrument. Thus, the TypeString argument determines how the remainderof the input arguments is interpreted.For example, instadd with the type string 'Bond' creates a portfolio of bondinstrumentsInstSet instadd('Bond', CouponRate, Settle, Maturity, Period,Basis, EndMonthRule, IssueDate, FirstCouponDate, LastCouponDate,StartDate, Face)1-6

Creating and Managing Instrument PortfoliosIn a similar manner, instadd can create portfolios of other types of investmentinstruments: Bond optionInstSet instadd('OptBond', BondIndex, OptSpec, Strike,ExerciseDates, AmericanOpt) Arbitrary cash flow instrumentInstSet instadd('CashFlow', CFlowAmounts, CFlowDates, Settle,Basis) Fixed rate note instrumentInstSet instadd('Fixed', CouponRate, Settle, Maturity,FixedReset, Basis, Principal) Floating rate note instrumentInstSet instadd('Float', Spread, Settle, Maturity, FloatReset,Basis, Principal) Cap instrumentInstSet instadd('Cap', Strike, Settle, Maturity, CapReset,Basis, Principal) Floor instrumentInstSet instadd('Floor', Strike, Settle, Maturity, FloorReset,Basis, Principal) Swap instrumentInstSet instadd('Swap', LegRate, Settle, Maturity, LegReset,Basis, Principal, LegType)To use the instadd function to add additional instruments to an existinginstrument portfolio, provide the name of an existing portfolio as the firstargument to the instadd function.1-7

1Getting StartedConsider, for example, a portfolio containing two cap instruments only.Strike [0.06; 0.07];Settle '08-Feb-2000';Maturity '15-Jan-2003';Port 1 instadd('Cap', Strike, Settle, Maturity);These commands create a portfolio containing two cap instruments with thesame settlement and maturity dates, but with different strikes. In general, theinput arguments describing an instrument can be either a scalar, or a numberof instruments (NumInst)-by-1 vector in which each element corresponds to aninstrument. Using a scalar assigns the same value to all instruments passed inthe call to instadd.Use the instdisp command to display the contents of the instrument set.instdisp(Port 1)Index Type Strike SettleMaturityCapReset Basis Principal1Cap 0.0608-Feb-2000 15-Jan-2003 NaNNaNNaN2Cap 0.0708-Feb-2000 15-Jan-2003 NaNNaNNaNNow add a single bond instrument to Port 1. The bond has a 4.0% coupon andthe same settlement and maturity dates as the cap instruments.CouponRate 0.04;Port 1 instadd(Port 1, 'Bond', CouponRate, Settle, Maturity);Use instdisp again to see the resulting instrument set.instdisp(Port 1)Index Type Strike SettleMaturityCapReset Basis Principal1Cap 0.0608-Feb-2000 15-Jan-2003 NaNNaNNaN2Cap 0.0708-Feb-2000 15-Jan-2003 NaNNaNNaNIndex Type CouponRate SettleMaturityPeriod Basis .3Bond 0.0408-Feb-2000 15-Jan-2003 NaNNaN .1-8

Creating and Managing Instrument PortfoliosPortfolio ManagementThe portfolio management capabilities provided by the Financial Derivativestoolbox include: Constructors for the most common financial instruments. (See “InstrumentConstructors” on page 1-9.) The ability to create new instruments or to add new fields to existinginstruments. (See “Creating New Instruments or Properties” on page 1-10.) The ability to search or subset a portfolio. See “Searching or Subsetting aPortfolio” on page 1-12.)Instrument ConstructorsThe toolbox provides constructors for the most common fin

MATLAB Datafeed Toolbox MATLAB functions for integrating the numerical, computational, and graphical capabilities of MATLAB with financial data providers Excel Link Tool that integrates MATLAB capabilities with Microsoft Excel for Windows Financial Time Series Toolbox Too