'Scipy Optimize Minimize - Syntax for function with array of arguments, and input fixed vector

getting some difficulty in setting up my scipy.optimize minimize function.

I thought I had set-it-up correctly, but my internal results just looks strange. Basically, I have this function (vol_function), which depends on 6 parameters I have two vectors,

  1. one vector x which is an array of values calculated from vol_function
  2. one vector y, which is an array of target values I want to 'calibrate' 3 params out of 6 from this vol_function, which will make the absolute difference between vector x and vector y minimized.

Vector x is the 'volcurve_' in the example below. Vector y is the 'targets' in the example below. Am I setting the scipy minimize correctly? Help!!! Below is the format of my code.

vol_function(strike, fwd, time, alpha, beta, rho, volvol):
    .....
    .....
    return vol_

strikes = [-1.0, -0.8, -0.6, -0.2, 0.0, .... 0.6, 0.8, 1.0]
targets = [10.0, 9.0, 8.0, ......, 16.0, 18.0, 20.0]

calib_(strikes, targets, fwd, time):
    volcurve_ = []
    for strike_ in strikes:
        vol_ = vol_function(strike_, fwd, time, alpha, beta, rho, volvol)
        volcurve_.append(vol_)
    
    return np.sum((volcurve_ - targets)**2)

x0 = np.array([alpha, beta, rho, volvol])
bounds = [(0.0001, None), (0.001, 0.9999), (-0.9999, +0.99999), (0.00001, None)]
res = minimize(calib_, x0, method = 'L-BFGS-B', bounds = bounds)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source