QuantLib
QuantLib copied to clipboard
Bachelier calculator
Hi, I was after a simple Bachelier (aka Normal, aka Black Normal, aka Bachelier Black) pricing and greek formula implemention, and I noticed that QuantLib seems to only have a BlackCalculator implementation under ql/instruments/payoffs.hpp and no normal pricing. There is a normal Cap/Floor pricer as well as a normal Swaption pricer but no general formula has been implemented unless I'm missing something. I'm happy to add an enhancement myself if needed.
Thanks
Thanks for posting! It might take a while before we look at your issue, so don't worry if there seems to be no feedback. We'll get to it.
Bachelier formula is available in ql/pricingengines/blackformula.hpp, even though it should probably be renamed more sensibly.
The Black calculator reimplements the formulas in the file above so that it avoids duplicated calculations for value and Greeks, and also covers different kinds of payoff. I'm not sure if that's needed for Bachelier...
Also, I'm not sure of the current interface, since it takes arguments (forward, stdDev) which are not those that one would reasonably expect (spot, volatility). We should probably rethink that part of the code. If you have any thoughts, they're welcome.
Hi, It's interesting - putting Bachelier into the file with the Black formula implementation is of course a counterintuitive choice but it's not a big deal. The fact that it takes stddev instead of vol is not a terribly big deal either. But as far as I can tell, the class BlackCalculator declared in the file ql/pricingengines/blackcalculator.hpp does not actually use that implementation. Instead it re-implements the Black formula without its Bachelier counterpart. And when it's called from Python via ql.BlackCalculator(), I still don't see any way to call Bachelier. What do you think the best solution is? Refactor BlackCalculator in ql/pricingengines/blackcalculator.hpp so that it uses ql/pricingengines/blackformula.hpp (so that then Bachelier is easy to access) or create a Bachelier Calculator alongside Black Calculator (with its own implementation, like it's done for Black now)?
The calculator reimplements the formulas on purpose, because usually it will be asked for value, delta, gamma etc and using the formulas would result in repeated calculations. I wouldn't refactor that.
Question: what are you looking for in a Bachelier calculator that you can't already get from the formulas?
I'm looking for a way to calculate a simple Bachelier price or greeks from Python
Hi @kp9991-git,
you could have a look one of the examples on Quantlib-SWIG, the library wrapping Quantlib to other languages including python, there is one involving the ql.BlackCapFloorEngine for which you can swap in ql.BachelierCapFloorEngine:
https://github.com/lballabio/QuantLib-SWIG/blob/master/Python/examples/capsfloors.py
The ITM probabilities of the caplets can be retrieved with cap.optionletsDelta() after cap.setPricingEngine(engine) has occurred.
Hi, thanks but that's the point. There are indeed swaption and cap/fooor engines but no ordinary Bachelier pricing engine (whereas there's one for Black)
Hi, right I totally missed your point. My bad. It's not hard to re-implement the formulas in python using e.g. ql.CumulativeNormalDistribution()(x), but I think that's also beside your point :)
Ok, at this time only ql.bachelierBlackFormula is available so it's not enough for you. Feel free to add the Bachelier calculator in a PR.
Am I missing something here? I can see this engine which is what you after? ql.BachelierSwaptionEngine
This one is specific to swaptions. I was interested in a more general one (@lballabio sorry, haven't had time to get on it yet but should be able to soon).
Ah ok got it thanks @kp9991-git
This issue was automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment, or this will be closed in two weeks.
Please keep it open