How to Implement Market Models Using VBA

Similar documents
Co p y r i g h t e d Ma t e r i a l

Financial Forecasting, Analysis, and Modelling

Fundamentals of Actuarial Mathematics

Paul Wilmott On Quantitative Finance

Handbook of Financial Risk Management

Stochastic Interest Rates

Mathematical Modeling and Methods of Option Pricing

Institute of Actuaries of India. Subject. ST6 Finance and Investment B. For 2018 Examinationspecialist Technical B. Syllabus

Interest Rate Modeling

Risk Management and Financial Institutions

A Foreign Exchange Primer

Martingale Methods in Financial Modelling

The SABR/LIBOR Market Model Pricing, Calibration and Hedging for Complex Interest-Rate Derivatives

MFE Course Details. Financial Mathematics & Statistics

Contents. Part I Introduction to Option Pricing

Martingale Methods in Financial Modelling

Principles of Group Accounting under IFRS

MFE Course Details. Financial Mathematics & Statistics

Handbook of Asset and Liability Management

by Kian Guan Lim Professor of Finance Head, Quantitative Finance Unit Singapore Management University

FINANCIAL DERIVATIVE. INVESTMENTS An Introduction to Structured Products. Richard D. Bateson. Imperial College Press. University College London, UK

AMSTERDAM BOSTON HEIDELBERG LONDON NEW YORK OXFORD PARIS SAN DIEGO SAN FRANCISCO SINGAPORE SYDNEY TOKYO Academic Press is an Imprint of Elsevier

Discounted Cash Flow. A Theory of the Valuation of Firms. Lutz Kruschwitz and Andreas Löffler

Preface Objectives and Audience

Risk-Neutral Valuation

THE NEW WEALTH MANAGEMENT

Risk Analysis. Assessing Uncertainties beyond Expected Values and Probabilities. Terje Aven. University of Stavanger, Norway

Implementing Models in Quantitative Finance: Methods and Cases

MFIN 7003 Module 2. Mathematical Techniques in Finance. Sessions B&C: Oct 12, 2015 Nov 28, 2015

With Examples Implemented in Python

Advanced Equity Derivatives


Hedge Fund. Course STUART A. MCCRARY. John Wiley & Sons, Inc.

Credit Risk Modeling Using Excel and VBA with DVD O. Gunter Loffler Peter N. Posch. WILEY A John Wiley and Sons, Ltd., Publication

Monte Carlo Methods in Financial Engineering

Project Finance in Construction

INTRODUCTION TO THE ECONOMICS AND MATHEMATICS OF FINANCIAL MARKETS. Jakša Cvitanić and Fernando Zapatero

QUANTITATIVE INVESTMENT ANALYSIS WORKBOOK

Fixed Income Modelling

Financial Models with Levy Processes and Volatility Clustering

Financial Statistics and Mathematical Finance Methods, Models and Applications. Ansgar Steland

Curriculum. Written by Administrator Sunday, 03 February :33 - Last Updated Friday, 28 June :10 1 / 10

Discrete Models of Financial Markets

MULTISCALE STOCHASTIC VOLATILITY FOR EQUITY, INTEREST RATE, AND CREDIT DERIVATIVES

Contents Critique 26. portfolio optimization 32

SYLLABUS. IEOR E4728 Topics in Quantitative Finance: Inflation Derivatives

Monte Carlo Methods in Finance

FE501 Stochastic Calculus for Finance 1.5:0:1.5

Global Property Investment

HIGH- FREQUENCY TRADING

Computational Methods in Finance

WILEY A John Wiley and Sons, Ltd., Publication

Master of Science in Finance (MSF) Curriculum

2.1 Mathematical Basis: Risk-Neutral Pricing

Market interest-rate models

MSc Financial Mathematics

Market Risk Analysis Volume I

FIXED INCOME SECURITIES

The Option Trader Handbook

Actuarial Models : Financial Economics

Derivative Securities Fall 2012 Final Exam Guidance Extended version includes full semester

MSc Financial Mathematics

MARVIN RAUSAND. Risk Assessment. Theory, Methods, and Applications STATISTICS I:-\ PRACTICE

Fundamentals of Futures and Options Markets

Pricing Options with Mathematical Models

Economic Scenario Generator: Applications in Enterprise Risk Management. Ping Sun Executive Director, Financial Engineering Numerix LLC

