fugit_binomialtree.txt ( File view )

  • By 2010-08-27
  • View(s):3
  • Download(s):0
  • Point(s): 1
			Function fugit(ByVal spot As Double, ByVal strike As Double, _
                    ByVal timetomaturity As Double, ByVal risk_free As Double, _
                    ByVal vol As Double, ByVal class As String, _
                    ByVal n As Integer) As Double
    
    Dim price() As Double                       'option price tree
    Dim fugitarray() As Double                  'fugit tree
    Dim S() As Double                           'stock price tree
    Dim dt As Double                            'time step in the tree
    Dim u As Double, d As Double                'binomial tree parameters
    Dim Pu As Double, Pd As Double
    Dim pv As Double                            'discount factor
    Dim I As Integer                            'running counter through the nodes
    Dim j As Integer                            'running counter through the time step
    Dim Arraysize As Integer                    'Size of array for the asset and option price tree
    Dim C_P As Integer                          'to indicate the option is call or put
      
      
    ' N is defined as integer and overflow will occur if 365 is not considered is double
    dt = timetomaturity / n
    pv = Exp(-risk_free * dt)
    Arraysize = n + 1
            
    'the default is a call option, unless a "p" is given to indicate put option
    If class = "p" Then
        C_P = -1
    Else
        C_P = 1
    End If
        
    ' the stock price S move to S*u and S*d in the next time step of the tree
    ' u and d and probability of going up or down are calculated in the following
    ' This is the standard Cox - Rubinstein tree setup
    u = Exp(vol * dt ^ (1 / 2))
    d = 1 / u
    
    Pu = (Exp(risk_free * dt) - d) / (u - d)
    Pd = 1 - Pu
    
    ReDim price(Arraysize)
    ReDim fugitarray(Arraysize)
    ReDim S(Arraysize)
        
    ' initialise asset prices at maturity step N
    S(0) = spot * (d ^ n)
    For I = 1 To n
        S(I) = S(I - 1) * u / d
    Next I
        
    ' initialise option values at maturity
    For I = 0 To n
        price(I) = Application.WorksheetFunction.Max(0#, C_P * S(I) - C_P * strike)
        fugitarray(I) = 0
    Next I
       
    ' stepping back the tree and applying the early exercie condition
    For j = n - 1 To 0 Step -1
        For I = 0 To j
            price(I) = pv * (Pu * price(I + 1) + Pd * price(I))
                S(I) = S(I) * u
                If price(I) > (C_P * S(I) - C_P * strike) Then
                    fugitarray(I) = (Pu * fugitarray(I + 1) + Pd * fugitarray(I)) + dt
                Else
                    fugitarray(I) = 0
                End If
        Next I
    Next j
    
    
    fugit = fugitarray(0)
    

End Function
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
fugit_binomialtree.txt2.72 kB11-10-08 03:06
...
Sponsored links

fugit_binomialtree.txt (1.29 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D