Introduction to C++ for Financial Engineers - Daniel J. Duffy - E-Book

Introduction to C++ for Financial Engineers E-Book

Daniel J. Duffy

0,0
79,99 €

oder
-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

This book introduces the reader to the C++ programming language and how to use it to write applications in quantitative finance (QF) and related areas. No previous knowledge of C or C++ is required -- experience with VBA, Matlab or other programming language is sufficient. The book adopts an incremental approach; starting from basic principles then moving on to advanced complex techniques and then to real-life applications in financial engineering. There are five major parts in the book:

  • C++ fundamentals and object-oriented thinking in QF
  • Advanced object-oriented features such as inheritance and polymorphism
  • Template programming and the Standard Template Library (STL)
  • An introduction to GOF design patterns and their applications in QF Applications

The kinds of applications include binomial and trinomial methods, Monte Carlo simulation, advanced trees, partial differential equations and finite difference methods.

This book includes a companion website with all source code and many useful C++ classes that you can use in your own applications. Examples, test cases and applications are directly relevant to QF.

This book is the perfect companion to Daniel J. Duffy’s book Financial Instrument Pricing using C++ (Wiley 2004, 0470855096 / 9780470021620)

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 539

Veröffentlichungsjahr: 2013

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Contents

Cover

Half Title page

Title page

Copyright page

Chapter 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

Chapter 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.4 C++ and quantitative finance: what’s the relationship?

1.5 What is software quality?

1.6 Summary and conclusions

1.7 Exercises

Chapter 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.7 The struct concept

2.8 Useful data conversion routines

2.9 Summary and conclusions

2.10 Exercises and projects

Chapter 3: C++ Fundamentals and my First Option Class

3.1 Introduction and objectives

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.7 Other paradigms

3.8 Summary and conclusions

3.9 Questions, exercises and projects

Chapter 4: Creating Robust Classes

4.1 Introduction and objectives

4.2 Call by reference and call by value

4.3 Constant objects everywhere

4.4 Constructors in detail

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.9 Summary and Conclusions

4.10 Questions, exercises and projects

Chapter 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.5 Using Operator overloading for simple I/O

5.6 Friend functions in general

5.7 Summary and conclusions

5.8 Exercise

Appendix: useful data structures in C++

Chapter 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.4 Small application: working with complex numbers

6.5 Creating an array class

6.6 Summary and conclusions

6.7 Exercises

6.8 Review questions and comments

Chapter 7: Functions, Namespaces and Introduction to Inheritance

7.1 Introduction and objectives

7.2 Functions and function pointers

7.3 An introduction to namespaces in C++

7.4 An introduction to the inheritance mechanism in C++

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

Chapter 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.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.8 Two-factor payoff functions and classes

8.9 Conclusions and summary

8.10 Exercises and projects

Chapter 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.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.9 Conclusions and summary

9.10 Exercises and research

Chapter 10: An Introduction to C++ Templates

10.1 Introduction and objectives

10.2 My first template class

10.3 Template functions

10.4 Consolidation: understanding templates

10.5 Summary and conclusions

10.6 Exercises and projects

Part II: Data Structures, Templates and Patterns

Chapter 11: Introduction to Generic Data Structures and Standard Template Library (STL)

11.1 Introduction and objectives

11.2 Complexity analysis

11.3 An introduction to data structures

11.4 Algorithms

11.5 Navigation in data structures: iterators in STL

11.6 STL by example: my first example

11.7 Conclusions and summary

11.8 Exercises and projects

Chapter 12: Creating Simpler Interfaces to STL for QF Applications

12.1 Introduction and objectives

12.2 Maps and dictionaries

12.3 Applications of maps

12.4 User-friendly 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

Chapter 13: Data Structures for Financial Engineering Applications

13.1 Introduction and objectives

13.2 The property pattern

13.3 Property sets

13.4 Property sets and data modelling for quantitative finance

13.5 Lattice structures

13.6 Conclusions and summary

13.7 Exercises and projects

Chapter 14: An Introduction to Design Patterns

14.1 Introduction and objectives

14.2 The software lifecycle

14.3 Documentation issues

14.4 An Introduction to design 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

Chapter 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.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

Chapter 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.5 Finite difference schemes

16.6 Test cases and presentation in excel

16.7 Summary

16.8 Exercises and projects

