hello,
i am trying to create a binomial asset Pricer and am expecting an output of ~$6.37 from my code.
i am getting the below error:
error.png
please help, thank you
full code:
BAPM_v1.xlsm
hello,
i am trying to create a binomial asset Pricer and am expecting an output of ~$6.37 from my code.
i am getting the below error:
error.png
please help, thank you
full code:
BAPM_v1.xlsm
Well, variable S is passed as a Double. The line of code that's failing is trying to reference S as if it were a two-dimensional array. VBA is expecting an array when you reference array indices but it's not an array; it's a Double.
WBD
Office 365 on Windows 11, looking for ✶ rep!
( removed )
Based on this page:
https://en.wikipedia.org/wiki/Binomi..._pricing_model
And adapting the algorithm on the right into VBA, this is what I came up with:
But it returns 5.251026 as the answer so perhaps it's not right?![]()
Public Function BAPM(S As Double, q As Double, r As Double, sigma As Double, T As Double, N As Double, K As Double) As Variant ' S - stock price ' q - dividend yield ' r - ? ' sigma - ? ' T - expiration time ' N - height of binomial tree ' K - strike price Dim deltaT, up, p0, p1 deltaT = T / N up = Exp(sigma * deltaT ^ 0.5) p0 = (up * Exp(-q * deltaT) - Exp(-r * deltaT)) / (up ^ 2 - 1) p1 = Exp(-r * deltaT) - p0 Dim i As Long, j As Long, p, exercise ReDim p(0 To N) For i = 0 To N p(i) = K - S * up ^ (2 * i - N) If p(i) < 0 Then p(i) = 0 Next i For j = N - 1 To 0 Step -1 For i = 0 To j p(i) = p0 * p(i + 1) + p1 * p(i) exercise = K = S * up ^ (2 * i - j) If p(i) < exercise Then p(i) = exercise Next i Next j BAPM = p(0) End Function
WBD
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks