Learning Modern C++ for Finance: Foundations for Quantitative Programming

Learning Modern C++ for Finance: Foundations for Quantitative Programming

Learning Modern C++ for Finance: Foundations for Quantitative Programming
Автор: Hanson Daniel
Дата выхода: 2025
Издательство: O’Reilly Media, Inc.
Количество страниц: 431
Размер файла: 1,8 МБ
Тип файла: PDF
Добавил: it-books

Copyright....3

Table of Contents....6

Preface....12

Navigating This Book....14

Conventions Used in This Book....17

Using Code Examples....18

OReilly Online Learning....19

How to Contact Us....19

Acknowledgments....19

Chapter 1. An Overview of C....22

C and Quantitative Finance....22

C11: The Modern Era Is Born....23

Open Source Mathematical Libraries....25

Some Myths about C....25

Compiled Versus Interpreted Code....25

The Components of C....26

C Language Features....26

The C Standard Library....27

Some New Language Features Since C11....30

The auto Keyword....31

Range-Based for Loops....32

The using Keyword....33

Uniform Initialization....34

Formatting Output....35

Class Template Argument Deduction....36

Enumerated Constants and Scoped Enumerations....37

Lambda Expressions....41

Mathematical Operators, Functions, and Constants in C....44

Standard Arithmetic Operators....44

Mathematical Functions in the Standard Library....45

Mathematical Special Functions....48

Standard Library Mathematical Constants....48

Naming Conventions....50

Summary....52

Further Resources....53

Chapter 2. Writing User-Defined Classes with Modern C Features....54

A Black-Scholes Class....55

Representing the Payoff....56

Writing the Class Declaration....56

Writing the Class Implementation....57

Using a Functor for Root Finding: Implied Volatility....60

Move Semantics and Special Member Functions....64

Data Members and Performance Considerations....64

An Introduction to Move Semantics....66

Initialization of Constructor Arguments with std::move(.)....69

Anonymous Temporary Objects and Move Semantics....71

Return Value Optimization....72

Default Constructor....73

Three-Way Comparison Operator (Spaceship Operator)....75

Lambda Expressions and User-Defined Class Members....79

Summary....80

Additional References....81

Chapter 3. Inheritance, Polymorphism, and Smart Pointers....84

Polymorphism....86

Resource Ownership with Raw Pointers....91

Using Clone Methods....95

Creating an Instance of OptionInfo....96

Preventing Shallow Copy....97

Implementing the OptionInfo Destructor....100

Pricing an Option....100

Implementing Copy Operations....102

The (Old) Rule of Three....106

Introducing Smart Pointers....106

Unique Pointers....107

Shared Pointers....109

Managing Resources with Unique Pointers....112

Just Move It....112

Using the Result in a Pricing Model....115

If Copy Operations Are Required....116

Summary....121

Further Resources....122

Chapter 4. The Standard Template Library Part I: Containers and Iterators....124

Templates....125

Using Function Templates....126

Using Class Templates....128

Compiling Template Code....130

STL Containers....131

Sequential Containers....132

Associative Containers....149

STL Iterators....155

Using auto to Reduce Verbosity....158

Using Constant Iterators....158

Iterators or Indices?....158

Iterators on Associative Containers....159

Summary....160

Further Resources....163

Chapter 5. The Standard Template Library Part II: Algorithms and Ranges....164

STL Algorithms....164

A First STL Algorithm Example....165

A First Example with Ranges....169

Some Commonly Used Algorithms....170

Function Objects as Auxiliary Functions....174

Class Member Functions as Auxiliary Functions....174

Locating, Sorting, Searching, Copying, and Moving Elements....175

Numeric Algorithms....182

Range Views, Range Adaptors, and Functional Programming....190

Range Views....191

Chaining for Functional Composition....194

Views, Containers, and Range-Based for Loops....194

Summary....195

Additional References....196

Chapter 6. Random Number Generation and Concurrency....198

Distributional Random Number Generation....199

Introducing Engines and Distributions....199

Generating Random Normal Draws....202

Using Other Distributions....203

Shuffling....205

