Introduction
The goal seek function is a very important tool in excel (it was also there in lotus). In large models the last thing you often do is to use a goal seek to make a bid on the model. I have wanted to make a goal seek function where you can make something like = SUM(…), but with =GOAL_SEEK(…). When you make a function, it can operate much faster than the classic method in excel and it can be used together with resolving a circular reference to make things speed up dramatically. I had tried this before AI but it was necessary to re-write the formulas in excel that go from the input that drives the goal seek (for example, the price), all the way to the end (for example, NPV). This was a complete pain before AI because you would have to write the formulas on a manual basis (for example, Revenues(period) = Price x Quantity(Period) and all of the other formulas down to NPV).
The power point slides include discussion of how AI can be used to compute a goal seek function that automatically computes something like the required price (the by changing) in the goal seek tool without stopping the model and to run the tool.
.
.
Bisectional, Newton Explanation
The two videos below explain the methods I use with macros and functions to program how a goal seek process works. I think there a few reasons to understand how the goal seek works. With a program to make the goal seek yourself you can eventually create a function that will work faster than the excel goal seek and you will be able to use the goal seek function to put into large models among other things. But if you ask AI to make a goal seek fuction, it will write something. If you do not understand how it should work, you have nothing but code that you do not understand.
In the first video, an engineer named Jeffrey explains how you can find a root, which means finding where the number in a function with x and y where the y goes to zero. In the context of financial analysis, this root is often where the NPV is equal to zero. Note that the x-axis would be the price to get the -axis NPV to zero. Jeffrey explains how the bisection method works by finding intervals and re-computing the NPV each time. When he makes a diagram with different values of x (the price), you can see how essential it is to start with a range that brackets the NPV. One price should give a negative NPV and another price must give you the postitive NPV. Then you can start with the low price and continue to bracket the NPV. You will iterate and move the high price lower. If the price gets too low and you are not bracketing the NPV, you must turn around. To compute the new bracket, you compute the average of the low price and the high price. You can find out if the average is a good bracket by making sure that NPV is negative because that means one NPV is higher than zero and the other is less than zero. If you are iterating and the NPV at the high range and the low range are the same, you have to turn around. That means the average should not be from the high value but it should be changed to the low value.
.
.
In the second video, our friend Jeffrey (who does not have publicity and does not beg for a like) discusses the Newton method. He expalins that you again need a starting point and then you iterate. He explains that the Newton method should converge faster than the bisection method. Jeffrey shows that even if you have a curved relationship (say between price and NPV), you can use the slope and intercept of a straight line to find the root, or in our case the point at which the NPV is equal to zero. Note that our friend (who does not beg for you to subscribe) tells you that you need a starting point. For our NPV and price example, you need two points and two start. If you have a price in your model, you can push the price up a bit and then push the price down a bit to get two prices. I have modified the method of Jeffrey because we may not be able to write out an equaton of the price relative to the NPV. You start Then you can compute the NPV for both prices and you have two points. He tries to find the square root of 2. He could start with the equation x squared = 2. If x squared = 2 then you have found the answer. For use, you can use the following:
- NPV => y
- Price => x
- With two points, find the slope and the intecept ==> y = Intercept + Slope * x
- Slope = (y – Intercept)/x or if you have two points (y1-y2)/(x1-x2)
- Root is where y or the NPV is zero. If you plug zero into the equation then Slope * x = – Intercept or
- x = – Intercept/Slope
- You can then use as a new x with the y = 0. After that you can continue to iterate
- The only question is other than this point, what should be the other point (it could be the one you started with)
- ..
.
.
Model without Goal Seek Functions
The two files below are designed to allow you to begin the process of analyzing the goal seek methods without any functions. The file I use as an example has some inputs for price, operating costs, capital expenditues and financing. I have used a relatively simple project finance model with a single construction period and no taxes so there are no circular references. The idea is to set the price in order to achieve an equity IRR. In the example, there is debt with either sizing from debt to capital or DSCR to make the goal seek process a little more complicated. Finally equity cash flow is computed and measured at a target equity IRR. The way this first file works is shown below. The InputC page demonstrates there are different debt structures and equity IRR targets and you want to derive the price for computing the IRR.
.

.
The next couple of screen shots illustrate the calculaton of IRR which is used as the basis for computing NPV with a goal seek, A basic goal seek function is computed using a macro from the NPV to make the NPV equal to zero.
.

.
The goal seek macro and a loop around the goal seek macro to put results back into the InputC page is shown in the screenshot below. You probably know how to do this, but you do not have to put any formulas around this goal seek formula. You certainly should use range names as shown in the code below. The second subroutine illustrates how you can create a loop that goes from 1 to the number of colums you have in your scenarios. You change the the scenario code number and then run the goal seek. Finally, the range is used together with the cells function to finish the job. This is of course fine for most problems, particularly if there is no circular references.
.

