QuantLib icon indicating copy to clipboard operation
QuantLib copied to clipboard

Bachelier calculator

Open kp9991-git opened this issue 8 months ago • 11 comments

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

kp9991-git avatar Mar 21 '25 05:03 kp9991-git

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.

boring-cyborg[bot] avatar Mar 21 '25 05:03 boring-cyborg[bot]

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.

lballabio avatar Apr 07 '25 13:04 lballabio

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)?

kp9991-git avatar Apr 07 '25 21:04 kp9991-git

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?

lballabio avatar Apr 09 '25 14:04 lballabio

I'm looking for a way to calculate a simple Bachelier price or greeks from Python

kp9991-git avatar Apr 09 '25 16:04 kp9991-git

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.

BohlSeb avatar Apr 11 '25 23:04 BohlSeb

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)

kp9991-git avatar Apr 12 '25 00:04 kp9991-git

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 :)

BohlSeb avatar Apr 12 '25 12:04 BohlSeb

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.

lballabio avatar Apr 15 '25 13:04 lballabio

Am I missing something here? I can see this engine which is what you after? ql.BachelierSwaptionEngine

LZ1153 avatar Jun 06 '25 07:06 LZ1153

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).

kp9991-git avatar Jun 06 '25 08:06 kp9991-git

Ah ok got it thanks @kp9991-git

LZ1153 avatar Jun 19 '25 02:06 LZ1153

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.

github-actions[bot] avatar Aug 19 '25 02:08 github-actions[bot]

Please keep it open

kp9991-git avatar Aug 20 '25 09:08 kp9991-git