Chapter 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.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

Chapter 18: Useful C++ Classes for Numerical Analysis Applications in Finance

18.1 Introduction and objectives

18.2 Solving tridiagonal systems

18.3 An introduction to interpolation

18.4 Summary and conclusions

Chapter 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.7 Approximating exponential functions

19.8 Summary and conclusions

19.9 Exercises

Chapter 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.4 The Monte Carlo method in quantitative finance

20.5 Software architecture for the Monte Carlo method

20.6 Examples and test cases

20.7 Summary and conclusions

20.8 Appendix: comparing Monte Carlo with other numerical methods

20.9 Exercises and projects

Chapter 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.8 Summary and conclusions

Part IV: Background Information

Chapter 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

Chapter 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

Chapter 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

Chapter 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

Chapter 26: COM Fundamentals

26.1 Introduction and objectives

26.2 Interfaces in COM

26.3 The IUnknown interface

26.4 Using IUnknown

26.5 Defining new versions of components

26.6 Summary

References

Index

Introduction to C++ for Financial Engineers

For other titles in the Wiley Finance Series please see www.wiley.com/finance

© 2006 Daniel J Duffy Published by 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.

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

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. 2. C++ (Computer program language) I. Title. HG176.7.D843 2006 005.13_3024332—dc22

2006020622

A catalogue record for this book is available from the British Library.

ISBN 978-0-470-01538-4 (HB)

Chapter 0

Goals of this Book and Global Overview

0.1 WHAT IS THIS BOOK?

The goal of this book is to introduce the reader to the C++ programming language and its applications to the field of Quantitative Finance. It is a self-contained introduction to the syntax of C++ in combination with its applications to current topics of interest. In particular, we develop libraries, frameworks and applications for a variety of derivatives models using numerical methods such as binomial and trinomial trees, finite difference methods (FDM) and the Monte Carlo (MC) method.

The book consists of three major parts. The first part concentrates on essential C++ syntax that must be learned before proceeding. The second part introduces generic programming and design pattern techniques and we show how to create libraries and data structures that we use in part three that deals with full applications. We also have written a number of chapters on topics related to the current book, for example a review of the C language, interfacing with Excel and an introduction to the Component Object Model (COM).

This book is a thorough introduction to C++ and how to use it to write non-trivial and robust applications in Quantitative Finance. Some special features of the book are:

A full discussion of C++ syntax (as described in Stroustrup, 1997)

Advanced topics in C++: memory management, exceptions, templates and RTTI

An introduction to data structures and Complexity Analysis

The Standard Template Library (STL) and its applications to Quantitative Finance

Introduction to Design Patterns and integration into Quantitative Finance applications

Creating real applications for derivative pricing

Working

source code for all chapters and applications

Exercises for every chapter

After having read this book, studied the code and done the exercises you will be in a position to appreciate how to use C++ for Quantitative Finance.

0.2 WHY HAS THIS BOOK BEEN WRITTEN?

We have written this book for a number of reasons. First, in our opinion there are very few books on C++ that teach the language and apply it to interesting and non-trivial problems in Quantitative Finance. This book assumes no knowledge of C++ nor do we assume that the reader is conversant with the C programming language. The first ten chapters of the book introduce the major syntax elements that you will need in order to write C++ applications.

The second reason was to show how to apply C++ to writing flexible and robust applications using an appropriate combination of the object, generic and functional programming models. Furthermore, we apply design patterns and established frameworks to help create extendible applications.

Finally, seeing that C++ is an important language in the financial world we have included exercises, questions and projects at the end of each chapter. We advise the reader to answer these questions and implement the exercises and projects because the best way to learn C++ is by doing it. It is our feeling (and hope) that you will then be able to face job interviews with confidence.

0.3 FOR WHOM IS THIS BOOK INTENDED?

We have written this book for quantitative analysts, designers and other professionals who are involved in developing front office and trading systems. The book is structured in such a way that both novice and experienced developers can use it to write applications in Quantitative Finance.

The book is also suitable for university students in finance, mathematics and other disciplines where C++ is used as the language for computation.

0.4 WHY SHOULD I READ THIS BOOK?

This is the first book (in our opinion) that attempts to give a complete overview of C++ and some of its applications to Quantitative Finance. We employ modern design and programming techniques to create flexible and robust software. Finally, we provide the reader with working source code in this book.