The Mathematics Of Financial Derivatives: A Student Introduction Free Ebooks PDF

MS Finance-Quantitative (MSFQ) Academic Year

Financial Engineering MRM 8610 Spring 2015 (CRN 12477) Instructor Information. Class Information. Catalog Description. Textbooks

The Liquidity Theory of Asset Prices. Gordon Pepper with Michael J. Oliver

TRADING OPTION GREEKS

Managing the Newest Derivatives Risks

for Finance Python Yves Hilpisch Koln Sebastopol Tokyo O'REILLY Farnham Cambridge Beijing

Accelerated Option Pricing Multiple Scenarios

Budgeting Basics and Beyond

MATH4143: Scientific Computations for Finance Applications Final exam Time: 9:00 am - 12:00 noon, April 18, Student Name (print):

Strategic Corporate Finance

Simple Profits from Swing Trading, Revised and Updated

DANIEL W. HALPIN, PURDUE UNIVERSITY BOLIVAR A. SENIOR, COLORADO STATE UNIVERSITY JOHN WILEY & SONS, INC.

The Pennsylvania State University. The Graduate School. Department of Industrial Engineering AMERICAN-ASIAN OPTION PRICING BASED ON MONTE CARLO

Wiley Trading ENH A NCED INDEXING STR ATEGIES. Ut ilizing Fu ture s and O p tions to Ac hieve Higher Pe r formanc e. Tristan Yates

NUMERICAL AND SIMULATION TECHNIQUES IN FINANCE

Studies in Computational Intelligence

DAY TRADING AND SWING TRADING THE CURRENCY MARKET

Table of Contents. Part I. Deterministic Models... 1

Valuation. The Market Approach

STOCHASTIC MODELLING OF ELECTRICITY AND RELATED MARKETS

Statistical Models and Methods for Financial Markets

Interest Rate Bermudan Swaption Valuation and Risk

Interpretation and Application of. IFRS Standards

ICEF, Higher School of Economics, Moscow Msc Programme Autumn Derivatives

Accounting for Derivatives

MODULE SPECIFICATIONS. Mathematical Methods of Finance (Online Version) Level M, Certificate Stage, 20 credits

SYLLABUS. IEOR E4724 Topic in Quantitative Finance: Introduction to Structured and Hybrid Products

ADDITIONAL PRAISE FOR MIDDLE MARKET M&A

Monte Carlo Methods in Structuring and Derivatives Pricing

Computer Exercise 2 Simulation

Interest Rate Cancelable Swap Valuation and Risk

The Enlargement of the European Union

Business Ratios and Formulas

Transcription:

How to Implement Market Models Using VBA

How to Implement Market Models Using VBA FRANÇOIS GOOSSENS

This edition first published 2015 2015 François Goossens 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. 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 publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com. 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. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with the respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. It is sold on the understanding that the publisher is not engaged in rendering professional services and neither the publisher nor the author shall be liable for damages arising herefrom. 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 is Available ISBN 978-1-118-96200-8 (hardback) ISBN 978-1-118-96198-8 (ebk) ISBN 978-1-118-96199-5 (ebk) ISBN 978-1-119-06583-8 Cover Design: Wiley Top Image: istock.com/pixel_dreams; Bottom Image: istock.com/awstok Set in 10/12pt Times by Laserwords Private Limited, Chennai, India Printed in Great Britain by TJ International Ltd, Padstow, Cornwall, UK

Contents Preface Acknowledgements Abbreviations About the Author ix xi xiii xv CHAPTER 1 The Basics of VBA Programming 1 1.1 Getting started 1 1.2 VBA objects and syntax 2 1.2.1 The object-oriented basic syntax 3 1.2.2 Using objects 3 1.3 Variables 5 1.3.1 Variable declaration 5 1.3.2 Some usual objects 7 1.3.3 Arrays 9 1.4 Arithmetic 10 1.5 Subroutines and functions 13 1.5.1 Subroutines 14 1.5.2 Functions 15 1.5.3 Operations on one-dimensional arrays 16 1.5.4 Operations on two-dimensional arrays (matrices) 16 1.5.5 Operations with dates 19 1.6 Custom objects 21 1.6.1 Types 21 1.6.2 Classes 22 1.7 Debugging 24 1.7.1 Error handling 24 1.7.2 Tracking the code execution 25 v

