-1
$\begingroup$

I'm using the following to compute the price and Greeks a vanilla European option:

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)
exercise = ql.EuropeanExercise(maturity_date)
european_option = ql.VanillaOption(payoff, exercise)

spot_handle = ql.QuoteHandle(
            ql.SimpleQuote(spot_price)
        )
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, 
                                                   dividend_yield, 
                                                   flat_ts, 
                                                   flat_vol_ts)

european_option.setPricingEngine(ql.AnalyticEuropeanEngine(bsm_process))

# price
bs_price = european_option.NPV()

price
6.749271812460607

# Greek sensitivities
delta = european_option.delta()
gamma = european_option.gamma()
vega = european_option.vega()
theta = european_option.theta()

delta
0.4582969846433817

gamma
0.018522331553816086

vega
41.655351781911605

theta
-5.131800499907545

This is a lengthy amount of code to price a vanilla option. Is there a more straightforward way?

Yes, I'm well aware that QuantLib is an extremely powerful engine and not necessarily built for simplicity, as mentioned very eloquently by @SmallChess in Why does it take so many lines of code to price even the simplest of options with QuantLib.

Are there any wrapper functions that I might be able to use to simplify things?

Thanks!

$\endgroup$

2 Answers 2

3
$\begingroup$

You should think of QuantLib as a set of very powerfull tools/parts which you can use to build your own pricers.

If you are going to price a single option, yes it takes a bit of boilerplate code to get the result.

But you can always reuse this code for different inputs, specially if you want to do sensitivity analysis. I think the way QuantLib stores inputs with quotes, enabling all consequent recomputation makes up for the initial boilerplate.

$\endgroup$
2
$\begingroup$

You could simply code the formulas yourself, but this would not reduce the amount of code. I would say using quantlib is already very compact.

$\endgroup$

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.