Skip to content
All library documents

QuantLib Black–Scholes Pricing: Day Counts and Calendar Dates

Article Quant Q&A · Author: Eka

Summary

The document shows a QuantLib setup for pricing European call options with the analytic Black–Scholes engine. It compares outputs for several strikes with an online calculator and asks whether QuantLib supports Black ’76. The response identifies two inputs that explain the discrepancy: the valuation date is a Saturday, so the stated expiry effectively leaves a four-day option period, and the code uses an Actual/360 day-count convention. Changing to Actual/365 Fixed can align the year fraction with the calculator’s assumptions.

The example illustrates that option values depend on calendar handling and day-count conventions as well as the spot, strike, volatility, rate, and expiry. The comparison is not a general validation of either model or calculator: the document gives no details about the online tool’s settings, and it does not answer the Black ’76 question.

Key ideas

  • QuantLib's European option engine calculates values from the supplied market data and term structures.
  • The valuation and expiry dates determine the time to expiry used in pricing.
  • Day-count conventions affect the year fraction and can change the option premium.
  • Matching a calculator requires matching its calendar and day-count assumptions.

Tags

Full text
# How to calculate premium in Black Scholes model with quantlib?


# How to calculate premium in Black Scholes model with quantlib?












I am new to quantlib as well as option price modelling. I need to get premium from black scholes model and found this code in internet

```
import QuantLib as ql

S=1100
strike=[1000,1100,1110,1120]
v=0.2
ri=0.04

for K in strike:
    today = ql.Date(20, 7, 2019)
    ql.Settings.instance().evaluationDate = today
    # The Instrument
    option = ql.EuropeanOption( ql.PlainVanillaPayoff(ql.Option.Call, K),
                             ql.EuropeanExercise(ql.Date(25, 7, 2019)))
    # The Market
    u = ql.SimpleQuote(S)      # set todays value of the underlying
    r = ql.SimpleQuote(ri)       # set risk-free rate 
    sigma = ql.SimpleQuote(v)   # set volatility
    riskFreeCurve = ql.FlatForward(0, ql.TARGET(), ql.QuoteHandle(r), ql.Actual360())
    volatility = ql.BlackConstantVol(0, ql.TARGET(), ql.QuoteHandle(sigma), ql.Actual360())
    # The Model
    process = ql.BlackScholesProcess( ql.QuoteHandle(u), 
                                   ql.YieldTermStructureHandle(riskFreeCurve),
                                   ql.BlackVolTermStructureHandle(volatility))
    # The Pricing Engine
    engine = ql.AnalyticEuropeanEngine(process)
    # The Result
    option.setPricingEngine(engine)
    print(option.NPV())
```

With output

```
100.33327806116641
8.195213254652364
4.131971032227009
1.7912417047751839
```

But when I did a comparison study with an online Black Scholes calculator, I got differen result

```
100.55
10.57
6.29
3.43
```

What is wrong with my code? How to I properly model for premium in quantlib? Did quantlib implement`black76` model?

## Answer by Cornholio (score 1)

https://quant.stackexchange.com/a/46732

2019-07-20 is a Saturday and 2019-07-21 is a Sunday, so basically you're looking on a 4 day option. Furthermore use `ql.Actual365Fixed()` to get the same results from the online calculator.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.