vi CONTENTS CHAPTER 2 Mathematical Algorithms 29 2.1 Introduction 29 2.2 Sorting lists 29 2.2.1 Shell sort 29 2.2.2 Quick sort 32 2.3 Implicit equations 34 2.4 Search for extrema 36 2.4.1 The Nelder-Mead algorithm 36 2.4.2 The simulated annealing 40 2.5 Linear algebra 43 2.5.1 Matrix inversion 44 2.5.2 Cholesky decomposition 46 2.5.3 Interpolation 48 2.5.4 Integration 57 2.5.5 Principal Component Analysis 60 CHAPTER 3 Vanilla Instruments 67 3.1 Definitions 67 3.2 Fixed income 67 3.2.1 Bond market 68 3.2.2 Interbank market 72 3.3 Vanilla derivatives 75 3.3.1 Forward contracts 75 3.3.2 Swaps 77 3.3.3 Bond futures 81 3.4 Options basics 84 3.4.1 Brownian motion 84 3.4.2 Ito integral 85 3.4.3 Ito formula 86 3.4.4 Black Scholes basic model 89 3.4.5 Risk-neutral probability 90 3.4.6 Change of probability 90 3.4.7 Martingale and numeraires 92 3.4.8 European-style options pricing 94 3.5 First generation exotic options 95 3.5.1 Barrier options 95 3.5.2 Quanto options 102 CHAPTER 4 Numerical Solutions 105 4.1 Finite differences 105 4.1.1 Generic equation 105 4.1.2 Implementation 106

Contents vii 4.2 Trees 112 4.2.1 Binomial trees 112 4.2.2 Trinomial trees 116 4.3 Monte-Carlo scenarios 116 4.3.1 Uniform number generator 117 4.3.2 From uniform to Gaussian numbers 127 4.4 Simulation and regression 129 4.5 Double-barrier analytical approximation 134 CHAPTER 5 Monte-Carlo Pricing Issues 139 5.1 Multi-asset simulation 139 5.1.1 The correlations issue 139 5.1.2 The Gaussian case 139 5.1.3 Exotics 143 5.2 Discretization schemes 146 5.3 Variance reduction techniques 147 5.3.1 Antithetic variates 147 5.3.2 Importance sampling 148 5.3.3 Control variates 153 CHAPTER 6 Yield Curve Models 163 6.1 Short rate models 163 6.1.1 Introduction 163 6.1.2 Hull and White one-factor model 164 6.1.3 Gaussian two-factor model 180 6.1.4 Hull and White two-factor model 203 6.2 Forward rate models 204 6.2.1 Generic Heath-Jarrow-Morton 205 6.2.2 LMM (LIBOR market model) 216 CHAPTER 7 Stochastic Volatilities 233 7.1 The Heston model 234 7.1.1 Code 234 7.1.2 A faster algorithm 239 7.1.3 Calibration 248 7.2 Barrier options 254 7.2.1 Numerical results 257 7.2.2 Code 257 7.3 Asian-style options 260 7.4 SABR model 264 7.4.1 Caplets 264 7.4.2 Code 265

viii CONTENTS CHAPTER 8 Interest Rate Exotics 267 8.1 CMS swaps 267 8.1.1 Code 269 8.2 Cancelable swaps 272 8.2.1 Code 272 8.2.2 Tree approximation 276 8.3 Target redemption note 281 8.3.1 Code 282 Bibliography 287 Index 289

