Chapter 3. Inheritance, Polymorphism, and Smart Pointers

Historically, C++ has been a popular language in the finance industry because it supports object-oriented programming, which leverages relationships and interactions among objects. Dependencies between objects are broadly divided into two categories: composition (a “has-a” relationship) and inheritance (an “is-a” relationship). Here are two examples related to financial programming:

  • An options contract has a payoff.

  • A call payoff is a type of payoff.

More financial examples of has-a relationships (composition) include the following:

  • A Treasury bill has a day count basis.

  • A coupon-paying bond has a first coupon date, penultimate coupon date, and maturity date.

And as for additional is-a relationships (inheritance), the financial world has cases such as these:

  • Each of Actual/365, Actual/360, and 30/360 is a day count basis.

  • A mortgage pass-through security, a collateralized mortgage obligation (CMO), an interest-only strip, or a principal-only strip is a mortgage-backed security.

Composition was touched upon in Chapter 2, where an enclosing object was composed with a subobject member. In addition, you saw how move semantics, introduced in C++11, allows the enclosing object to have exclusive control over this member without incurring the cost of object copy. Using std::move just in the initialization of the data vector in the sketch of the PatternAnalytics example resulted in over a tenfold increase in speed. ...

Get Learning Modern C++ for Finance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.