[討論] 自訂函數失敗

作者: yuseke (大將)   2017-04-12 11:32:34
如題,因在自學matlab
我自訂了一個函數想自己計算看看
然後我就上網找了一個好像很夯(?)的東西(B-S model)
參考了wiki上的公式之後
function c = BSM(S,L,T,sigma,r)
D1 = ( log(S/L)+(r+0.5*(sigma^2))*T ) / (sigma*(T^0.5))
D2 = D1-sigma*sqrt(T)
c = S * normcdf(D1) * ( exp^(-r*T) * L * normcdf(D2) )
end
這樣
然後儲存起來
回到command window 輸入了>> BSM=( 100 , 95 , 1 , 2 , 0.02 )
然後就換來了
BSM=( 100 , 95 , 1 , 2 , 0.02 )

Error: Expression or statement is incorrect
作者: ntumath (math mad)   2017-04-12 11:50:00
你的function end呢?
作者: yuseke (大將)   2017-04-12 11:53:00
!!!!!!!!!!!!
作者: ntumath (math mad)   2017-04-12 11:58:00
你應該這樣呼叫函數-->BSM(100,95,1,2,0.02)不用加等於
作者: yuseke (大將)   2017-04-12 12:29:00
我的exp還多加一個"^".....我真的是ORZ

Links booklink

Contact Us: admin [ a t ] ucptt.com