Skip to content

OptionLib is a versatile C++ library for building and managing option portfolios with arbitrary underlying assets, offering robust tools for valuation, risk analysis, and modeling using frameworks like Black-Scholes and Heston.

Notifications You must be signed in to change notification settings

James-Wirth/option-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OptionLib

CMake Build and Test

OptionLib is a C++ library designed for options pricing and financial modelling, with support for various pricing models. This project is a work in progress, with more features planned for future release.

We have so-far implemented support for the following models:

  • Black-Scholes (analytic, Monte-Carlo, binomial)
  • Heston

Installation

Make sure you have a C++20 compatible compiler. Clone the repo and build using CMake:

git clone https://github.com/James-Wirth/OptionLib.git
cd OptionLib
mkdir build && cd build
cmake ..
make

To install the library and the executables, run:

make install

Run the unit tests with:

ctest

Usage

Here is a simple usage that demonstrates setting up a portfolio with a single call option. The Factory:: pattern allows you to make std::shared_ptr objects for clean memory management.

using namespace OptionLib;

// Define the asset and set its key features
double spotPrice = 100.0;
AssetSP asset = Factory::makeSharedAsset("AAPL", spotPrice);
asset->set(Param::volatility, 0.2);     
asset->set(Param::riskFreeRate, 0.05);  

// Create a call option
double strikePrice = 100.0;
double timeToMaturity = 1.0;  // Time to maturity: 1 year
OptionSP callOption = Factory::makeSharedOption(
    asset, 
    strikePrice, 
    timeToMaturity, 
    OptionType::Call
);

// Initialize a Black-Scholes model
ModelSP model = Factory::makeSharedModel<BlackScholes>();

// Build the portfolio and add the option
Portfolio portfolio(model);
portfolio.addOption(callOption);

Greeks Calculation:

Calculate the value of the Greeks for each option in the portfolio. For example, for the $\Delta$,

... = portfolio.greekVector(GreekType::Delta)

Risk Analysis:

Calculate the value at risk (VaR) and the expected shortfall (ES).

... = portfolio.VaR(confidenceLevel, holdingPeriod);
... = portfolio.ExpectedShortfall(confidenceLevel, holdingPeriod);

About

OptionLib is a versatile C++ library for building and managing option portfolios with arbitrary underlying assets, offering robust tools for valuation, risk analysis, and modeling using frameworks like Black-Scholes and Heston.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published