[VBA ] function與ByRef引數型態不符
附上原始碼
--
Public Function BSoption(cp As String, s As Double, k As Double, t As Double,
sig As Double, r As Double) As Double
Dim d1 As Double
Dim d2 As Double
d1 = (Log(s / k) + (r + sig * sig / 2) * t) / (sig * Sqr(t))
d2 = d1 - sig * Sqr(t)
If cp = "C" Then
BSoption = s * cdf(d1) - k * Exp(-r * t) * cdf(d2)
Else
BSoption = k * Exp(-r * t) * cdf(-d2) - s * cdf(-d1)
End If
End Function
--
我的想讓cp可以直接抓到某個位置的字元,但因為這樣就會使得引數型態不符?
有沒有辦法可以使我的function使用上可以直接在excel上使用成這樣:
=BSoption(C,50,50,1,0.25,0.06)
或者是:
=BSoption(A1,A2,A3,A4,A5,A6)
A1 A2 A3 A4 A5 A6
----------------------------
C 50 50 1 0.25 0.06
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.22.18.73
→
03/15 11:56, , 1F
03/15 11:56, 1F