Preface Graduate students and practitioners coming to the area of quantitative finance may be daunted by the abstruseness of stochastic matters, coupled with the austerity of scientific programming languages. Learning these disciplines is a challenge that some are reluctant to tackle. Then, to get some hands-on expertise of complex valuation issues with an easy-to-learn programming language, without delving too deeply into the theory, proves to be an attractive alternative: this is what this book invites you to do. For this purpose, VBA has been chosen for its accessible code and its connection with Excel and its easy-to-use spreadsheet format. What sort of financial applications may be run in VBA? Contrary to common belief, you can run a lot of complex pricings with VBA, almost as fast as in C++ even if VBA is not going to compete with C++ as the engine of big risk management systems. This book will not specifically address the computing performance topic: for a comprehensive approach to this see, e.g., Webber (2011). However, one thing to remember is that, not only in terms of accuracy, but also in terms of computational cost, VBA is an efficient tool to get fast and in-depth understanding skills on complex derivatives. How this book can help you To complete a pricing project from scratch is a road paved with challenging steps. If you are holding this book it means you are already a VBA developer, or you intend to become one, and you have some taste for quantitative matters: it is already a good start. Guiding you through the technical obstacles and making you familiar with the means to fix them is the ambition of this book. The quicker you complete your first Monte-Carlo algorithm or tree-based pricing program, the more self-confidence you get, if you are a newcomer in applications coding. To strengthen this self-confidence, no aspect of quantitative issues must remain in the shadow: you will probably notice that barrier option valuation theory and yield curve modeling are developed in detail, for they illustrate best the key notions of stochastic calculus. Knowledge prerequisites No VBA knowledge is required. The essentials presented in this book should suffice. You must have basic notions of analysis (continuity, derivability, integration) and linear algebra basics (matrix calculus). In the capital markets domain, you must be familiar with vanilla derivatives (forward contracts, European-style options) and, preferably, have some knowledge of the common risk management issues, such as delta or gamma positions. As regards the stochastic calculus theory, this book helps you to apply theory with a practical approach. ix

x PREFACE Structure of the book Chapter 1 delivers the essential syntax and vocabulary elements to start coding algorithms in VBA; some emphasis is put on matricial calculus, as it occupies a prominent place in numerical algorithms and Monte-Carlo scenarios. Chapter 2 introduces common algorithms that fix unavoidable numerical problems in the course of a pricing algorithm. In fact, every valuation program will encounter at least one interpolation or optimization hurdle at some stage of the algorithm. Chapter 3 gives the reader an opportunity to check his knowledge of the capital market fundamentals. For complete VBA beginners, it also provides some training exercises to put into practice VBA techniques, such as loops. In a second part, one key aspect of the stochastic calculus theory, the change of probability measure is addressed. This technique is implemented via barrier options pricing. Chapter 4 deals with numerical solutions that are called in aid when no analytical solution is available: to put it bluntly, it fixes 99% of the problems. This is the core material of the book, since every pricing algorithm refers more or less to one of the recipes presented in this chapter. Chapter 5 deals with classes of assets that are valued using Monte-Carlo simulation methods. It covers multi-asset and path-dependent instruments. Variance reduction techniques are logically investigated in this chapter. Chapter 6 addresses widely used yield curve models and the critical calibration issues. It introduces first Hull & White and Gaussian short rate models, secondly Heath-Jarrow-Morton and LIBOR market forward rate curve models. Chapter 7: as a widespread standard stochastic volatility model, Heston s is here presented in detail. Some recipes to tackle exotic pricings using this model are developed. In addition, one paragraph is devoted to SABR. Chapter 8: in this chapter, our yield curve modelings are put into application to implement numerical algorithms aimed at some "standard" interest rate exotics: CMS Swaps, Cancelable Swaps, and Target Redemption Notes. Solutions resulting from different models or numerical methods will be compared.

Acknowledgements My thanks go first to the staff of Wiley for their patience and assistance in the unenviable task of correcting the manuscript. I would also like to thank the practitioners and principal lecturers at the Paris Dauphine and Paris-Sorbonne universities who provided time from their busy schedules to review or comment on this book. Advice and encouragement given by Sofiane Aboura especially have been of great help in completing the work. Last but not least, I would like to express my gratitude to the authors, some are mentioned in the bibliography, who succeeded in making quantitative finance an appealing matter: I owe them an incurable taste for financial algorithms. xi

Abbreviations ATM BGM BS CMS HJM IRS LMM OTC RNG RV TARN At-the-money (options) Benhamou/Gobet/Miri approximation method (Heston model) Black Scholes Constant Maturity Swap Heath-Jarrow-Morton model Interest Rate Swap LIBOR Market Model Over-The-Counter Random Number Generator Random Variable TArget Redemption Note xiii

About the Author François Goossens has 12 years experience in Java and VBA programming of pricing algorithms. As a consultant, he currently trains students and young practitioners in computational finance through VBA coding. Prior to that he ran, over 15 years, interest-rates and equity related trading desks with Credit Lyonnais and Ixis, and was strongly involved in exotic derivatives management. François graduated from École Centrale in Paris. xv