Skip to content
All library documents

Representing Local Volatility in Python QuantLib

Article Quant Q&A · Author: rwicl

Summary

The document asks how to use a Python-defined local volatility function with QuantLib’s Black–Scholes process. It clarifies that a local volatility term structure handle cannot simply be constructed from an arbitrary Python function in the shown way; the underlying C++ interface also expects a Black volatility term structure.

The answer points to FixedLocalVolSurface as an available route in QuantLib 1.30: sample the local volatility function over a grid, then pass those values to the surface class. This turns a continuous function into tabulated inputs suitable for the library’s process. The material is implementation guidance rather than a discussion of local volatility theory or simulation accuracy. It does not specify grid design, interpolation choices, boundary behavior, or how discretization affects simulated paths, so those details must be addressed separately.

Key ideas

  • A Python callable cannot be passed directly as the local volatility term structure in the proposed construction.
  • The relevant QuantLib interface requires a Black volatility term structure as an input.
  • QuantLib 1.30 provides FixedLocalVolSurface, which accepts local volatility values sampled over a grid.
  • Grid selection and interpolation affect how the tabulated surface represents the original volatility function.

Tags

Full text
# Use `LocalVolTermStructureHandle` in Python QuantLib


# Use `LocalVolTermStructureHandle` in Python QuantLib












I would like to simulate a local volatility underlying $$ dS_t = S_t\sigma(t, S_t)dW_t $$ and have looked at QuantLib's `LocalVolTermStructureHandle` to do so.

So far:

```
today = ql.Date().todaysDate()
calendar = ql.NullCalendar()
dayCounter = ql.Actual365Fixed()
spot = 100
rate = 0.0

initial_value = ql.QuoteHandle(ql.SimpleQuote(spot))
flat_curve = ql.FlatForward(today, rate, ql.Actual365Fixed())

riskfree_ts = ql.YieldTermStructureHandle(flat_curve)
dividend_ts = ql.YieldTermStructureHandle(flat_curve)
```

Now, I have some Python-based implementation `localvol_func` of $(t, s)\mapsto \sigma(t, s)$ and would like to invoke

```
localvol_ts = ql.LocalVolTermStructureHandle(localvol_func)
```

(or similar) to finally do

```
process = ql.GeneralizedBlackScholesProcess(initial_value, dividendTS=dividend_ts, riskfreeTS=riskfree_ts, localVolTS=localvol_ts)
```

Does that make sense at all? Would this achieve what I'm trying to achieve? I know Python QuantLib is just a wrapper, so most likely I cannot be working with a Python-based implementation of the local volatility function, right? What would I need to do instead?

## Answer by Chiu-Tzu-Hsuan (score 2)

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

Take a look at line 64. C++ takes five inputs, so BlackVolTermStructure must be added.

https://rkapl123.github.io/QLAnnotatedSource/d0/da0/blackscholesprocess_8hpp_source.html

## Answer by Luigi Ballabio (score 1)

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

As of QuantLib 1.30, you can sample your local volatility over a grid and pass the results to the FixedLocalVolSurface class.

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.