Skip to content
All library documents

Modeling Quantitative Finance Functions with C++ Function Objects

Article QuantStart

Summary

The article introduces ways to represent mathematical functions in C++, using quantitative finance examples such as option payoffs, differential equation coefficients, and matrices. It compares function pointers with function objects, which let class instances be invoked like functions by overloading the call operator. A small example uses pointers to select addition or multiplication at runtime, then replaces that approach with an inheritance hierarchy of callable classes.

Function objects can hold state in their instances, which can help when a calculation needs to retain information or support multiple configurations. The article also notes tradeoffs: function pointers are simple but have limitations around state, templates, adapting argument types, and compiler inlining. The example uses virtual dispatch and manual allocation, so it illustrates the concept rather than establishing that every functor design is faster or preferable. The article is an introduction and points readers toward later coverage of STL function objects and newer C++ features.

Key ideas

  • Function pointers let code choose a function to execute at runtime.
  • Function objects make class instances callable by overloading the call operator.
  • Function objects can store state separately in each instance.
  • Function pointers can be awkward to adapt, combine with templates, or use with shared state.
  • The best way to represent a function depends on efficiency, reuse, and maintainability needs.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.