+ Reply to Thread
Results 1 to 5 of 5

compile error: expected array ; binomial asset pricer

Hybrid View

  1. #1
    Registered User
    Join Date
    10-29-2017
    Location
    Miami, FL
    MS-Off Ver
    2010
    Posts
    76

    compile error: expected array ; binomial asset pricer

    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

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: compile error: expected array ; binomial asset pricer

    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!

  3. #3
    Registered User
    Join Date
    10-29-2017
    Location
    Miami, FL
    MS-Off Ver
    2010
    Posts
    76
    Quote Originally Posted by WideBoyDixon View Post
    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
    Gotcha!
    What Can I change it to? I don?t believe it needs to be an array. That line should output just 1 # per line

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Post Re: compile error: expected array ; binomial asset pricer


    ( removed )

  5. #5
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: compile error: expected array ; binomial asset pricer

    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:

    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
    But it returns 5.251026 as the answer so perhaps it's not right?

    WBD

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. need help with error : compile error expected array
    By eggs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2017, 01:50 PM
  2. Replies: 0
    Last Post: 08-09-2017, 07:06 AM
  3. [SOLVED] Compile error: Expected Array
    By jkj115 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-27-2016, 03:01 PM
  4. [SOLVED] Compile error: expected array
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2015, 04:06 AM
  5. [SOLVED] Help with Compile Error: Expected Array
    By g8r777 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2012, 11:44 AM
  6. Compile Error: Expected Array
    By abfrempong in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-13-2012, 02:35 AM
  7. Compile Error - Expected Array
    By AccountantCost in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2009, 02:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1