52,99 €
Implementing Models of Financial Derivatives is a comprehensive treatment of advanced implementation techniques in VBA for models of financial derivatives. Aimed at readers who are already familiar with the basics of VBA it emphasizes a fully object oriented approach to valuation applications, chiefly in the context of Monte Carlo simulation but also more broadly for lattice and PDE methods. Its unique approach to valuation, emphasizing effective implementation from both the numerical and the computational perspectives makes it an invaluable resource. The book comes with a library of almost a hundred Excel spreadsheets containing implementations of all the methods and models it investigates, including a large number of useful utility procedures. Exercises structured around four application streams supplement the exposition in each chapter, taking the reader from basic procedural level programming up to high level object oriented implementations. Written in eight parts, parts 1-4 emphasize application design in VBA, focused around the development of a plain Monte Carlo application. Part 5 assesses the performance of VBA for this application, and the final 3 emphasize the implementation of a fast and accurate Monte Carlo method for option valuation. Key topics include: ?Fully polymorphic factories in VBA; ?Polymorphic input and output using the TextStream and FileSystemObject objects; ?Valuing a book of options; ?Detailed assessment of the performance of VBA data structures; ?Theory, implementation, and comparison of the main Monte Carlo variance reduction methods; ?Assessment of discretization methods and their application to option valuation in models like CIR and Heston; ?Fast valuation of Bermudan options by Monte Carlo. Fundamental theory and implementations of lattice and PDE methods are presented in appendices and developed through the book in the exercise streams. Spanning the two worlds of academic theory and industrial practice, this book is not only suitable as a classroom text in VBA, in simulation methods, and as an introduction to object oriented design, it is also a reference for model implementers and quants working alongside derivatives groups. Its implementations are a valuable resource for students, teachers and developers alike. Note: CD-ROM/DVD and other supplementary materials are not included as part of eBook file.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 1013
Veröffentlichungsjahr: 2011
Contents
Cover
Half Title page
Title page
Copyright page
Dedication
Preface
Related Reading
Structure of the Book
Acknowledgements
Part I: A Procedural Monte Carlo Method in VBA
Chapter 1: The Monte Carlo Method
1.1 The Monte Carlo Valuation Method
1.2 Issues with Monte Carlo
1.3 Computational Issues
1.4 Summary
1.5 Exercises
Chapter 2: Levels of Programming Sophistication
2.1 What Makes A Good Application?
2.2 A High-Level Design
2.3 Progressing Towards the Ideal
2.4 Summary
2.5 Exercises
Chapter 3: Procedural Programming: Level 1
3.1 Designing A Monte Carlo Valuation Application
3.2 Deficiencies of the Level 1 Code
3.3 Summary
3.4 Exercises
Chapter 4: Validation and Error Handling: Level 2
4.1 Validation and Error Handling
4.2 Encapsulating Functionality
4.3 The Level 2 main()
4.4 Summary
4.5 Exercises
Part II: Objects and Polymorphism
Chapter 5: Introducing Objects: Level 3
5.1 Objects in Vba
5.2 An Example: The StopWatch Object
5.3 Further Helpful VBA Features
5.4 Objects in the Monte Carlo Application
5.5 Summary
5.6 Exercises
Chapter 6: Polymorphism and Interfaces: Level 4
6.1 Polymorphism
6.2 Interfaces in VBA
6.3 Implementing A Polymorphic Stopwatch
6.4 Polymorphism and the Monte Carlo Application
6.5 Assessment of the Polymorphic Design
6.6 Summary
6.7 Exercises
Chapter 7: A Slice-Based Monte Carlo
7.1 The Revised Monte Carlo Application Object
7.2 The Option Object
7.3 The Evolver Object
7.4 Summary
7.5 Exercises
Chapter 8: An Embryonic Factory: Level 5
8.1 Events
8.2 The Level 5 Monte Carlo Application
8.3 The Factory Object
8.4 Output
8.5 Summary
8.6 Exercises
Part III: Using Files with VBA
Chapter 9: Input and Output to File in VBA
9.1 File Handling in VBA
9.2 The TextStream and FileSystemObject Objects
9.3 Intrinsic VB Language Functions
9.4 Example: Reading and Writing to Sequential and Random Files
9.5 Summary
9.6 Exercises
Chapter 10: Valuing a Book of Options
10.1 Outline of the Application
10.2 Timings
10.3 Summary
10.4 Exercises
Part VI: Polymorphic Factories in VBA
Chapter 11: The VBE Object Library and a Simple Polymorphic Factory
11.1 Using the Vbe Object Library
11.2 A Simple Factory Illustration
11.3 Summary
11.4 Exercises
Chapter 12: A Fully Polymorphic Factory: Level 6
12.1 Conceptual Features
12.2 The Polymorphic Factory
12.3 Using the Factory Object
12.4 Summary
12.5 Exercises
Chapter 13: A Semi-Polymorphic Factory: Meta-Classes
13.1 The Structure of the Application
13.2 Meta-Class Objects
13.3 The Semi-Polymorphic Factory
13.4 Summary
13.5 Exercises
Part V: Performance Issues in VBA
Chapter 14: Performance and Cost in VBA
14.2 Arithmetic Operations
14.3 Procedure Calls
14.4 Data Typing Issues
14.5 Summary
14.6 Exercises
Chapter 15: Level and Performance
15.1 Variations of the Level 0 Application
15.2 Effect of Level on Times
15.3 Summary
15.4 Exercises
Chapter 16: Evolution and Data Structures
16.1 Data Structures in VBA
16.2 Using VBA Containers
16.3 Numerical Comparisons
16.4 Summary
16.5 Exercises
Part VI: Variance Reduction in the Monte Carlo Method
Chapter 17: Wiener Sample Paths and Antithetic Variates
17.1 Generating Wiener Sample Paths
17.2 Antithetic Variates
17.3 Numerical Assessment
17.4 Summary
17.5 Exercises
Chapter 18: The Wiener Process and Stratified Sampling
18.1 Stratified Sampling
18.2 Implementing Stratified Sampling
18.3 Numerical Assessment
18.4 Summary
18.5 Exercises
Chapter 19: Low-Discrepancy Sampling
19.1 Low-Discrepancy Sampling
19.2 Implementing LD Sampling
19.3 Numerical Assessment
19.4 Summary
19.5 Exercises
Chapter 20: Variance Reduction with Control Variates
20.1 Control Variates
20.2 Examples of Control Variates
20.3 Auxiliary Model Control Variates
20.4 Summary
20.5 Exercises
Chapter 21: Implementing Control Variates
21.1 A Control Variate Application
21.2 Numerical Assessment
21.3 Summary
21.4 Exercises
Chapter 22: Extreme Options and Importance Sampling
22.1 Importance Sampling
22.2 Valuing an OTM Digital Option
22.3 Choices for the is Density
22.4 Implementing Importance Sampling
22.5 Numerical Assessment
22.6 Summary
22.7 Exercises
Chapter 23: Combining Variance Reduction Methods
23.1 Combining CV and IS
23.2 Implementing variance reduction methods in combination
23.3 Numerical Assessment
23.4 Summary
23.5 Exercises
Part VII: The Monte Carlo Method: Convergence and Bias
Chapter 24: The Monte Carlo Method: Convergence and Bias
24.1 Reducing Bias
24.2 Bias Reduction Methods
24.3 Bias and Barrier Options
24.4 Summary
24.5 Exercises
Chapter 25: Discretization Methods
25.1 Discretization and Convergence
25.2 It–taylor Discretization Schemes
25.3 Schemes in 1-Dimension
25.4 Predictor–Corrector Simulation
25.5 Numerical Assessment for Benchmark Processes
25.6 Summary
25.7 Exercises
Chapter 26: Applications to Models
26.1 The Cir Process
26.2 Simulating Discount Factors
26.3 Summary
26.5 Exercises
Chapter 27: Valuation in the Heston Model
27.1 Discretizing the Heston Model
27.2 Convergence in the Heston Model
27.3 Option Valuation in the Heston Model
27.4 Summary
27.5 Exercises
Part VIII: Valuing American Options by Simulation
Chapter 28: Valuing American and Bermudan Options
28.1 American Options
28.2 Monte Carlo and American Options
28.3 Summary
28.4 Exercises
Chapter 29: Estimating the Early Exercise Boundary
29.1 Approximating the Continuation Value Function
29.2 Choices for Basis Functions
29.3 The Early Exercise Boundary
29.4 Effect on Valuation
29.5 Summary
29.6 Exercises
Chapter 30: The Plain LSLS Method
30.1 Implementation in VBA
30.2 Valuing the American Put?
30.3 Summary
30.4 Exercises
Chapter 31: Control Variates and the LSLS Method
31.1 Control Variates and the American Put
31.2 Control Variates and the EEB
31.3 A Two-Pass LSLS
31.4 Summary
31.5 Exercises
Afterword
Appendices
Appendix A: VBA and Excel
A.1 Setting Up Excel
A.2 Compiler Problems in VBA
Appendix B: Some Option Formulae
B.1 Geometrically Averaged Average Rate Options
B.2 A Quadratic Payoff Option
B.3 A Bermudan Option
Appendix C: The Utility Code Modules
C.1 The Utility Procedures
C.2 The Complex Number Object
C.3 Quadrature
Appendix D: Running DLLs from VBA
Appendix E: Object-Oriented Programming
E.1 Motivation for Objects
E.2 Properties of Objects
E.3 Implementing Objects in VBA
E.4 Patterns of Object Use
E.5 Summary
Appendix F: A Yukky Level 0 Monolithic Lattice Implementation
F.1 Lattice Methods
F.2 Implementing A Level 0 Lattice Method
F.3 Summary
Appendix G: A Level 1 Crank–Nicolson PDE Implementation
G.1 PDE Methods for Derivative Valuation
G.2 The Crank–Nicolson Finite Difference Method
G.3 Implementing Crank–Nicolson
G.4 Assessment of the Design
G.5 Successive Over-Relaxation (SOR)
G.6 Summary
Appendix H: Root-Finding and Minimization Algorithms
H.1 Root Finding Algorithms
H.2 Minimization Algorithms
H.3 Summary
VBA, Modelling, and Computing Glossary
Abbreviations
Coding, Notational, and Typographical Conventions
Index to Code
Index to Spreadsheets
Index to Implementations
Index to Library Functions
Bibliography
Index
Implementing Models of Financial Derivatives
For other titles in the Wiley Finance series please see www.wiley.com
This edition first published 2011 © 2011, John Wiley & Sons, Ltd
Registered office John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, United Kingdom
For details of our global editorial offices, for customer services and for information about how to apply for permission to reuse the copyright material in this book please see our website at www.wiley.com
The right of the author to be identified as the author of this work has been asserted in accordance with the Copyright, Designs and Patents Act 1988.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, except as permitted by the UK Copyright, Designs and Patents Act 1988, without the prior permission of the publisher.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
Designations used by companies to distinguish their products are often claimed as trademarks. All brand names and product names used in this book are trade names, service marks, trademarks or registered trademarks of their respective owners. The publisher is not associated with any product or vendor mentioned in this book. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold on the understanding that the publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought.
Library of Congress Cataloging-in-Publication Data Webber, Nick. Implementing models of financial derivatives : object oriented applications with VBA / Nick Webber.p. cm. Includes bibliographical references and index. ISBN 978-0-470-71220-7 1. Derivative securities Mathematical models. 2. Microsoft Visual Basic for applications. I. Title. HG6024.A3W43 2010 332.64’570285543 – dc22 2010022097
A catalogue record for this book is available from the British Library.
ISBN: 978-0-470-71220-7 (hardback), ISBN: 978-0-470-66251-9 (ebk),
ISBN: 978-0-470-66173-4 (ebk), ISBN: 978-0-470-66184-0 (ebk)
To clients of this book, may you enjoy itas much as I enjoyed writing it.
Preface
The purpose of this book is, as the title suggests, to acquaint the reader with the more advanced features of Visual Basic for Applications (VBA), and programming methods in general, in the context of numerical applications in valuing financial derivatives. Specifically it discusses error handling, objects and interfaces, file handling, events, polymorphic factories, design patterns and data structures and shows how they are used in Monte Carlo methods.
The context for the book is the reader who is developing applications from Excel and who does not have, or does not want, access to VBA outside that which accompanies Excel. Throughout, by “VBA” is meant VBA v6.X, implemented with Excel. This is accessible and widely used. VBA 2005, regarded here as a hybrid mixture of VB and C++, is not used, nor is VBA.Net.
VBA is one of the great standard tools of application implementation. Its ability to meld with Excel, and other Office applications, and its ability to facilitate extremely fast development, has led to its wide adoption even for serious applications. Here I am concerned chiefly with its ability to implement fast numerical methods for derivative valuation. Remarkably one finds that although it is slower than C++, it is not significantly slower.1 One can make a very strong case that the complexity of C++ overweights its speed advantage, and that VBA should be the routine vehicle of choice for numerical application design – except where speed really is the over-riding, dominant factor, and where very sophisticated C++ support (rather than just proficient and ordinarily sufficient levels of support) is available.
The reader is assumed to be familiar with the basics of VBA; procedures, declarations, logical structures, et cetera, and using VBA from within Excel, but perhaps not so familiar with objects in VBA.
Our topic is VBA for numerical applications, specifically the Monte Carlo numerical integration method. Our emphasis is thus very different from that of database or games designers who have their own priorities, distinct from ours. They may need to manage a large diverse range of objects, and be concerned with their interactions, just as we do, but the emphasis is different. Our objects come in a relatively small number of families, each with a distinct function within the application; there are things that do the doing and things that get done. There may be a large database of option specifications, but a relatively small number of objects with very particular functions within the valuation machinery. Computation is intense but of a qualitatively different sort to, for instance, image rendering.
This book has evolved over the years out of teaching material used for courses at the University of Warwick and at Cass Business School, and in practitioner courses. My own appreciation of VBA and my ability to use it effectively have developed together over this period.
RELATED READING
There are a number of good books on VBA. These include Kimmel et al. (2004), Green et al. (2007), Getz and Gilbert (2001) and Lomax (1998). Kimmel et al. and Green et al. are reference style books that are nevertheless written pedagogically. Kimmel et al. is written around Excel 2003 whereas Green et al., a later version, is for Excel 2007. Getz and Gilbert is an older book (it is based in Office 2000) but it emphasizes object-oriented VBA. Lomax is even older, but is still fresh and worthwhile.
VBA has been used in several books whose subject is financial derivatives of one sort or another. These include Jackson and Staunton (2001), Rouah and Vainberg (2007), Loeffler and Posch (2007) and Haug (2007). The emphasis in these books is more on the underlying models and applications, rather than on the effective use of VBA.
This book bridges the two categories. Like the more advanced VBA books it is object-oriented; like the derivatives books, it is about numerical methods applied to financial derivatives. There exist books such as Duffy (2004, 2007), Joshi (2004) and London (2004) that apply object-oriented C++ to derivatives pricing models. This book fills an analogous role to these for VBA, arguing, as we have indicated, that VBA should be considered as a competitive implementation language for a range of applications.
The focus in this book is on Monte Carlo methods although both lattice methods and PDE methods are touched upon. An excellent high-level treatment of Monte Carlo methods for derivative valuation is Glasserman (2004). Jäckel (2002) is less technical but is highly recommended; the author comes across as having been there and done that. Further good references are McLeish (2005) and Dagpunar (2007).
Finally, in a class of its own, I have to mention Numerical Recipes in C++ (Press et al., (2007)). This book is a vade mecum for anyone in the numerics business. It is both a collection of coded numerical procedures and a textbook in its own right. The procedures it describes are widely applicable in many areas of science and computation, including those touched on here. Some of the more technical programs presented here adapt methods that can be found there. It is a strongly recommended buy for readers who wish to develop these aspects further.
STRUCTURE OF THE BOOK
This book is in eight parts. The first four parts focus on VBA. Each part introduces and discusses a new VBA feature and incorporates it into a developing, but plain, Monte Carlo application. The Monte Carlo method is used as a peg on which to hang some VBA. In stages, a simple procedural application is converted into a layered fully object-oriented application. Part I develops a very basic application. A simple procedural Monte Carlo method is constructed, and then error handling added in. Objects are introduced in Part II, including interfaces and run-time polymorphisms. Part III introduces files, demonstrating how the increasingly sophisticated application can input from file a book of options specifications and value them simultaneously. A polymorphic factory is constructed in Part IV.
Part V discusses performance-related issues, comparing, on the one hand, itty-bitty coding methods and, on the other, the costs of using the various built-in VBA data structures. It evaluates the performance of the Monte Carlo methods developed up to this point.
In the final three parts the focus is on the Monte Carlo application itself. The first of this group, Part VI, investigates a number of speed-up techniques, including stratified sampling, importance sampling, and the use of control variates. These are presented along with implementations and their effectiveness, alone and in combinations, assessed. Part VII looks at key practical issues linked by the concepts of convergence and bias. These include discretization, and option and model bias reduction methods. Finally, in a part to itself, valuation with the Longstaff and Schwartz least squares Monte Carlo method for American and Bermudan options is investigated.
A full set of appendices adds substantive material, including a discussion of lattice and PDE methods, a brief review of important root-finding methods, with implementations, and a primer on OOP.
In parallel with the exposition accompanying the development of the Monte Carlo application are a series of exercises. The reader is invited to develop a set of applications, several of which are presented first in appendices as low-level yukky applications, into high-level object-oriented structured applications. The applications are a simple trinomial application, a one-dimensional Crank-Nicolson PDE method, an implied volatility solver and an application to compute the value of π. Building up these applications, shadowing the evolution of the Monte Carlo application, enables the reader to apply at first hand the techniques presented in the chapters, and to experience directly the challenging delights of coding high-level applications. How to program can be learned only by doing it, not by reading about it or by listening to lectures.
ACKNOWLEDGEMENTS
I would like to thank everyone who has contributed to the development of this book. These include my students – not only those who have taken my VBA courses but also those who have given me very valuable and detailed comments on its various drafts. In particular I am grateful to Kai Zhang and Pokpong Chirayukool for their thorough and careful reading of the manuscript, and their thoughtful suggestions. Part VII has benefited particularly from Kai’s comments and Part VIII from Pokpong’s suggestions. Between them they have corrected a large number of errors.
I would like especially to thank Alexandra Dias for reviewing the entire book as it was being written. Her constructive and insightful criticisms have been very greatly appreciated. Finally, I am grateful to the anonymous reviewers for contributing a set of very useful suggestions based on detailed readings of the manuscript. These have led to notable improvements in the book. Remaining errors and deficiencies are my responsibility.
Nick WebberJanuary 2010
Part I
A Procedural Monte Carlo Method in VBA
This is an introductory part. Initial chapters introduce the Monte Carlo method in outline form, and discuss levels of program design.
Chapter 1 discusses the Monte Carlo method in abstract terms. It presents some of the mathematics lying behind the Monte Carlo methods that are later operationalized in code. It presents different evolution methods and data representation issues, but there is no actual coding.
Chapter 2 discusses issues in application design, setting the scene for the elaborations that follow. It briefly outlines the structure of an application that is developed through the first parts of the book.
In Chapter 3 we start to code up. This chapter constructs a purely procedural version of the Monte Carlo application. This has the properties of being utterly transparent but useless in practice; its faults are dissected and removed in subsequent chapters. Chapter 4 improves the application by introducing error handling. It also starts to move tentatively towards an object-oriented approach to programming by introducing a user-defined type to hold data in.
At this stage the application is still completely procedural. By the end of this part we will have gone about as far as it is sensible to go without using objects. Objects are introduced in Part II.
Chapter 2
Levels of Programming Sophistication
Much of this part is concerned with programming techniques, exploiting VBA features, and assessing the damage or delight this causes to speed and clarity. In this chapter we look at a grand design.
2.1 WHAT MAKES A GOOD APPLICATION?
A number of factors contribute towards a good application. Of course the application must provide basic functionality, but it is equally important to recognize that the strength of an application resides not only in what it happens to be able to do at the moment, but also in how easy it is to adapt its functionality to changing requirements.