0.5 THE STRUCTURE OF THIS BOOK

The book is divided into four major sections with each section devoted to one major focus of attention. The sections are:

Part I: C++ Essential SkillsPart II: Data Structures, Templates and PatternsPart III: Quantitative Finance ApplicationsPart IV: Background Information

Each part represents a level of C++ expertise. If you learn Part I you will receive a green belt, completing Part II entitles you to brown belt grade and if you learn the contents of Part III you may then call yourself a black belt.

An overview of the contents of this book is given in Chapter 21.

I would like to thank Dr Joerg Kienitz for his willingness to write a chapter in this book on the Monte Carlo method.

0.6 WHAT THIS BOOK DOES NOT COVER

This book is about C++ syntax and its applications to Quantitative Finance. It uses a number of concepts and techniques that are discussed elsewhere in more detail. Thus, this book is not:

an introduction to Quantitative Finance (see Hull, 2006)

an introduction to numerical methods (see Duffy, 2006)

advanced C++ programming and Excel AddIn interfacing (see Duffy, 2004)

The source code on the CD is Datasim copyrighted and you may use it for your own applications provided you keep the copyright notice in the source. It may not be sold on to third parties.

0.7 MORE INFORMATION AND SUPPORT

We will continue to support this book (as well as my other books) on the web sites www.datasim.nl and www.datasim-component.com. We also give both in-company and courses in this area.

The author can be contacted at [email protected]. I welcome your feedback and suggestions for improvement.

Good luck with C++ and Finance.

Part I

C++ Essential Skills

Chapter 1

Introduction to C++ and Quantitative Finance

1.1 INTRODUCTION AND OBJECTIVES

In this chapter we give an overview of the C++ programming language, its relationship with Quantitative Finance (QF) and why C++ is suitable for complex applications in this domain. In particular, we discuss the various programming paradigms and how each paradigm is suited to software projects in QF. Furthermore, we shall describe how these paradigms can be dovetailed to help us build efficient and robust code. Last, but not least, our objective is to create software that is also easy to understand and to maintain. This is an extremely important requirement because a large C++ application consisting of a network of tightly coupled objects can be difficult to maintain at best, and a nightmare at worst. In this day and age the focus is on developing flexible frameworks that can be easily and quickly customised to changing requirements in the market place. To this end, we are convinced that C++ can realise these requirements if and only if we design our software systems in a correct and proper way.

You can skip this chapter if you wish to start as soon as possible on this C++ journey. Then you should go immediately to chapter two. Before doing so, however, we would strongly advise you to read section 1.3 (Programming Paradigms). This book complements my book on C++ for financial instrument pricing (Duffy, 2004) because the latter book assumes previous C++ knowledge and the current book takes a more leisurely pace by discussing each topic in detail.

If we compare this book to an opera, then this chapter would correspond to the overture. It sets the tone by providing some background information on C++ and its relevance and applicability to Quantitative Finance.

1.2 A SHORT HISTORY OF C++

The object-oriented way of thinking and programming (we call this a paradigm) is almost fifty years old and it has its origins in the programming language Simula that was developed in Norway. Simula was the first language to support the concept of a class as we know it in its current form.

C++ has its origins in the early 1980’s when its inventor, Dr Bjarne Stroustrup (Stroustrup, 1997) was working at AT&T. The original name for the language was ‘C with classes’ because the language was developed as an object-oriented extension to the programming language C while still remaining compatible with it. This very fact may be a reason why C++ has weathered the storm: the legacy C code that organisations maintained could be upgraded to C++. C++ is compatible with C and was called a ‘better C’ in those early days.

The late 1980’s can be seen as the period when C++ came out of the laboratories and began to manifest itself in mainstream applications. The first C++ compiler (actually, precompiler because C++ code was compiled to C code) was from a company called Glockenspiel in Dublin in 1988 and it was in this period that the current author started to work with C++.

The early 1990’s saw a remarkable growth in interest in the object-oriented (OO) paradigm in general and in C++ in particular. As with many new technologies promises were made that were not met. For example, it was believed in some circles that OO would solve all software ails and that a new industry would emerge in which application builders would purchase reusable class libraries from companies that could be described as ‘class library builders’. The most important applications in this period were in the following domains: simulation (Computer Aided Design (CAD), Computer Graphics), telecommunications and real-time applications (for example, medical devices and process control). It was during this period that the current author worked on an early version of a pricing and risk management system in C++.