Monte Carlo Option Pricing....215

A Review of Monte Carlo Option Pricing....215

Generating Random Equity Price Scenarios....217

Calculating the Option Price....219

Pricing Path-Dependent Options....223

Concurrency and Parallelism....229

Parallel Algorithms from the Standard Library....230

Task-Based Concurrency....235

Concluding Remarks on async and future....243

Summary....243

Further Resources....244

Chapter 7. Dates and Fixed Income Securities....246

Representation of a Date....247

Serial Representation....250

Accessor Functions for Year, Month, and Day....251

Checking the Validity of a Date....251

Checking Leap Years and Last Day of the Month....252

Identifying Weekdays and Weekends....253

Adding Years, Months, and Days....254

A Date Class Wrapper....257

Class Declaration....257

Class Implementation....260

Day Count Basis....267

Yield Curves....270

Deriving a Yield Curve from Market Data....270

Discount Factors....273

Calculating Forward Discount Factors....273

Implementing a Yield-Curve Class....274

Implementing a Linearly Interpolated Yield Curve Class....278

A Bond Class....279

Bond Payments and Valuation....280

Designing a Bond Class....285

Implementing the Bond Class....287

A Bond Valuation Example....292

Summary....296

Additional Reference....297

Chapter 8. Linear Algebra....298

Lazy Evaluation and Expression Templates....299

Lazy Evaluation....300

Expression Templates....303

The Eigen Linear Algebra Library....307

Eigen Matrices and Vectors....308

Matrix and Vector Math Operations....312

STL Compatibility....318

Matrix Decompositions and Applications....324

Fund Tracking with Multiple Regression....324

Correlated Random Equity Paths and the Cholesky Decomposition....327

Yield-Curve Dynamics and Principal Component Analysis....331

Future Directions: Linear Algebra in the Standard Library....334

mdspan....335

BLAS Interface....340

Summary....342

Further Resources....342

Chapter 9. The Boost Libraries....344

Mathematical Constants....345

Statistical Distributions....346

Probability Functions....347

Drawdown Example, Revisited....349

Random Number Generation with Boost Distributions....350

MultiArray....352

A Simple Two-Dimensional MultiArray....352

Binomial Lattice Option Pricing....354

Accumulators....367

Max and Min Example....367

Mean and Variance....369

Rolling Mean and Variance....370

Trading Indicator Examples....371

Summary....376

Further Reading....376

Chapter 10. Modules and Concepts....378

Modules....379

Standard Library Header Units....381

Templates in Modules....382

import Versus include....383

Declarations in Module Interfaces....385

Separating Declarations from Implementation....386

Namespaces....390

Partitions....391

Concepts....391

Defining Concepts....393

Defining Concepts with Multiple Conditions....394

Standard Library Concepts....395

Summary....397

Appendix A. Virtual Default Destructor....398

Appendix B. Object Slicing....402

Appendix C. Implementation of Move Special Member Functions....406

Appendix D. Resolving Conflicts in the Initialization of a vector....410

Appendix E. valarray and Matrix Operations....412

Arithmetic Operators and Math Functions....413

valarray as a Matrix Proxy....415

Index....418

About the Author....428

Colophon....429

This practical book demonstrates why C++ is still one of the dominant production-quality languages for financial applications and systems. Many programmers believe that C++ is too difficult to learn. Author Daniel Hanson demonstrates that this is no longer the case, thanks to modern features added to the C++ Standard beginning in 2011.

Financial programmers will discover how to leverage C++ abstractions that enable safe implementation of financial models. You’ll also explore how popular open source libraries provide additional weapons for attacking mathematical problems. C++ programmers unfamiliar with financial applications also benefit from this handy guide.

  • Learn C++ basics from a modern perspective: syntax, inheritance, polymorphism, composition, STL containers, and algorithms
  • Dive into newer features and abstractions including functional programming using lambdas, task-based concurrency, and smart pointers
  • Implement basic numerical routines in modern C++
  • Understand best practices for writing clean and efficient code

Похожее:

Список отзывов:

Нет отзывов к книге.