Tuesday, September 2, 2008

Weighted Average Calculations in Microsoft Excel

There are many analyses you will undertake that will require the need to calculate a weighted average instead of a simple average, and there are a few different methods by which to do so. This article will first define the concept and then illustrate the methods used to calculate the correct answer. Once you understand the shortcut that Excel provides in determining the result, you will likely not return to the longer, more cumbersome approach.

First, what is a weighted average ("WAVG")? The WAVG uses a parameter, like market capitalization or shares traded, to modify a simple average calculation. As an example, let's assume that you have five data points that are stock prices: $3.00, $4.00, $4.50, $5.00 and $5.50. If these are the closing prices over the last five trading days, the average price over this period would be $4.40. But, if we assume that these prices were intraday prices, we could say that the average price for the day was $4.40. This is misleading, however, as it does not consider the volume of shares at each trade. The volume at the time of each trade provides a clearer picture of what the market thinks of valuation. The calculation used to weight these trades is the volume weighted average price ("VWAP") and is a common practice in private capital transactions involving equity or equity-linked securities, like convertible debt (note that VWAP and WAVG are calculated in the same fashion, and I use VWAP to illustrate a real life application).

In keeping with the prior example, let us assume that we have volume information associated with the prices as follows: 1,000 shares, 1,500 shares, 1,000 shares, 10,000 shares and 500 shares. You can see from the data that many more shares traded at $5.00 – 71.4% of the total daily volume to be exact. How does one incorporate that information to determine the VWAP? There are two approaches for doing the calculation: the step-by-step method or the SUMPRODUCT method.



Assume that in the first column of your spreadsheet contains the stock prices and the next column contains the shares traded at each price. The step-by-step approach would dictate that you create two new columns: weighting and contribution. The weighting column would contain the result of that day's shares divided by the total shares traded for the day for each of the data points. For example, the weight for the $4.00 price would be 10.7% (1,500 divided by the total shares traded that day of 14,000 shares). Once you have the weightings completed, you can do the contribution column, which would be the weighting value multiplied by the actual stock price. In the $4.00 example, you would take the 10.7% and multiply by $4.00, yielding $0.43 – the contribution to the total VWAP. Summing the contribution column yields the VWAP, which, in this case, is $4.73, higher than the simple average of $4.40. The result would indicate that the actual value of this stock is closer to $4.73 than $4.40.



To avoid the need for two additional columns, Excel provides the SUMPRODUCT function. The form of this function is =SUMPRODUCT(array1,[array2],[array3]….). This formula takes an array (row or column) and multiplies it by one or more other arrays of the same size. To calculate the VWAP from our prior example, all you would need is =SUMPRODUCT(prices,volume)/total volume. This would result in the same answer as above, $4.73. The answer is calculated without the additional columns. When you look at the formula and break it down, you can see that it takes the form of (A x B)/C, which can be rewritten as A x (B/C). The B/C component is the same as the "weighting" column described in the step-by-step approach, with A being the stock price used in determining the "contribution" column in the former method.

Finally, you can also utilize an array method to calculate the VWAP using the form of ={SUM((prices)*(volume))/total volume}, which is entered using ctrl+shift+enter. You can clearly se that 1) this is not much of a time saver and 2) SUMPRODUCT is similar to this form. I only show this to illustrate that there are several ways to accomplish the WAVG calculation, and depending upon space, modeling skill or other personal factors, you can use whichever works for you. I recommend minimization of superfluous data and err towards using the functionality contained in the Excel formulas, and would use SUMPRODUCT over the lengthier method.

Sunday, August 17, 2008

MATCH Function in Microsoft Excel

Excel offers a function for finding specific data in column or row called MATCH. This function will allow you to find the location within an array, versus the LOOKUP functions that provide information related to the data you are seeking but in another column or row (you can use the LOOKUP function to return values in the same column or row, but the MATCH function shortens it a bit).

The format of the MATCH function is:

=MATCH(lookup_value,lookup_array,match_type).

The lookup_value is the item you want to find within the lookup_array, like finding "apple" in a range of fruits or "green" in a list of colors. The match_type can be 1, 0 or 1. If the match_type is left blank, then it is assumed to equal 1. By using 1, MATCH will return the exact value or the value that is the largest value less than the specific item for which you are searching. In this case, the array must be in ascending order. Conversely, using -1 will provide he value that is immediately larger than the item for which you are searching, if no exact value exists. If you use -1, the array must be in descending order. If the match_type is 0, only an exact match is accepted, and if no exact match is available, #N/A! is returned. With match_type set to 0, the array can be in any order.

The order is important, because the 1 or -1 is dependent on how the data is presented. If, for example, you have a range of data in a non-sequential order, you will get the wrong answer. Let's assume that the array contains the following data:

1, 4, 7, 2, 21, 14, 5, 32, 6.