At the moment of writing we can conclude that the object-oriented paradigm is (justifiably) accepted as a necessary precondition for success in software development. However, it is not sufficient in the sense that blind adherence to it will not automatically lead to good results. First, there are other software paradigms that complement and even compete with the object-oriented paradigm and second the paradigm can be taken to extremes, as we have seen in the past. We discuss these problems and risks in this chapter and we provide some guidelines on how to turn our object-oriented projects into success stories.

1.3 C++, A MULTI-PARADIGM LANGUAGE

One of the features of C++ is that it supports many kinds of programming paradigms, unlike some languages that are ‘pure’ object-oriented languages (in the sense that every piece of software must be an object or a class). Instead, we can write applications that are a mixture of different programming styles. Whether this is a wise thing to do is debatable but that is not the issue at the moment. In general, the author does not believe that a single paradigm is flexible enough to encompass every possible kind of application and in general some parts of an application can be written in an object-oriented fashion while other parts can and should be written using a modular approach, reminiscent of Fortran, C and Cobol.

1.3.1 Object-oriented paradigm

This paradigm is based on the concept of a class. Classes have their origins in philosophy, logic and cognitive psychology (Eysenck and Keane, 2000). In particular, the theory of concepts has been an important influence on the development of the object paradigm. There are a number of theories, one of which is the defining attribute view. This view was developed and elaborated by the German logician Frege (Frege, 1952). Frege maintained that a concept can be characterised by a set of defining attributes or semantic features. He distinguishes between a concept’s intension and extension. The intension of a concept consists of the set of attributes that determine what it is to be a member of the concept. This idea is similar to a class in class-based object-oriented languages. The extension of a concept is the set of entities that are members of the concept. This idea corresponds to class instances or objects. Some features of the defining attribute view are:

The meaning of a concept is captured by its defining attributes

Attributes are atomic building blocks for concepts

Attributes are necessary and sufficient for defining members of a concept

There is no doubt about whether an entity is in the concept; there are clear-cut boundaries between members and non-members of the concept

All members of the concept are equally representative of the concept; we cannot say that one member is more typical of the concept than another member

When concepts are organised in a hierarchy the defining attributes of the more specific concept (for example, a sparrow) include all the attributes of the superordinate concept (in this case, bird).

These features are implemented in many class-based object-oriented languages such as C++, Java and C#. In this case we first define a class consisting of data and functions and we then create objects or so-called instances of the class by initialising the data in the class. Looking back in hindsight (which is always easy), the author concludes that these assumptions are too restrictive for certain types of applications. There are other object-oriented languages where there is no class concept. Instead, if we wish to create an object we must clone or copy it from an existing prototypical object. The Self language is one example of a so-called classless object-oriented language.

Let us take a simple example. In this case we wish to model one-factor plain options (in other words we can only exercise at the maturity date T). An option can be a call option or a put option. When we model this as a class we must discover its attributes and the messages to which instances (objects) of the class respond to. The attributes are:

The risk-free interest rate: r

The volatility of the relative price change: σ

The strike price: K

The time to expiration (in years): T

The cost-of-carry: b

These attributes are just names and when we create instances of the class we must assign values to them, for example (Haug, 1998):

We thus see that the object is concrete while its corresponding class is abstract. Having defined the object’s data we may speculate on the kinds of information we wish to extract from the object. Since this is a context-sensitive question we would expect different answers from various stakeholder groups such as:

Traders

Quantitative analysts

Risk managers

IT personnel

Each group has its own requirements and features that they would like to have. For example, a common set of requirements might be:

Calculate the option price

Calculate an option’s sensitivities (for hedging applications)

The ability to support constant, time-dependent and stochastic volatility models

Export option-related information to a spreadsheet, for example Excel

These features will be implemented by one or more so-called member functions. In order to reduce the scope we concentrate on the pricing and hedging functionality. For example, the price for a one-factor plain call or put option is known analytically:

In this code we use the variable U to denote the underlying variable.

1.3.2 Generic programming

This is a paradigm that can be a competitor of the object-oriented paradigm and it can also be used in conjunction with the latter paradigm.

