Cephei Swap

Example model

Posted by steve on February 25, 2021

Cephei is an addin framework that allows models developed in Excel to be exported to code, that can be used either to provide tailored recipes (that hide Quant Library details and curve building/bootstrapping) or deployed to a server for real-time pricing or risk.

Quantlib

As a proof-of-concept, the open source Quantlib library has been included to demonstrate how the framework can be used. Quantlib was originally developed for pricing of Fixed Income produces (Bonds, Swaps, Options), but has been extended for a wide verity of instruments.

Quantlib demonstrates that any financial library can be integrated with Cephei, because it was designed for real-time pricing where separate calculations for (NPV, Yield, Cash, Clean/Dirty, etc) prices are avoided, using cached data. The design is not conducive to parallel calculation, but locking enables it to be used in most cases.

Swap sample

The swap sample is a conversion of the standard Quantlib Swap sample, that calculates (NPV, Fair Spread, Fair Rate) for a five-year bond with spot prices (using historical reference data) and forward starting. The swaps priced using curves for:

  • Deposit rates on the short end, and exchange traded swap rates on the long end.
  • Deposit and future rates on the short end, with and exchange traded swap rates on the long end.
  • Deposits and Forward Rate Agreements (FRA) on the short end, and exchange traded swap rates on the long end.

Development of the sheet, highlighted an issue with Quantlib that iterative bootstrapping can result in deadlock. Without the option to completely refactor the code, MayLock has been added, to prevent the error causing the process to hang. MayLock is a workaround to prevent deadlock, and not recommended as an alternative to refactoring. The cell framework has been changed to retry the Lock Recursion problem this causes, but is far from ideal.

Changes to the evaluation date exacerbate the locking contention problem

File Notes
Cephei.xll Addin to provide Cephei and functions to 32-bit version of Excel
Cephei64.xll Addin to provide Cephei and functions to 64-bit version of Excel
Swap.xlsx Sample spreadsheet for a swap model
Swap.fs Generated code from the Swap.xlsx spreadsheet