1
votes

I want to calculate the time to expiration on a few call options using newton's method. I tried recreating this method in the code below. I get an odd type mismatch for the variable called functionDerived. This variable is the derived form of variable function0. The error 13 occurs at that point.

The variables in the calculation are the following types:

opT integer;
S double;
sigma double;
K double;
rf double;
q double;
T integer;
optionbidprice double;

Here is my code:

Public Function calculateOptionExpiration(opT, S, sigma, K, rf, q, T, optionBidPrice)

'************************************************************************
'Variables
'************************************************************************

Dim function0 As Double
Dim functionDerived As Double
Dim optionPrice As Double
Dim differenceZero As Double

Dim Tnext As Integer

Dim Pii As Double
Dim d1 As Double
Dim d2 As Double
Dim ND1 As Double    'Cumulative standard normal probability for value d1
Dim ND2 As Double    'Cumulative standard normal probability for value d2
Dim Nd1accent As Double  'Derivation, N'(x), see book page 456
Dim Nd2accent As Double




'************************************************************************
'Newton's method to calculate time to option expiration T
'************************************************************************

'theta formula page 456, use this in newton's method

'Step 1: f(T) = 0

    Pii = Application.WorksheetFunction.Pi


    d1 = BSD1(S, K, rf, q, T, sigma)

    d2 = BSD2(S, K, rf, q, T, sigma)


    ND1 = Application.NormSDist(d1)

    ND2 = Application.NormSDist(d2)

    Nd1accent = (1 / Sqr(2 * Pii)) * Exp(-d1 ^ 2 / 2)

    function0 = ((-S * Nd1accent * sigma * Exp(-q * T)) / (2 * Sqr(T))) + _
    (q * S * ND1 * Exp(-q * T)) - (rf * K * Exp(-rf * T) * ND2)


'Step 2 : f'(T)

    Nd2accent = (1 / Sqr(2 * Pii)) * Exp(-d2 ^ 2 / 2)

    functionDerived = (q / 2) * (S * Nd1accent * sigma * Exp(-q * T) * 2 ^  (-1) * T ^ (-3 / 2)) _
     - q * (q * S * Nd1accent * Exp(-q * T)) + rf(rf * K * Exp(-rf * T) + Nd2accent)



'step 3: Tnext = T - function0/functionderived, find the T so that option bid - optionprice = 0


Do Until differenceZero = 0

    optionPrice = BSMOptPrice(opT, S, sigma, K, rf, q, T)

    differenceZero = optionBidPrice - optionPrice

    Tnext = T - (function0 / functionDerived)

    T = Tnext

Loop

    calculateOptionExpiration = Tnext
1
Is this part in the assignment of functionDerived really correct: rf(rf * K * Exp(-rf * T) + Nd2accent)? It looks as if you are attempting to call a function rf() while you mention above that rf is a double. - bovender
That was indeed the issue. Thank you! - Jolien .A
@bovender- you could make your comment the answer. - Davesexcel
@Jolien.A would you be so kind and accept my answer so I can earn me some reputation? Thanks. - bovender

1 Answers

0
votes

This part in the assignment of functionDerived was incorrect:

rf(rf * K * Exp(-rf * T) + Nd2accent)

rf(...) is a function call, but the parameter rf is a double, so that's the type mismatch.