Skip to content
All library documents

Diagnosing QuantLib Heston Helper Input Type Errors

Article Quant Q&A · Author: user324313

Summary

The document investigates a Python QuantLib TypeError raised while constructing Heston model calibration helpers for options. The replies point to mismatched input types or values as the likely cause and identify code issues to check, including an inconsistent risk-free rate variable name and helper lists that are not initialized within the function.

A refactored example calculates the time to expiration once, creates a period and grid data, initializes the helper list, and passes the market inputs into each helper. It also highlights that the implied-volatility value should be used for each strike. The discussion provides no confirmed diagnosis for the original run, and its proposed example appears to pass the model parameter sigma instead of the loop’s implied volatility. The practical lesson is to verify constructor argument types and trace each input to its intended source; the example is illustrative rather than a verified fix.

Key ideas

  • QuantLib reports an overloaded-constructor TypeError when the Heston helper receives incompatible argument types or values.
  • Check that the risk-free rate variable name matches the function argument.
  • Initialize helper and grid containers in the function before appending to them.
  • Calculate the expiry period once when all options share the same expiration.
  • Ensure each helper receives the implied volatility associated with its strike.

Tags

Full text
# 58997


# What is the cause of this error 'TypeError: Wrong number or type of arguments for overloaded function 'new_HestonModelHelper'?












I'm simulating the option prices every month using the Heston Model. The option contract expires at the of the month and the next option contract start the day after the previous contract expire. In order to simulate it, first, I need to calibrate the parameters of Heston model. I construct the Heston model helpers using the code below.

```
def helpers(strikes,spot,implied,param,calculation_date,expiration_date,risk_free_interest,dividend_rate):
    calendar = ql.India()
    theta,kappa,sigma,rho,v0  = list(param)
    
    flat_ts = ql.YieldTermStructureHandle(ql.FlatForward(calculation_date, risk_free_rate, ql.Actual365Fixed()))
    dividend_ts = ql.YieldTermStructureHandle(ql.FlatForward(calculation_date, dividend_rate, ql.Actual365Fixed()))    
    
    process = ql.HestonProcess(flat_ts, dividend_ts, 
                           ql.QuoteHandle(ql.SimpleQuote(spot)), 
                           v0, kappa, theta, sigma, rho)
    model = ql.HestonModel(process)
    engine = ql.AnalyticHestonEngine(model, 0.0001, 1000)

    for j, s in enumerate(strikes):
        t =  calendar.businessDaysBetween(calculation_date, expiration_date)
        p = ql.Period(t, ql.Days)
        sigma = implied[j]
        
        helper = ql.HestonModelHelper(p, calendar, spot , s , 
                                      ql.QuoteHandle(ql.SimpleQuote(sigma)),
                                      flat_ts,
                                      dividend_ts)
        helper.setPricingEngine(engine)
        heston_helpers.append(helper)  
        grid_data.append((expiration_date,s))
    model = ql.HestonModel(process)
    engine = ql.AnalyticHestonEngine(model, 0.0001, 1000)
    return heston_helpers, grid_data, model
```

```
For the first option contract of 2014: 
strikes = [10000 10100 10200 10300 10400 ...]
spot = 10150.05
implied = [3.2958984375, 1.468658447265625, 0, 0, 0 ...]
param = (0.55, 15.5, 0.4, -0.5, 0.00659640970297048)
risk_free_interest =  0.0867
dividend_rate =  0.018000000000000002
calculation_date = December 27th, 2013 
expiration_date = January 30th, 2014
```

I ran the function with these inputs above but I ran into some kind of TypeError and I cant figure out why. I used the same function for my other simulations and it worked perfectly. Im just wondering why it doesnt work now. Can please someone help me?

```
<ipython-input-75-981b2d8597ce> in helpers(strikes, spot, implied, param, calculation_date, expiration_date,risk_interest_rate,dividend_rate)
     31                                       ql.QuoteHandle(ql.SimpleQuote(sigma)),
     32                                       flat_ts,
---> 33                                       dividend_ts)
     34         helper.setPricingEngine(engine)
     35         heston_helpers.append(helper)

~\Anaconda3\lib\site-packages\QuantLib\QuantLib.py in __init__(self, *args)
  10477 
  10478     def __init__(self, *args):
> 10479         _QuantLib.HestonModelHelper_swiginit(self, _QuantLib.new_HestonModelHelper(*args))
  10480     __swig_destroy__ = _QuantLib.delete_HestonModelHelper
  10481 

TypeError: Wrong number or type of arguments for overloaded function 'new_HestonModelHelper'.
  Possible C/C++ prototypes are:
    HestonModelHelper::HestonModelHelper(Period const &,Calendar const &,Real const,Real const,Handle< Quote > const &,Handle< YieldTermStructure > const &,Handle< YieldTermStructure > const &,BlackCalibrationHelper::CalibrationErrorType)
    HestonModelHelper::HestonModelHelper(Period const &,Calendar const &,Real const,Real const,Handle< Quote > const &,Handle< YieldTermStructure > const &,Handle< YieldTermStructure > const &)
```

## Answer by David Duarte (score 1)

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

The error seems to be a wrong variable type in the inputs of the `HestonModelHelper` constructor.

There are a few errors in the code like `risk_free_rate` vs `risk_free_interest` as the variable name; and `heston_helpers` and `grid_data` not being defined inside the function but apart from that it should work if you give it the right type of inputs.

Here is a slight refactoring of your code but I suspect the problem was the way your inputs were defined.

```
import QuantLib as ql

def helpers(strikes, spot, implied, param, calculation_date, expiration_date, risk_free_interest, dividend_rate):
    heston_helpers= []
    calendar = ql.India()
    theta,kappa,sigma,rho,v0  = list(param)
    
    flat_ts = ql.YieldTermStructureHandle(ql.FlatForward(calculation_date, risk_free_interest, ql.Actual365Fixed()))
    dividend_ts = ql.YieldTermStructureHandle(ql.FlatForward(calculation_date, dividend_rate, ql.Actual365Fixed()))        
    process = ql.HestonProcess(flat_ts, dividend_ts, ql.QuoteHandle(ql.SimpleQuote(spot)), v0, kappa, theta, sigma, rho)
    model = ql.HestonModel(process)
    engine = ql.AnalyticHestonEngine(model, 0.0001, 1000)
    
    t =  calendar.businessDaysBetween(calculation_date, expiration_date)
    p = ql.Period(t, ql.Days)
    grid_data = [(expiration_date, strike) for strike in strikes]
    for strike, vol in zip(strikes, implied):
        helper = ql.HestonModelHelper(p, calendar, spot, strike, 
                                      ql.QuoteHandle(ql.SimpleQuote(sigma)),
                                      flat_ts,
                                      dividend_ts)
        helper.setPricingEngine(engine)
        heston_helpers.append(helper)          
    return heston_helpers, grid_data, model

strikes = [10000, 10100, 10200, 10300, 10400]
implied = [3.2958984375, 1.468658447265625, 0, 0, 0]
spot = 10150.05
param = (0.55, 15.5, 0.4, -0.5, 0.00659640970297048)
calculation_date = ql.Date(27, 12, 2013)
expiration_date = ql.Date(30, 1, 2014)
risk_free_interest =  0.0867
dividend_rate =  0.018
helpers(strikes, spot, implied, param, calculation_date, expiration_date, risk_free_interest, dividend_rate)
```

You can check this link for some examples.

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.