logo资料库

C++ for financial Engineering.pdf

第1页 / 共441页
第2页 / 共441页
第3页 / 共441页
第4页 / 共441页
第5页 / 共441页
第6页 / 共441页
第7页 / 共441页
第8页 / 共441页
资料共441页,剩余部分请下载后查看
Introduction to C++ for Financial Engineers
Contents
0 Goals of this Book and Global Overview
0.1 What is this Book?
0.2 Why has this Book been Written?
0.3 For whom is this Book Intended?
0.4 Why should I read this Book?
0.5 The Structure of this Book
0.6 What this Book does not Cover
0.7 More Information and Support
Part I C++ Essential Skills
1 Introduction to C++ and Quantitative Finance
1.1 Introduction and Objectives
1.2 A Short History of C++
1.3 C++, a Multi-Paradigm Language
1.3.1 Object-Oriented Paradigm
1.3.2 Generic Programming
1.3.3 Procedural, Modular and Functional Programming
1.4 C++ and Quantitative Finance: What’s the Relationship?
1.5 What is Software Quality?
1.6 Summary and Conclusions
1.7 Exercises
2 The Mechanics of C++: From Source Code to a Running Program
2.1 Introduction and Objectives
2.2 The Compilation Process
2.3 Header Files and Source Files
2.4 Creating Classes and Using their Objects
2.5 Template Classes and Template Functions
2.6 Kinds of Errors
2.6.1 Compiler Errors
2.6.2 Linker Errors
2.6.3 Run-Time Errors
2.7 The Struct Concept
2.8 Useful Data Conversion Routines
2.9 Summary and Conclusions
2.10 Exercises and Projects
3 C++ Fundamentals and My First Option Class
3.1 Introduction and Objectives
3.2 Class == member data + member functions
3.3 The Header File (Function Prototypes)
3.4 The Class Body (Code File)
3.5 Using the Class
3.6 Examining the Class in Detail
3.6.1 Accessibility Issues
3.6.2 Using Standard Libraries
3.6.3 The Scope Resolution Operator ‘::’
3.6.4 Virtual Destructor: Better Safe than Sorry
3.7 Other Paradigms
3.8 Summary and Conclusions
3.9 Questions, Exercises and Projects
4 Creating Robust Classes
4.1 Introduction and Objectives
4.2 Call by Reference and Call by Value
4.3 Constant Objects Everywhere
4.3.1 Read-Only (Const) Member Functions
4.4 Constructors in Detail
4.4.1 Member Initialisation
4.5 Static Member Data and Static Member Functions
4.6 Function Overloading
4.7 Non-Member Functions
4.8 Performance Tips and Guidelines
4.8.1 The ‘Inline’ Keyword
4.8.2 Anonymous Objects in Function Code
4.8.3 Loop Optimisation
4.9 Summary and Conclusions
4.10 Questions, Exercises and Projects
5 Operator Overloading in C++
5.1 Introduction and Objectives
5.2 What is Operator Overloading and what are the Possibilities?
5.3 Why Use Operator Overloading? The Advantages
5.4 Operator Overloading: The Steps
5.4.1 A Special Case: The Assignment Operator
5.5 Using Operator Overloading for Simple I/O
5.6 Friend Functions in General
5.6.1 Friend Classes
5.7 Summary and Conclusions
5.8 Exercise
Appendix: Useful Data Structures in C++
6 Memory Management in C++
6.1 Introduction and Objectives
6.2 Single Objects and Arrays of Objects on the Stack
6.3 Special Operators: 'new' and 'delete'
6.3.1 Single Objects
6.3.2 Arrays of Objects
6.4 Small Application: Working with Complex Numbers
6.5 Creating an Array Class
6.5.1 Memory Allocation and Deallocation
6.5.2 Accessing Functions
6.5.3 Examples
6.5.4 The Full Header File
6.6 Summary and Conclusions
6.7 Exercises
6.8 Review Questions and Comments
7 Functions, Namespaces and Introduction to Inheritance
7.1 Introduction and Objectives
7.2 Functions and Function Pointers
7.2.1 Functions in Financial Engineering
7.2.2 Function Categories
7.2.3 Modelling Functions in C++
7.2.4 Application Areas for Function Pointers, Part I
7.3 An Introduction to Namespaces in C++
7.3.1 Some Extra Functionality
7.4 An Introduction to the Inheritance Mechanism in C++
7.4.1 Basic Inheritance Structure
7.4.2 Adding New Functionality
7.4.3 Overriding Functionality: Polymorphic and Non-Polymorphic Behaviour
7.5 Multiple Inheritance
7.6 Solution of Nonlinear Equations
7.7 Nonlinear Solvers in C++: Design and Implementation
7.8 Applying Nonlinear Solvers: Calculating Volatility
7.9 Summary and Conclusions
7.10 Exercises and Projects
8 Advanced Inheritance and Payoff Class Hierarchies
8.1 Introduction and Objectives
8.2 The Virtual Specifier and Memory Deallocation
8.3 Abstract and Concrete Classes
8.3.1 Using Payoff Classes
8.4 Lightweight Payoff Classes
8.5 Super Lightweight Payoff Functions
8.6 The Dangers of Inheritance: A Counterexample
8.7 Implementation Inheritance and Fragile Base Class Problem
8.7.1 Deep Hierarchies
8.7.2 Multiple Inheritance Problems
8.8 Two-Factor Payoff Functions and Classes
8.9 Conclusions and Summary
8.10 Exercises and Projects
9 Run-Time Behaviour in C++
9.1 Introduction and Objectives
9.2 An Introduction to Reflection and Self-Aware Objects
9.3 Run-Time Type Information (RTTI)
9.4 Casting between Types
9.4.1 More Esoteric Casting
9.5 Client-Server Programming and Exception Handling
9.6 Try,Throw and Catch : Ingredients of the C++ Exception Mechanism
9.7 C++ Implementation
9.8 Pragmatic Exception Mechanisms
9.8.1 An Example of Use
9.9 Conclusions and Summary
9.10 Exercises and Research
10 An Introduction to C++ Templates
10.1 Introduction and Objectives
10.2 My First Template Class
10.2.1 Using Template Classes
10.2.2 (Massive) Reusability of the Range Template Class
10.3 Template Functions
10.4 Consolidation: Understanding Templates
10.4.1 A Test Program
10.5 Summary and Conclusions
10.6 Exercises and Projects
Part II Data Structures, Templates and Patterns Data Structures, Templates and Patterns
11 Introduction to Generic Data Structures and Standard Template Library (STL)
11.1 Introduction and Objectives
11.2 Complexity Analysis
11.2.1 Examples of Complexities
11.3 An Introduction to Data Structures
11.3.1 Lists
11.3.2 Stacks and Queues
11.3.3 Sets and Multisets
11.3.4 Maps and Multimaps
11.4 Algorithms
11.5 Navigation in Data Structures: Iterators in STL
11.6 STL by Example: My First Example
11.6.1 Constructors and Memory Allocation
11.6.2 Iterators
11.6.3 Algorithms
11.7 Conclusions and Summary
11.8 Exercises and Projects
12 Creating Simpler Interfaces to STL for QF Applications
12.1 Introduction and Objectives
12.2 Maps and Dictionaries
12.2.1 Iterating in Maps
12.2.2 Erasing Records in a Map
12.3 Applications of Maps
12.4 User-Friendly Sets
12.4.1 STL Sets
12.4.2 User-Defined and Wrapper Classes for STL Sets
12.5 Associative Arrays and Associative Matrices
12.6 Applications of Associative Data Structures
12.7 Conclusions and Summary
12.8 Exercises and Projects
13 Data Structures for Financial Engineering Applications
13.1 Introduction and Objectives
13.2 The Property Pattern
13.3 Property Sets
13.3.1 Basic Functionality
13.3.2 Addition and Removal of Properties
13.3.3 Navigating in a Property Set: Creating your own Iterators
13.3.4 Property Sets with Heterogeneous Data Types
13.4 Property Sets and Data Modelling for Quantitative Finance
13.4.1 Fixed Assemblies (Assemblies-Parts Relationship)
13.4.2 Collection-Members Relationship
13.4.3 Container-Contents Relationship
13.4.4 Recursive and Nested Property Sets
13.5 Lattice Structures
13.5.1 Some Simple Examples
13.5.2 A Simple Binomial Method Solver
13.6 Conclusions and Summary
13.7 Exercises and Projects
14 An Introduction to Design Patterns
14.1 Introduction and Objectives
14.2 The Software LifeCycle
14.3 Documentation Issues
14.3.1 Generalisation and Specialisation
14.3.2 Aggregation and Composition
14.3.3 Associations
14.3.4 Other Diagrams
14.4 An Introduction to Design Patterns
14.4.1 Creational Patterns
14.4.2 Structural Patterns
14.4.3 Behavioural Patterns
14.5 Are we Using the Wrong Design? Choosing the Appropriate Pattern
14.6 CADObject, a C++ Library for Computer Graphics
14.7 Using Patterns in CADObject
14.8 Conclusions and Summary
14.9 Exercises and Projects
Part III QF Applications
15 Programming the Binomial Method in C++
15.1 Introduction and Objectives
15.2 Scoping the Problem
15.3 A Short Overview of the Binomial Method
15.4 Software Requirements for a Binomial Solver
15.5 Class Design and Class Structure
15.5.1 UML Class Structure
15.5.2 Information Flow
15.6 Applying Design Patterns
15.7 The Builder and Director Classes
15.8 The Process and the Steps
15.9 Test Cases and Examples
15.10 Conclusions and Summary
15.11 Exercises and Questions
16 Implementing One-Factor Black Scholes in C++
16.1 Introduction and Objectives
16.2 Scope and Assumptions
16.3 Assembling the C++ Building Blocks
16.4 Modelling the Black Scholes PDE
16.4.1 Creating your own One-Factor Financial Models
16.5 Finite Difference Schemes
16.5.1 Explicit Schemes
16.5.2 Implicit Schemes
16.5.3 A Note on Exception Handling
16.5.4 Other Schemes
16.6 Test Cases and Presentation in Excel
16.6.1 Creating the user Interface Dialogue
16.6.2 Vector and Matrix Output
16.6.3 Presentation
16.7 Summary
16.8 Exercises and Projects
17 Two-Factor Option Pricing: Basket and Other Multi-Asset Options
17.1 Introduction and Objectives
17.2 Motivation and Background
17.3 Scoping the Problem: PDEs for Basket Options
17.4 Modelling Basket Option PDE in UML and C++
17.4.1 Data Classes for Instruments
17.4.2 Modelling the PDE with C++ Classes
17.5 The Finite Difference Method for Two-Factor Problems
17.6 Discrete Boundary and Initial Conditions
17.7 Assembling the System of Equations
17.8 Post Processing and Output
17.9 Summary and Conclusions
17.10 Exercises and Projects
18 Useful C++ Classes for Numerical Analysis Applications in Finance
18.1 Introduction and Objectives
18.2 Solving Tridiagonal Systems
18.2.1 A Tridiagonal Solver in C++
18.3 An Introduction to Interpolation
18.3.1 Polynomial Interpolation
18.3.2 Rational Function Interpolation
18.3.3 Cubic Spline Interpolation
18.4 Summary and Conclusions
19 Other Numerical Methods in Quantitative Finance
19.1 Introduction and Objectives
19.2 The Trinomial Method for Assets
19.3 Lattice Data Structures
19.4 Trinomial Tree for the Short Rate
19.5 The Multidimensional Binomial Method
19.6 Generic Lattice Structures
19.6.1 Candlestick Charts
19.6.2 (Highly) Generic Lattice Structures
19.7 Approximating Exponential Functions
19.8 Summary and Conclusions
19.9 Exercises
20 The Monte Carlo Method Theory and C++ Frameworks
20.1 Introduction and Objectives
20.2 A Short History of the Monte Carlo (MC) Method
20.3 Examples of the Application of the Monte Carlo Method
20.3.1 Calculation of Definite Integrals
20.3.2 Device Reliability
20.4 The Monte Carlo Method in Quantitative Finance
20.4.1 An Overview of Stochastic Differential Equations (SDE)
20.4.2 Other Background Information
20.5 Software Architecture for the Monte Carlo Method
20.6 Examples and Test Cases
20.6.1 Plain Options
20.6.2 Barrier Options
20.6.3 Asian Options
20.7 Summary and Conclusions
20.8 Appendix: Comparing Monte Carlo with Other Numerical Methods
20.9 Exercises and Projects
21 Skills Development: from White Belt to Black Belt
21.1 Introduction and Objectives
21.2 Review of Book
21.3 Part I: C++ Essential Skills
21.4 Part II: Data Structures, Templates and Patterns
21.5 Part III: Applications in Quantitative Finance
21.6 Part IV: Background Information
21.7 Choosing a Programming Paradigm
21.7.1 Layer 1: Foundation Classes
21.7.2 Layer 2: Mechanisms
21.7.3 Layer 3: Building Blocks
21.7.4 Layer 4: Application Level
21.8 Summary and Conclusions
Part IV Background Information
22 Basic C Survival Guide
22.1 Introduction and Objectives
22.2 Basic Data Types
22.3 The C Preprocessor
22.4 Pointers and References
22.5 Other Useful Bits and Pieces
22.6 What to Avoid in C
22.7 Test Case: Numerical Integration in One Dimension
22.8 Conclusions and Summary
22.9 Exercises
23 Advanced C Syntax
23.1 Introduction and Objectives
23.2 Fixed-Size and Dynamic Arrays
23.3 Multi-Dimensional Arrays
23.4 Introduction to Structures
23.5 Unions
23.6 Useful C Libraries
23.7 Test Case: Linear Regression
23.8 Conclusions and Summary
23.9 Exercises
24 Datasim Visualisation Package in Excel: Drivers and Mechanisms
24.1 Introduction and Objectives
24.2 Fundamental Functionality in the Package
24.3 Basic Driver Functionality
24.4 Excel Mechanisms
24.5 Option Values and Sensitivities in Excel
24.6 Finite Difference Method
24.7 Summary and Conclusions
24.8 Exercises and Projects
25 Motivating COM and Emulation in C++
25.1 Introduction and Objectives
25.2 A Short History of COM
25.3 An Introduction to Multiple Inheritance (MI)
25.4 Interfaces and Multiple Inheritance
25.5 Virtual Function Tables
25.6 Summary
26 COM Fundamentals
26.1 Introduction and Objectives
26.2 Interfaces in COM
26.3 The IUnknown Interface
26.4 Using IUnknown
26.4.1 Testing the Interface
26.5 Defining New Versions of Components
26.6 Summary
References
Index
Introduction to C++ for Financial Engineers An object-oriented approach Daniel J. Duffy
Introduction to C++ for Financial Engineers
For other titles in the Wiley Finance Series please see www.wiley.com/finance
Introduction to C++ for Financial Engineers An object-oriented approach Daniel J. Duffy
Copyright C 2006 Daniel J Duffy Published by John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England Telephone (+44) 1243 779777 Email (for orders and customer service enquiries): cs-books@wiley.co.uk Visit our Home Page on 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, scanning or otherwise, except under the terms of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London W1T 4LP, UK, without the permission in writing of the Publisher. Requests to the Publisher should be addressed to the Permissions Department, John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England, or emailed to permreq@wiley.co.uk, or faxed to (+44) 1243 770620. 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. Other Wiley Editorial Offices John Wiley & Sons Inc., 111 River Street, Hoboken, NJ 07030, USA Jossey-Bass, 989 Market Street, San Francisco, CA 94103-1741, USA Wiley-VCH Verlag GmbH, Boschstr. 12, D-69469 Weinheim, Germany John Wiley & Sons Australia Ltd, 42 McDougall Street, Milton, Queensland 4064, Australia John Wiley & Sons (Asia) Pte Ltd, 2 Clementi Loop #02-01, Jin Xing Distripark, Singapore 129809 John Wiley & Sons Canada Ltd, 6045 Freemont Blvd, Mississauga, ONT, L5R 4J3, Canada Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Cataloging-in-Publication Data Duffy, Daniel J. Introduction to C++ for financial engineers : an object-oriented approach / Daniel J Duffy. p. cm.—(Wiley finance series) Includes bibliographical references and index. ISBN-13: 978-0-470-01538-4 (cloth: alk. paper) ISBN-10: 0-470-01538-1 (cloth : alk. paper) 1. Financial engineering—Computer programs. language) I. Title. HG176.7.D843 2006 005.13 3024332—dc22 2. C++ (Computer program 2006020622 British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library ISBN 13 978-0-470-01538-4 (HB) ISBN 10 0-470-01538-1 (HB) Typeset in 10/12pt Times by TechBooks, New Delhi, India Printed and bound in Great Britain by Antony Rowe Ltd, Chippenham, Wiltshire This book is printed on acid-free paper responsibly manufactured from sustainable forestry in which at least two trees are planted for each one used for paper production.
Contents 0 Goals of this Book and Global Overview 0.1 What is this book? 0.2 Why has this book been written? 0.3 For whom is this book intended? 0.4 Why should I read this book? 0.5 The structure of this book 0.6 What this book does not cover 0.7 More information and support PART I C++ ESSENTIAL SKILLS 1 Introduction to C++ and Quantitative Finance 1.1 Introduction and objectives 1.2 A short history of C++ 1.3 C++, a multi-paradigm language 1.3.1 Object-oriented paradigm 1.3.2 Generic programming 1.3.3 Procedural, modular and functional programming 1.4 C++ and quantitative finance: what’s the relationship? 1.5 What is software quality? 1.6 Summary and conclusions 1.7 Exercises 2 The Mechanics of C++: from Source Code to a Running Program 2.1 Introduction and objectives 2.2 The compilation process 2.3 Header files and source files 2.4 Creating classes and using their objects 2.5 Template classes and template functions 2.6 Kinds of errors 2.6.1 Compiler errors 2.6.2 Linker errors 2.6.3 Run-time errors 2.7 The struct concept 1 1 1 2 2 2 2 3 5 7 7 7 8 8 10 11 11 11 13 14 15 15 15 16 19 22 25 25 26 26 27
分享到:
收藏