.
Initial File to Evaluate Goal Seek Function - Simple Model with Classic Goal Seek Macro with Loop
.
Slope Macro
A file where the equity IRR is computed from the price and different scenarios are computed is attached to the button below. If you want to practice all of the excercises in the videos, you can use this file. Other files illustrate subsequent steps in the process including translating the model equations to VBA using AI and adjusting the VBA with templates for using goal seek functions. The goal seek macro includes equations that show how the slope changes until the NPV equals zero is illustrated in the screenshot below.
In this slope method you need a starting point and then you iterate. In the macro I do this with the existing price that is input where for one point I use this point (the x) and then compute the NPV (the y). After that I increase the price a bit and re-compute the NPV. This gives you another x and y. This initial step is shown on the screenshot below after the graph. Once you see have developed the two points, you can compute the price or the root or the point where x = 0 as x = – Intercept/Slope.
Once you have the new price, you can test whether the slope and intercept give you an NPV of zero. If the NPV with the computed price is not zero, you try again with two new points. One of the points is the price you computed with and NPV is somewhat different from zero. Then you have to compute a second point. I have multiplied the price by a factor (1.5 in the case below). I do not know if there is a fancy way to adjust the second price). Once I do this, I try to make a graph of the changing graph with different slope and intercept.
.

.
The screenshot below demonstrates the initial computation of the two prices. In this case I put in a very low price and a very high price. When a macro is used, a range name gets the NPV from the calculations. Note that the model must be run twice. next, the low and high prices are used to compute the price result with two points. This is the function that is called Slope_and_Intercept().
.

.
If the result is not zero, then the last price is used, and another price must be used for the iteration.
.

.

.
Bisection Macro
Another macro is illustrated in the screenshot below for the bi-sectional method. The result table shows how the estimate moves up or down depending whether the resulting NPV is positive or negatives. When you press the macro button you can see how the price moves up and down depending on whether the prior NPV sign changes.
The macro for bisection is designed to find a root, which means finding the x-axis number that is zero. In the context of financial analysis, this root is generally where the NPV is equal to zero. the x-axis in a typical case could be the price to get the NPV to zero. The bisection method works by finding intervals and re-computing the NPV each time. You can see how essential it is to start with a range that brackets the NPV. One price should give a negative NPV and another price must give you the postitive NPV. Then you can start with the low price and continue to bracket the NPV. You will iterate and move the high price lower. If the price gets too low and you are not bracketing the NPV, you must turn around. To compute the new bracket, you compute the average of the low price and the high price. You can find out if the average is a good bracket by making sure that NPV is negative because that means one NPV is higher than zero and the other is less than zero. If you are iterating and the NPV at the high range and the low range are the same, you have to turn around. That means the average should not be from the high value but it should be changed to the low value.
The trick is how you push something up or push something down. If the result is negative, then make the next average of the last price and the high price so the NPV will be pushed up:
- If NPV is negative result, the next average for computing the NPV is the average of HIGH price and the last average
- If NPV is postive result, the next average for computing the NPV is the average of LOW price and the last average
.

.
The step of computing the goal seek with a macro rather than the excel goal seek tool is included in the file attached to the button below. This file include separate macros that work through how to compute the slope between two sets of points and iterate until a goal is reached. The second macro uses the bi-sectional method where the driver of the solution is pushed up or down until the goal is reached. You can run the macros and then look at the code.
.
File with Macros that Evaluate Goal Seek with Macros Rather than Using the Goal Seek Tool in Excel
.
Files with Goal Seek Functions
In this section I explain how you can compute the goal seek by yourself and how excel may be doing the calculations. As introduced in the two videos above, you can use the newton method which essentially creates a straight line with two points and then uses the line to find where it crosses the x-axis. For example, the x-axis can be the NPV and the y-axis can be the price. The point where the x-axis or NPV is zero gives you the price. If you use the target IRR for the NPV discount rate, the point at which the NPV is zero gives you the required price.
The third file which is attached to the buttons below demonstrates how you can compute the goal seek with functions. If you use functions you have to work through different formulas which is not necessary using the macro method above. The iteration process in the Newton method and the Bisectional method is similar, but unlike the process with a macro, you need to work through all of the equations between the driver of the goal seek (the by changing cell) and the result (the set cell). To create all of the equations between the changing cell and the set cell, you can use AI to replicate equations. For example, between the target (e.g. price) and the outcome (e.g. equity NPV). The AI functions are called by the Newton or the Bisectional functions. The functions change one variable in the model such as price.
.
.

.

.

.
Video on Goal Seek Functions
.
.