Search code examples
pythonquantlib

Correctly specifying the Risk free rate in option calculation


As per my understand a typical option contract is priced using QuantLib as below -

    import QuantLib as ql
    today = ql.Date(7, ql.March, 2014)
    ql.Settings.instance().evaluationDate = today
    u = ql.SimpleQuote(100.0)
    r = ql.SimpleQuote(0.01)
    sigma = ql.SimpleQuote(0.20)
    riskFreeCurve = ql.FlatForward(
                                    0, 
                                    ql.TARGET(), 
                                    ql.QuoteHandle(r), 
                                    ql.Actual360()
                                )
    volatility = ql.BlackConstantVol(
                                        0, 
                                        ql.TARGET(), 
                                        ql.QuoteHandle(sigma), 
                                        ql.Actual360()
                                    )
    process = ql.BlackScholesProcess(ql.QuoteHandle(u), ql.YieldTermStructureHandle(riskFreeCurve), ql.BlackVolTermStructureHandle(volatility))
    engine = ql.AnalyticEuropeanEngine(process)
    
    option = ql.EuropeanOption(ql.PlainVanillaPayoff(ql.Option.Call, 100.0), ql.EuropeanExercise(ql.Date(7, ql.June, 2014)))
    option.setPricingEngine(engine)

This is good. However when I defined the risk-free rate, I did not explicitly define the compounding frequency. In typical BS formula, the risk-free rate, dividend etc. are defined as Continuously compounding rate. So my questions are

  1. Is above calculation correct since I did not explicitly define the compounding frequency?
  2. If not, then how can I convert above risk free rate to Continuously compounding rate?

Solution

  • The FlatForward class you used (as most classes in QuantLib) by default interprets the passed rates as continuously compounded, so your code is already doing what you mean.

    If you want to specify a different compounding convention or if you want to be explicit, the constructor can take additional parameters. For instance, you can write

    ql.FlatForward(
        0,
        ql.TARGET(),
        ql.QuoteHandle(r),
        ql.Actual360(),
        ql.Continuous,
    )
    

    or

    ql.FlatForward(
        0,
        ql.TARGET(),
        ql.QuoteHandle(r),
        ql.Actual360(),
        ql.Compounded,
        ql.Quarterly,
    )