If you enter the formula =MATCH(6,{1, 4, 7, 2, 21, 14, 5, 32, 6}), you will get the answer 2. Clearly there is a number 6 at the end of the array, but because it is not an exact search and the data is not in order, the MATCH formula produces an answer you do not want. If you modify the formula to read =MATCH(6,{1, 4, 7, 2, 21, 14, 5, 32, 6},0), the answer will be 9, which is the correct location. So remember that for a NON-exact search, the order is imperative.

Once I learned to better incorporate the lookup functions, the MATCH function lost its relevance for many applications. In addition, when counting and summing, the array multiplication formulas work much better, and I will be discussing that in later articles. The point is that MATCH is good for a very limited set of basic inquiries, but ultimately, it is likely easily replaced by LOOKUP or other means. For now, it is a decent way to familiarize with the methodology Excel uses.

Finally, another formula used to determine the exact match that the MATCH formula uses, is, not surprisingly, EXACT. The format for this formula is = EXACT(text1,text2). This formula is not case sensitive, and straightforward in construct. This is another formula that is not entirely useful in most instances, because the double equal sign (= =) accomplishes the same result. For example, =EXACT(A1,B1) is the same as the formula =A1= = B1. Thus, the latter is as easy to use as the actual EXACT formula. The only rationale for mentioning this formula is to remind you that there are a myriad of formulas Excel provides, but some that may never be used or are easily replaced by better, more flexible formulas. The more experience you have in financial modeling, the more easily you will understand which formulas are the appropriate to use under the specific circumstances of your model.

Sunday, August 10, 2008

SEARCH and FIND Functions in Microsoft Excel

There are two very similar functions in Excel to look for data inside of cells matching parameters that you dictate: SEARCH and FIND. There are so similar, in fact, that one wonders why have two separate functions that perform virtually the identical results and are identical in the construct of the formula. This article will discuss he one, basic difference.

SEARCH Introduction

The SEARCH function is a way to find a character or string within another cell, and it will return the value associated with the starting place. In other words, if you are trying to figure out where a character is within the cell that contains a word, sentence or other type of information, you could use the SEARCH function. The format for this function is:

=SEARCH("find_text","within_text",start_num).



If, for example, the word "alphabet" was in cell C2, and your model needed the location of the letter "a" in that cell, you would use the formula =SEARCH("a",C2,1), and the result would be 1. To continue this simplistic example, if you were seeking the location of "b" in the word, the formula would be =SEARCH("b",C2,1), and the result would be 6. You can also use search on strings of characters. If, for example, cell F2 contains 1023-#555-A123, the formula =SEARCH("A12",F2,1) would yield the 11 as an answer.

FIND Introduction

The FIND function is another way to find a character or string within another cell, and it will return the value associated with the starting place, just like the SEARCH function. The format for this function is:

=FIND("find_text","within_text",start_num).

Using the same example as before, the location of the letter "a" in cell C2 would be discovered using =FIND("a",C2,1), and the result would be 1. Looking for "b" in cell C2 would be accomplished be =FIND("b",C2,1), resulting in the number 6. Finally, continuing on the similarity path, if cell F2 contains 1023-#555-A123 (as before), the formula =FIND("A12",F2,1) would yield the 11 as an answer. As you can see, up to this point, both methods would give you the same results.

Note: You probably quickly recognized that there are two a's in the word located in cell C2. By stating the starting point in each of the formulas as 1, we will pick up the first instance of the letter "a". If we needed to choose the next instance, we could merely have the "start_num" part of the formula to be 2, thus skipping the first instance of the letter and resulting in an answer of 5.

Main Differences

The main difference between the SEARCH function and the FIND function is that FIND is case sensitive and SEARCH is not. Thus, if you used the formula =SEARCH("A",C2,1) (note the capital "A"), the result would still be 1, as in the case before. If you were to use the formula =FIND("A",C2,1), you would get #VALUE!. FIND is case sensitive and there is no "A" in the word "alphabet".



Another difference is that SEARCH allows for the use of wildcards whereas FIND does not. In this context, a question mark will look for an exact phrase or series of characters in a cell, and an asterisk will look for the beginning of the series of characters right before the asterisk. For example, the formula =SEARCH("a?p",C2,1) in our alphabet example would yield an answer of 1, as it is looking for an exact grouping of the letter "a" with anything next to it with a "p" immediately after. As this is in the beginning of the word, the value returned is 1. Continuing with the alphabet example, the formula =SEARCH("h*t",C2,1) would yield a value of 4. In this instance, the wildcard "*" can represent any number of characters in between the "h" and the "t" as long as there is a string beginning and ending with the two letters you use in the formula. If the formula was =SEARCH("h*q",C2,1), you would get #VALUE!.

In short, these two formulas are very similar, and unless you need confirmation of an exact character or string of characters, you would likely err on the side of using SEARCH. Instances where this may not be the case might involve searches involving specific SKUs or names of employees. In my experience, SEARCH has been more helpful in specific financial modeling exercises, but it is helpful to understand the differences in usage and results as you work through your own modeling projects.