When we design a software entity using the generic paradigm we try to stop thinking about hard-wired data types and so on. We then design the software using generic underlying types. When we wish to work with specific data types we instantiate or clone the software entity by replacing the generic types by these specific types. The compiler takes care of these replacement issues and it checks that the specific data types satisfy the interface requirements demanded by the generic type.

Let us take a simple example. Suppose that we wish to define a function that calculates the maximum of two numbers. In C++ we realise this using a template function:

template <class Numeric>         Numeric Max(const Numeric& x, const Numeric& y);

This template function in C++ accepts two parameters of a generic type and then calculates their maximum. The code for the function is easy to read if you have programmed in any high-level language:

template <class Numeric> Numeric Max(const Numeric& x, const Numeric& y) {     if (x > y)         return x;     return y; }

The only difference with normal programming practice in this case is that we need to give the compiler a hint that we are working with generic data types and not with specific ones. An example of use is:

Concluding, when we work in this way we write the software once and reuse it many times. We have applied the generic paradigm to quantitative finance applications in Duffy (2004).

1.3.3 Procedural, modular and functional programming

The programming language Fortran (Formula Translation) has been the most successful language of all time for scientific, mathematical and engineering applications. It is ideally suited to problems involving data structures such as vectors and matrices and the corresponding algorithms that use these data structures. Hundreds of libraries have been built to help Fortran programmers, for example:

Numerical linear algebra

Initial value problems

Ordinary and partial differential equations

And many more…

Fortran achieves this level of reusability by the use of subroutines and modules. A module is a function that produces output from input. It is not a member function of a class and hence we do not need to create an object in order to use it. Object-oriented purists may frown on this approach but my answer would be: not everything is, or needs to be an object.

We have applied the modular paradigm to quantitative finance applications in Duffy (2004).

1.4 C++ AND QUANTITATIVE FINANCE: WHAT’S THE RELATIONSHIP?

C++ has become very popular in Quantitative Finance and its importance will grow rather than diminish in the coming years (in my humble opinion). It may not be the most elegant and usable language out there but – all things being equal – it is the most flexible and adaptable language. It is an ISO standard, which means your C++ code will also work in 20 years time!

I could say much more, but for good or bad there is no way we can ignore C++. An important point is that potential employers wish to see employees with C++ experience. Accepting this fact, and the fact that so many people wish to learn the language (and learn it well) I have decided to write this book. I hope that it will help you in your career.

1.5 WHAT IS SOFTWARE QUALITY?

The ISO 9126 standard (see Kitchenham and Pfleeger, 1996) is a description of a set of characteristics that measures the quality of software products. It consists of six orthogonal quality characteristics that describe how good a product is. We discuss them because they are very useful in all phases of the software development lifecycle (in particular, business modelling) and not just in the more solution-dependent stages such as design, coding and maintenance. In fact, many managers think in term of these characteristics, albeit implicitly. Furthermore, each characteristic has several sub-characteristics.

The six characteristics are:

Functionality

Reliability

Usability

Efficiency

Maintainability

Portability

Functionality refers to the capability of a system (in fact, the software that implements the system) to satisfy user needs. These needs may be explicitly stated but they can also be implicit. This characteristic has five sub-characteristics:

Suitability

: this has to do with functions for specified tasks and their appropriateness for their tasks

Accuracy

: this has to do with the problem of producing correct and agreed results or the agreed effect

Interoperability

: this has to do with the ability to interact with other systems. An important precondition is that the systems are predefined

Compliance

: this sub-characteristic refers to whether the system adheres to standards and conventions such as regulations, domain-related standards and the law

Security

: this has to do with the ability of the system to prevent unauthorised access, whether it be deliberate or accidental

Reliability is concerned with how a system maintains a given level of performance over some given period of time. We must also state the conditions under which the system performs

This characteristic has three sub-characteristics:

Maturity

: has to do with the frequency of failure in the system. Most failures are caused by so-called faults

Fault tolerance

: refers to the ability of the system to maintain a specified level of performance. We must specify the duration of time in which that level is to be maintained. Disturbances compromise this level of performance. These disturbances are caused by software faults and bad interfaces, for example

Recoverability

: this refers to the capability to re-establish previous levels of performance. For example, we could consider the time and effort it takes to recover information and data after a system crash

