By global pricing library I mean a library
- handling equity, rate etc, hybrid products
- having several models (BS, LV, SV, LSV)
- having several numerical methods (analytic formula, MC, PDE FD/FE)
I never had to design a global pricing library, only had to write isolated MC or PDE FD pricing libraries, with BS, LV and SV mainly, in a purely front office setting, so I was quite free for the modelling and designing. In these cases I always used the following architecture (in the case of a toy MC) :
- a
Product
has a (reference to) aPayOff
- a
PayOff
has aModel
and aComputePayOff
method that computes the payoff on a path generated by the model - a
Model
has aRandomNumberGenerator
and aGenerateMCPath
method that generates an MC path given dates with the given random generator
PayOff
is abstract, as well as Model
and RandomNumberGenerator
, even if I always had issues with avoiding exponential increase of subclasses due to transverse functionality, as I am not a design pattern (bridge ?) expert.
So that PayOff
has a lot of "non-immutable" information. For instance if my RandomNumberGenerator
is a Sobol, it may have a member that changes after generating random number, so that after a pricing, PayOff has a information that has changed. I never cared about that.
Now, I have the task of laying out a poc for a global pricing library, with the constraint that Product
and PayOff
must not change (they going to be (de)serialized). I could of course, with a lot of contorsions, continue to do as in the previous toy-example, but it would be wrong.
Still, after thinking, some things do not change : I indeed want to have three categories of "objects" :
- products (or payoffs to make it simple)
- models
- numerical methods
and these categories may intersect, for instance :
- the intersection of european payoffs, BS model and closed formulae (a special kind of numerical method) yields the BS formula
- the intersection of european payoffs and Heston model yields as numerical methods either closed formulas, PDE FD2D or MC
etc. In fact, the library needs to process a given payoff under a given model, using a given numerical method, keeping track of the fact that it cannot price everything in any model and with any numerical method ...
Is there a classic way to design this ? As I do not intend to necessarily reinvent the wheel, I looked at QuantLib and Strata so far, but they both have "non-immutable" "payoffs".