I'm using quantlib via the quantlib-python or open-source-risk-engine both on pypi. The question relates whether it's possible to extend QuantLib term structure base classes in python rather than C++. My guess is you can't, but wanted to double check.
I've hit a limitation whereby the available BlackVarianceSurface is unable to take different strikes for different tenors when building a surface - my FX market instruments are quotes in moneyness, not absolutely strikes.
I've found ORE's extension - FxBlackVannaVolgaVolatilitySurface, which is very close to what I want, but only handles market quotes at a single delta (eg only 25-delta by default).
So, in order to add more market deltas, I was hoping to extend the parent class - BlackVolatilityTermStructure. However, the python bindings only seem to expose its parent BlackVolTermStructure - the idea being to write a new FX Surface implementation, following the C++ for FxBlackVannaVolgaVolatilitySurface as a rough guide, but to do it in python.
I'm not sure extending BlackVolTermStructure in python is the right thing to do? My test class extending BlackVolTermStructure instantiates OK, but when I try to create a BlackVolTermStructureHandle from the instance it fails (see below). It looks to me like QuantLib is expecting a shared pointer to the class which I'm assuming I can't provide to a python-implemented child class (error below)?
My questions are:
- Is it possible to create your own extended volatility term structures using only python, or am I should I write it in C++ and build python bindings to my C++ extension?
- Given it's a small extension is there a way to bundle this as a separate library I build in C++ rather than forking and changing QuantLib itself? Any guides on this?
- On the off-chance if anyone has managed to use FxBlackVannaVolgaVolatilitySurface from ORE in python with (for example) 10 and 25 market deltas on the same surface that would remove the need for me to extend!
- Perhaps there's a better approach to avoid extending that I'm missing, given what I'm trying to build is quite typical for FX Option pricing - any advice gladly received. I'm not against implementing my extension in C++, but would prefer to avoid this complication if possible.
self = <ORE.ORE.BlackVolTermStructureHandle; >, args = (<lib.opcalc.volatility.vol_surface.CustomVolatilitySurface; >,)
def __init__(self, *args):
> _ORE.BlackVolTermStructureHandle_swiginit(self, _ORE.new_BlackVolTermStructureHandle(*args))
E TypeError: Wrong number or type of arguments for overloaded function 'new_BlackVolTermStructureHandle'.
E Possible C/C++ prototypes are:
E Handle< BlackVolTermStructure >::Handle(ext::shared_ptr< BlackVolTermStructure > const &)
E Handle< BlackVolTermStructure >::Handle()