AnswerBun.com

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

Quantitative Finance Asked by user324313 on November 30, 2020

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)

~Anaconda3libsite-packagesQuantLibQuantLib.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 &)

One Answer

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.

Answered by David Duarte on November 30, 2020

Add your own answers!

Related Questions

Volatility of multimodal distribution of returns

0  Asked on February 3, 2021 by vivek-subramanian

     

How does Bloomberg calculate beta?

0  Asked on January 8, 2021 by friedrich

   

Calculation of the Bid-Ask Spread on Bloomberg

1  Asked on January 7, 2021 by user45980

   

delta neutral option cost

1  Asked on December 28, 2020 by roller

   

Obtaining current list of companies in the FTSE 100 via an API

3  Asked on December 23, 2020 by thechubbypanda

 

Converting US Treasury CMT to Discount Yields

1  Asked on December 13, 2020 by mikerand

   

How to calculate Greeks for leveraged Barrier options?

0  Asked on December 12, 2020 by twhale

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir