原文是建立在http://www.reibang.com/p/ee33c4375a8e的基礎(chǔ)之上的屡萤,在檢驗(yàn)其代碼時發(fā)現(xiàn)這一ETOD代入有問題双饥,因?yàn)檫@篇文章是在matlab上的代碼做的,我看matlab上也是這樣戒劫,就沒太搞懂。
具體更改的代碼
```def KMVOptSearch(E,D,r,T,EquityTheta):
? ? def KMVfun(x,E,D,r,T,EqutityTheta):
? ? ? ? d1 = (np.log(x[0]/D)+(r+0.5*x[1]**2)*T)/x[1]*np.sqrt(T)
? ? ? ? d2 = d1-x[1]*np.sqrt(T)
? ? ? ? return [E-x[0]*stats.norm.cdf(d1,0,1)+D*np.exp(-r*T)*stats.norm.cdf(d2,0,1),
? ? ? ? ? ? ? ? EqutityTheta-x[0]*stats.norm.cdf(d1,0,1)*x[1]/E]
? ? VaThetaX = fsolve(KMVfun,[100,0.001],args=(E,D,r,T,EquityTheta))
? ? Va = VaThetaX[0]
? ? AssetTheta = VaThetaX[1]
? ? return Va, AssetTheta```
但是運(yùn)行起來總會報錯,報錯內(nèi)容是RuntimeWarning: invalid value encountered in log
還希望有人指點(diǎn)一下