TypeError:()缺少2个必需的位置参数:“ lnS”和“ T”
我试图在不同的地方声明变量'lnS'和'T'。
下面是代码:
def minimize(param):
CF=lambda u, lnS, T:\
cf_log_cgmy(u=u, lnS=lnS, T=Tmt, mu=r, half_etasq=param[4],\
C=param[0], G=param[1], M=param[2], Y=param[3])
Call_price_CM_CF(CF, lnS)
sum = 0
for i in range(0,len(prices_oom)):
a = Call_price_CF_K(np.log(strike_oom[i])) - prices_oom[i]
sum = sum+a*a
return sum
错误是:
TypeError: <lambda>() missing 2 required positional arguments: 'lnS' and 'T'
答案 0 :(得分:2)
def psi(CF, GLOBALVJ, GLOBALALPHA, lnS, GLOBALT):
u=GLOBALVJ-(GLOBALALPHA*1j+1j)
denom = GLOBALALPHA**2 + GLOBALALPHA - Sigma**2 + GLOBALVJ * 2 * GLOBALALPHA * 1j + 1j * GLOBALVJ
return CF(u)/denom
这就是问题所在。在psi
函数内部,您正在调用lambda CF
,但仅传递一个参数。预计您的声明为3
CF=lambda u, lnS, T:\
cf_log_cgmy(u=u, lnS=lnS, T=Tmt, mu=r, half_etasq=param[4],\
C=param[0], G=param[1], M=param[2], Y=param[3])