Usability refers to the effort that is needed in order to ‘use’ an application or system. Of course, there are many kinds of users of a system and each one has a definition of usability. For example, there are both direct and indirect users of the system. It is important to define what developers, managers and users of the software mean by usability.

This characteristic has three sub-characteristics:

Understandability

: the effort needed to recognize logical concepts and their applicability

Learnability

: the effort needed to learn the application, for example how often the user manual is consulted

Operability

: the effort for operation and operational control, for example backup and file management

Efficiency refers to the level of performance and the amount of resources needed to achieve the performance.

This characteristic has two sub-characteristics:

Time behaviour

: this is related to response and processing times

Resource behaviour

: has to do with the amount of resources needed to perform functions. This sub-characteristic is also concerned with how long the resources are held while performing the functions

Maintainability refers to the effort needed to make specified modifications. These modifications may include corrections, improvements or adaptation. In general, modifications are caused by changes in the environment and by changes to requirements and functionality.

This characteristic has four sub-characteristics:

Analysability

: the effort needed for diagnosis or deficiency detection. We wish to detect the causes of failure in this case and to identify parts of the system requiring modification

Changeability

: this is related to the effort that is needed for modification, fault removal or environmental change

Stability

: the risk of unexpected effect of modification. This is the sub-characteristic that gives managers and project leaders nightmares. Traditional object-oriented software projects tend to suffer from this problem because of their inherent bottom-up approach, aggravated by overuse of the C++ inheritance mechanism. The end-result is a tightly coupled set of object networks that

can

(and usually) does lead to huge maintenance problems

Testability

: the effort that is needed to validate the modified software or the effort that is needed to test it

Portability refers to the ability of software in a system to be transferred from one environment to another environment. This includes organisational, hardware and software environments.

This characteristic has four sub-characteristics:

Adaptability

: the opportunity for adaptation of software to different specified environments. This implies that no other actions should be applied or changes made

Installability

: the effort needed to install software in a specified environment

Conformance

: does software adhere to standards or conventions?

Replaceability:

the opportunity and effort of using software in place of other software in the same environment. This sub-characteristic may also include attributes of both installability and adaptability

1.6 SUMMARY AND CONCLUSIONS

In this chapter we have given an overview of a number of programming paradigms and how they are supported in C++. Furthermore, we gave a short history of C++ and its applications during the last 25 years. Finally, we gave an introduction to the ISO 9126 standard that describes the quality of software products. Just like my car or washing machine, we wish to create software applications that are extendible and easy to maintain and of course, fast. We realise the first two requirements by improving design and programming skills while the third requirement can be realised by a clever synergy between software and hardware.

1.7 EXERCISES

1. Which programming language(s) are you using at the moment? In how far does it support the following paradigms: Object oriented programmingGeneric programming (as is seen with C++ templates)Procedural and modular programming
Are there things you would like to do with the language that are not possible?
2. In how far do the following languages support the above three paradigms: Java, VBA, C#, C, Cobol, Fortran, APL, PL/I, Maple, Matlab, Smalltalk, VB.NET?
3. Which ISO 9126 characteristics are important for the following kinds of software projects:
(a) A throwaway prototype application to test if a new pricing model is accurate
(b) A COM Addin (written in C++) that will be used on the trading floor
(c) A large system using the finite difference method that will be updated, extended and improvement over a period of years
4. What are the three most important ISO 9126 characteristics in general in your opinion?

Chapter 2

The Mechanics of C++: from Source Code to a Running Program

Tús maith leath na hoibre (a good start is half the work)

2.1 INTRODUCTION AND OBJECTIVES

In this chapter we introduce the C++ language by defining just enough syntax to allow us to create and run simple programs. We concentrate on the steps that you need to carry out in order to create an executable file. Of course, we need to introduce some C++ syntax so that we are in a position to understand what is being presented. In this chapter both the code and the examples are simple enough to be understood by a reader with some knowledge of programming. In particular, we discuss three major examples:

Problem 1: Procedures for calculating the maximum and minimum of some numbersProblem 2: A simple C++ classProblem 3: A simple template class and template function

The objective is thus to understand the full process of creating C++ code, compiling it and linking with the other code and libraries in the system. Only when all compiler and linker errors have been resolved can we run our program.

The main objectives in this chapter are:

Discuss what is actually needed when creating a C++ program

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!