Bootstrap for implementing code snippets from Duffy's Financial Instrument Pricing Using C++.
mkdir build && cd buildcmake .. && cmake --build .ctest -V
- CMake >= 3.15
- C++17 compatible compiler
mkdir -p build && cd build
cmake ..
cmake --build .Open this directory in CLion (File > Open) to import the CMake project.
This project bootstraps the code examples from Duffy's Financial Instrument Pricing Using C++. It provides:
-
Core interfaces (
include/sud.hpp):OptionData<T>: a tuple<K, T, r, σ>representing option parameters.ComputedData<T>: a tuple<V, Δ, Γ>representing the computed price and sensitivities.IAlgorithm<T>: a type-safe callable for pricing algorithms.SUD<T,Source,Sink>: a policy-based "System Under Discussion" that wires a source, algorithm, and sink.
-
Demo application (
src/main.cpp): call and put pricing demo usingSUD,Processing,Input, andOutput.
You can implement your own Source/Sink, write any pricing algorithm (e.g. Black‑Scholes), and hook them up via SUD for end-to-end execution.
. ├── CMakeLists.txt # top-level CMake configuration
├── include/
│ ├── sud.hpp # core templates and interfaces
│ └── option_pricing.hpp # domain logic (Black‑Scholes formulas)
├── src/
│ ├── CMakeLists.txt # builds all .cpp files in this folder
│ └── main.cpp # application entry-point (demo runner)
├── tests/
│ ├── CMakeLists.txt # tests build rules
│ └── test_option_pricing.cpp # unit tests for pricing routines
└── README.md # project documentation
Below is a minimal sketch of how to plug in a source, algorithm, and sink:
#include "sud.hpp"
struct MySource {
OptionData<double> getData() { /* read/write input... */ }
};
struct MySink {
void SendData(const ComputedData<double>& x) { /* output data... */ }
void end() { /* cleanup... */ }
};
int main() {
// Black‑Scholes pricing lambda
IAlgorithm<double> blackScholes = [](const OptionData<double>& od, double S) {
double V = /* ... */;
double delta = /* ... */;
double gamma = /* ... */;
return ComputedData<double>{V, delta, gamma};
};
SUD<double, MySource, MySink> app(blackScholes);
app.run(100.0 /* spot price */);
return 0;
}After building (see Building), from the build directory run:
./option_pricingYou should see the call price + sensitivities followed by the put price + sensitivities, for example:
(2.13337,0.372483,0.0420428)
end
(5.84628,-0.372483,0.0420428)
end
After building (see Building), from the build directory run:
ctest -VThis will execute the option_pricing unit tests (normal PDF/CDF checks and basic call/put pricing validations).
For a detailed introduction, see docs/JavaGuide.md.
This project is licensed under the MIT License. Pricing formulas are provided for educational purposes only and should not be used in production without proper validation.