I can calculate the fair price of a European Option using Quantlib as below -

import QuantLib as ql 
maturity_date = ql.Date(15, 1, 2016)
spot_price = 127.62
strike_price = 130
volatility = 0.20 
dividend_rate =  0.0163
option_type = ql.Option.Call

risk_free_rate = 0.001
day_count = ql.Actual365Fixed()
calendar = ql.UnitedStates()

calculation_date = ql.Date(8, 5, 2015)
ql.Settings.instance().evaluationDate = calculation_date

payoff = ql.PlainVanillaPayoff(option_type, strike_price)
settlement = calculation_date
eu_exercise = ql.EuropeanExercise(maturity_date)
european_option = ql.VanillaOption(payoff, eu_exercise)

spot_handle = ql.QuoteHandle(
flat_ts = ql.YieldTermStructureHandle(
    ql.FlatForward(calculation_date, risk_free_rate, day_count)
dividend_yield = ql.YieldTermStructureHandle(
    ql.FlatForward(calculation_date, dividend_rate, day_count)
flat_vol_ts = ql.BlackVolTermStructureHandle(
    ql.BlackConstantVol(calculation_date, calendar, volatility, day_count)
bsm_process = ql.BlackScholesMertonProcess(spot_handle, 

This is perfect. However I want to see the actual calculation engine to look into the actual formula being used for the calculation.

Can you please help me to find the actual file location to see the formula being used? I have searched various files in my local file-system of ~ql and also online resources like https://rkapl123.github.io/QLAnnotatedSource/d2/d98/analyticeuropeanengine_8hpp_source.html, but failed to find such.

Your help will be highly appreciated.

  • $\begingroup$ Not familiar with it, but based on naming seems likely simply a BSM implementation. What details are you looking for? $\endgroup$
    – Chris
    Aug 24, 2020 at 0:57

1 Answer 1


QuantLib-Python is actually using SWIG to run C++ code

I expect it is running compiled C++ code underneath so you won't find the actual lines of code on your computer

But assuming your ql.VanillaOption and your ql.BlackScholesMertonProcess are connected with a ql.AnalyticEuropeanEngine pricing engine, the engine's code is here and you will see that on Line 71 it calls the Black Calculator here which is doing the calculations.

  • $\begingroup$ So if I make a change in github.com/lballabio/QuantLib/blob/master/ql/pricingengines/…, how that can be implemented in my calculation? I am using Xcode to run the C++ code (also python) $\endgroup$
    – Bogaso
    Aug 24, 2020 at 6:54
  • $\begingroup$ @Bogaso, You appear to be using python for your scripting in your original question so it is not clear that you're running your scripts using C++ as well. As long as you have complied the QuantLib library from the original C++ source and then used SWIG to generate the Python module, you can: 1/ edit the C++ code in original source; 2/ recompile the C++ library; 3/ regenerate the Python module. In other words if you edit the C++ source files you have to rebuild the library from source to recreate the binaries (which are then translated to a Python module via SWIG). $\endgroup$
    – user35980
    Aug 24, 2020 at 11:34
  • $\begingroup$ My question was that, what should be the bottommost source file, that to be modified. Should I download the QuantLib-1.19.tar.gz from bintray.com/quantlib/releases/QuantLib and then untar it and then modify the required file? $\endgroup$
    – Bogaso
    Aug 24, 2020 at 11:45
  • $\begingroup$ yes, modify and then recompile to obtain the updated binaries (i.e. run ./configure, make, make install etc). After you've done that, if you're going to use Python, download Quantlib-SWIG and then compile that to obtain the modified Quantlib Python module. $\endgroup$
    – user35980
    Aug 24, 2020 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.