You are on page 1of 2

Newton-Raphson Method in Excel VBA

Newton’s Algorithm
Newton's algorithm, alternately called the Newton-Raphson method, is The above is the simpler method of interpretation, but the statement
a numerical method for solving equations of the type f(x)=0. It has f(x) = mx+c is actually derived from the more generalised Taylor's
numerous applications in finance, and we will use it to determine the series expansion where a continuous, differentiable function f may be
volatility surface for a call option using the Black Scholes formula. expanded about a point c as follows: f(x) =f(c)+f'(c)(x-c)+f''(c)/2!*(x-
c)^2+...
The method applies when we have a close approximation for a
solution to the equation. The method assumes that the tangent to the This is the univariate version of the Taylor expansion, but it will suffice
graph at our approximation intersects the x-axis closer to the solution for finding, for example, volatility smiles since we assume that all other
of the equation, i.e. closer to where the line we are evaluating variables remain constant.
intersects the x-axis. By solving for where the tangent intersects the x-
axis, and repeating the process from that point, we get closer and Since the equation is linear, no second order derivatives exist so
closer to the actual solution of the equation. these fall away, leaving
f(x) =f(c)+f'(c)(x-c). In our example, x0=c, giving y = f'(x0)(x-x0) + f(x0)
Let's say we're at our approximate solution, x0. The value of y-axis at
this point is y = f(x0). The equation of the intersection of the tangent with the y-axis is given
by the following:
We know that the tangent has gradient f'(x) - the same gradient as the 0 = f'(x0)(x1-x0) + f(x0)
line, from the definition of a tangent.
We then solve for x1
We also know that a univariate linear function takes the form f(x) = mx x1 = x0 - (f(x0)/f'(x0)
+ c, where m is the gradient, x is the horizontal displacement from the
starting point, and c is the vertical displacement from the starting From this we can induce (though actual proof is out of scope here),
point. As such, we have y = f'(x0)(x-x0) + f(x0) as the line of the that
tangent. We solve this for y = 0 in order to get the next guesstimate of xn+1 = xn - f(xn)/f'(xn) , which is the formula for Newton's method.
the solution to f(x) = 0.
The formula for Newton's method works in cases where the function is
differentiable, and where the gradient is not equal to zero.

1 Nyasha Madavo, Exceltasks Ltd


Newton-Raphson Method in Excel VBA
VBA implementation of Newton's algorithm Function func(x_n) As Double

Here is an implementation of Newton's algorithm for a simple function, func = x_n ^ 2 - 3


f(x) = x2 - 3.
End Function
For the volatility surface version, func(x_n) will be replaced by the
Black Scholes VBA pricing function, and func_dash(x_n) will be Function func_dash(x_n) As Double
replaced by the VBA function for calculating vega, the first derivative
of the option price with respect to volatility.
func_dash = 2 * x_n
Function Newton(Seed As Double, Precision As Double) As Double
End Function
Dim x_next As Double, x_n As Double, error_val As Double
Dim ctr As Integer

x_n = Seed
ctr = 0

Do

x_next = x_n - func(x_n) / func_dash(x_n)


error_val = x_next - x_n
x_n = x_next
ctr = ctr + 1

Loop Until (Abs(error_val) <= Precision Or ctr = 1000)


Newton = x_next
End Function

2 Nyasha Madavo, Exceltasks Ltd