Attribute VB_Name = "FINAN_DERIV_TRINOMIAL_LIBR" Option Explicit 'Requires that all variables to be declared explicitly. Option Base 1 'The "Option Base" statement allows to specify 0 or 1 as the 'default first index of arrays. '************************************************************************************ '************************************************************************************ '© Copyright NicoSystem 2009. All rights reserved by Rafael Nicolas Fermin Cota, 'San Francisco, CA. USA www.rnfc.org 'nfermincota.hba2005@ivey.ca '************************************************************************************ '************************************************************************************ 'FUNCTION : TRINOMIAL_TREE_OPTION_PRICE_FUNC 'DESCRIPTION : The following model is built under the assumption that cash paid to 'owners of the underlying, such as dividends and interest, are paid 'continuously at constant rate over the life of the option. This 'assumption is relatively accurate for valuing puts generally, and calls 'on bonds, commodities, currencies and stock index portfolios. 'LIBRARY : DERIVATIVES 'GROUP : TRINOMIAL 'ID : 001 'AUTHOR : RAFAEL NICOLAS FERMIN COTA 'LAST UPDATE : 01/29/2009 '************************************************************************************ '************************************************************************************ Function TRINOMIAL_TREE_OPTION_PRICE_FUNC(ByVal SPOT As Double, _ ByVal STRIKE As Double, _ ByVal EXPIRATION As Double, _ ByVal RISK_FREE_RATE As Double, _ ByVal DIVIDEND_YIELD As Double, _ ByVal VOLATILITY As Double, _ ByVal nSTEPS As Long, _ Optional ByVal OPTION_FLAG As Integer = 1, _ Optional ByVal EXERCISE_TYPE As Integer = 0) 'SPOT: Underlying asset current price. 'STRIKE: Price at which the underlying can be bought (for calls) or 'sold (for puts). 'EXPIRATION: Maturity scaled on an annualized basis 'RISK_FREE_RATE: The cost of funds for the number of days to MATURITY 'It should corresponds to the period to the record date, not the option MATURITY 'DIVIDEND_YIELD: Yield paid on the underlying asset matching 'the option's MATURITY. 'VOLATILITY: Annualized volatility of the underlying asset price 'nSTEPS --> Number of nSTEPS (e.g. One-month intervals) 'OPTION_FLAG: 1 for call, and -1 for put. 'EXERCISE_TYPE: 0 For European, else For American Dim i As Long Dim j As Long Dim DISCOUNT_FACTOR As Double 'Discount Factor Dim DELTA_TIME As Double 'time step in the tree Dim UP_STEP_SIZE As Double Dim DOWN_STEP_SIZE As Double Dim PROB_UP_MOVE As Double Dim PROB_DOWN_MOVE As Double Dim PROB_MID_MOVE As Double Dim TEMP_MATRIX As Variant On Error GoTo ERROR_LABEL If OPTION_FLAG <> 1 Then: OPTION_FLAG = -1 'Put DELTA_TIME = EXPIRATION / nSTEPS DISCOUNT_FACTOR = Exp(-RISK_FREE_RATE * DELTA_TIME) UP_STEP_SIZE = Exp(VOLATILITY * Sqr(2 * DELTA_TIME)) DOWN_STEP_SIZE = Exp(-VOLATILITY * Sqr(2 * DELTA_TIME)) PROB_UP_MOVE = ((Exp((RISK_FREE_RATE - DIVIDEND_YIELD) * DELTA_TIME / 2) - Exp(-VOLATILITY * _ Sqr(DELTA_TIME / 2))) / (Exp(VOLATILITY * Sqr(DELTA_TIME / 2)) - _ Exp(-VOLATILITY * Sqr(DELTA_TIME / 2)))) ^ 2 PROB_DOWN_MOVE = ((Exp(VOLATILITY * Sqr(DELTA_TIME / 2)) - Exp((RISK_FREE_RATE - DIVIDEND_YIELD) * _ DELTA_TIME / 2)) / (Exp(VOLATILITY * Sqr(DELTA_TIME / 2)) - Exp(-VOLATILITY * _ Sqr(DELTA_TIME / 2)))) ^ 2 PROB_MID_MOVE = 1 - PROB_UP_MOVE - PROB_DOWN_MOVE ReDim TEMP_MATRIX(0 To 2 * nSTEPS, 1 To 1) For i = 0 To (2 * nSTEPS) TEMP_MATRIX(i, 1) = MAXIMUM_FUNC(0, OPTION_FLAG * _ (SPOT * UP_STEP_SIZE ^ MAXIMUM_FUNC(i - nSTEPS, 0) * _ DOWN_STEP_SIZE ^ MAXIMUM_FUNC(nSTEPS * 2 - nSTEPS - i, _ 0) - STRIKE)) Next i For j = nSTEPS - 1 To 0 Step -1 For i = 0 To (j * 2) Select Case EXERCISE_TYPE Case 0 ', "e", "EURO" TEMP_MATRIX(i, 1) = (PROB_UP_MOVE * TEMP_MATRIX(i + 2, 1) + _ PROB_MID_MOVE * TEMP_MATRIX(i + 1, 1) + PROB_DOWN_MOVE * _ TEMP_MATRIX(i, 1)) * DISCOUNT_FACTOR Case Else '"a", "amer" TEMP_MATRIX(i, 1) = MAXIMUM_FUNC((OPTION_FLAG * (SPOT * UP_STEP_SIZE ^ _ MAXIMUM_FUNC(i - j, 0) * DOWN_STEP_SIZE ^ MAXIMUM_FUNC(j * 2 - j - i, _ 0) - STRIKE)), (PROB_UP_MOVE * TEMP_MATRIX(i + 2, 1) + PROB_MID_MOVE * _ TEMP_MATRIX(i + 1, 1) + PROB_DOWN_MOVE * TEMP_MATRIX(i, 1)) * _ DISCOUNT_FACTOR) End Select Next i Next j TRINOMIAL_TREE_OPTION_PRICE_FUNC = TEMP_MATRIX Exit Function ERROR_LABEL: TRINOMIAL_TREE_OPTION_PRICE_FUNC = Err.number End Function '************************************************************************************ '************************************************************************************ '© Copyright NicoSystem 2009. All rights reserved by Rafael Nicolas Fermin Cota, 'San Francisco, CA. USA www.rnfc.org 'nfermincota.hba2005@ivey.ca '************************************************************************************ '************************************************************************************ 'FUNCTION : TRINOMIAL_TREE_OPTION_DELTA_FUNC 'DESCRIPTION : PLAIN_VANILLA_TRINOMIAL_DELTA 'LIBRARY : DERIVATIVES 'GROUP : TRINOMIAL 'ID : 002 'AUTHOR : RAFAEL NICOLAS FERMIN COTA 'LAST UPDATE : 01/29/2009 '************************************************************************************ '************************************************************************************ Function TRINOMIAL_TREE_OPTION_DELTA_FUNC(ByVal DELTA_SPOT As Double, _ ByVal SPOT As Double, _ ByVal STRIKE As Double, _ ByVal EXPIRATION As Double, _ ByVal RISK_FREE_RATE As Double, _ ByVal DIVIDEND_YIELD As Double, _ ByVal VOLATILITY As Double, _ ByVal nSTEPS As Long, _ Optional ByVal OPTION_FLAG As Integer = 1, _ Optional ByVal EXERCISE_TYPE As Integer = 0) 'SPOT: Underlying asset current price. 'STRIKE: Price at which the underlying can be bought (for calls) or 'sold (for puts). 'EXPIRATION: Maturity scaled on an annualized basis 'RISK_FREE_RATE: The cost of funds for the number of days to MATURITY 'It should corresponds to the period to the record date, not the option MATURITY 'DIVIDEND_YIELD: Yield paid on the underlying asset matching 'the option's MATURITY. 'VOLATILITY: Annualized volatility of the underlying asset price 'nSTEPS --> Number of nSTEPS (e.g. One-month intervals) 'OPTION_FLAG: 1 for call, and -1 for put. 'EXERCISE_TYPE: 0 For European, else For American Dim ATEMP_MATRIX As Variant Dim BTEMP_MATRIX As Variant On Error GoTo ERROR_LABEL ATEMP_MATRIX = TRINOMIAL_TREE_OPTION_PRICE_FUNC(SPOT + DELTA_SPOT, STRIKE, _ EXPIRATION, RISK_FREE_RATE, DIVIDEND_YIELD, VOLATILITY, nSTEPS, OPTION_FLAG, EXERCISE_TYPE) BTEMP_MATRIX = TRINOMIAL_TREE_OPTION_PRICE_FUNC(SPOT, STRIKE, _ EXPIRATION, RISK_FREE_RATE, DIVIDEND_YIELD, VOLATILITY, nSTEPS, OPTION_FLAG, EXERCISE_TYPE) TRINOMIAL_TREE_OPTION_DELTA_FUNC = (ATEMP_MATRIX(LBound(ATEMP_MATRIX, 1), LBound(ATEMP_MATRIX, 2)) _ - BTEMP_MATRIX(LBound(BTEMP_MATRIX, 1), LBound(BTEMP_MATRIX, 2))) / DELTA_SPOT Exit Function ERROR_LABEL: TRINOMIAL_TREE_OPTION_DELTA_FUNC = Err.number End Function