Sample Models

Prototype to Production

Posted by steve on January 21, 2021

Cephei has been designed for extensibility and specialisation:

  • Extensibility is achieved by loading any assembly ending in Model.dll in the same directory as the Cephei.xll or Cephei64.xll folder that contains Excel DNA functions

  • Specialisation is achieved by generating source-code from the Excel model that includes the functions necessary to be used using the extensibility framework. This blog walks through the process of modelling in Excel, generating code, and re-using the generated code.

Sample Models

Setup

Please register and then download either the Cephei 32-bit or Cephei 64-bit addin from cepheis.com. The download contains a single XLL (Excel Link Library) file that can be opened directly in Excel without admin installation. To avoid prompting when opened, it should be saved to an Excel trusted addin folder.

Bond1

Bond1 is a scratchpad sheet that replicates the data and calculations of Quantlib; using examples for Zero, Fixed and Floating Rate bonds.

The sheet demonstrates that arbitrarily complex models can be constructed in Excel using Cephei, and provides the template for the samples below.

Global parameters

Globals is the copy & paste of parameters for settlement days and other global values from Bond1. Selecting the menu ribbon command Cephei/Generate saves the spreadsheet as code to Globals.fs.

The zip file contains the generated source-code and compiled Cephei.Model.dll that is used in the following examples. Any compiled assembly that ends with Model.dll that is in the same directory as Cephei.xll will file will be loaded at start-up.

Bond Pricer

Bond Pricer is a copy & paste from Bond1 of the cells needed to build a Quantlib pricing engine from Libor rates and bond futures for a yield curves.. All global references have been replaced with references to __Global functions generated in the last step.

Selecting the menu ribbon command Cephei/Generate saves the spreadsheet as source code to BondPricer.fs (included in the zip file). The generated source includes the line let _Globals = new GlobalsModel (_settlementDate) the spreadsheet uses the generated globals functions and with source code references automatically generated

Bond1_Fixed

Bond1_Fixed is a copy & paste from Bond1, with references to pricing engine replace with call to =+__BondPricer(A13,B3) generated in the step above and globals generated in the step before that.

This is the final spreadsheet used to demonstrate code generation.

Bond_Fixed_Portfolio

Bond_Fixed_Portfolio usea the Fixed Rate Model created in the step above and applies it to a portfolio of 100 bonds, with calculation of {NPV, Clean Price, Dirty Price, Yield} for each the bonds and presentation within a graph and trend condition formatting.

The sample performs hundreds of calculations per second, but does not stop interactive editing in the same way that market-data subscription does not stop editing.

Conclusion

The samples demonstrate that complex models can be prototyped in Excel, generated to source code, re-used in other models and deployed to servers for real-time pricing and risk management. The core Cell framework and Quantlib integration are open-source, and can be used directly or used as a proof-of-concept for integration with in-house financial libraries.

Cephei is most useful for rapid product structuring with short concept to implementation cycle, but also for financial digital twins to manage exposure for larger organisations