我无法理解此错误的来源:
第327行,在function_wrapper中返回函数(*(wrapper_args + args))TypeError:SSVOptionPriceObjFunc()缺少1个必需的位置参数:'marketVolSurface'
相关代码如下:
x0 = [1.0, 0.0] # (lambda0, rho)
x0 = np.asarray(x0)
args = (spot, 0.01*r, daysInYear, mktPrices, volSurface)
# constraints: lambd0 >0, -1<= rho <=1
boundsHere = ((0, None), (-1, 1))
res = minimize(SSVOptionPriceObjFunc, x0, args, method='L-BFGS-B', jac=None,
bounds=boundsHere,options={'xtol': 1e-8, 'disp': True})
要最小化的功能如下。前两个参数是自由变量,而其他五个则固定为参数。
def SSVOptionPriceObjFunc(lambda0, rho, spot, spotInterestRate, daysInYear, marketPrices,
marketVolSurface):
我的意图是找出(lambd0,rho)给出最小值。从调试器看来,我的最初猜测x0被解释为单个变量,而不是向量,给出了有关缺少位置参数的错误。我尝试过将x0作为列表,元组和ndarray传递;都失败了。有人可以发现错误或建议解决方法吗?先感谢您。
更新:我找到了一个解决方案:使用functools包中的包装函数来设置参数。将功能工具导入为ftSSVOptionPriceObjFuncWrapper = ft.partial(SSVOptionPriceObjFunc,spot = spot,spotInterestRate = 0.01 * r,daysInYear = daysInYear,marketPrices = mktPrices,marketVolSurface = volSurface)
然后通过args = None将SSVOptionPriceObjFuncWrapper传递到最小化器>
谢谢您的答复。
我无法理解此错误的根源:function_wrapper返回函数中的第327行(*(wrapper_args + args))TypeError:SSVOptionPriceObjFunc()缺少1个必需的位置...
认真对待已记录的minimize
输入。编写适合minimize
功能的函数是您的工作,而不是相反。