Advanced Excel Workshop

advertisement
Advanced Excel
Workshop
Monte Carlo Simulation
Page 1
Contents
Monte Carlo Simulation Tutorial .................................................................................................................... 2
Example 1: New Marketing Campaign ..................................................................................................... 2
VLOOKUP ............................................................................................................................................................. 5
Example 2: Revenue Forecast ..................................................................................................................... 6
Pivot Table ............................................................................................................................................................... 8
Macros ....................................................................................................................................................................... 9
Regression Analysis .......................................................................................................................................... 10
Important Formulas: ........................................................................................................................................ 11
Contact Information
Scott Bardwell
smbard@bu.edu
Page 2
Monte Carlo Simulation Tutorial
The Monte Carlo Simulation derives its name from the Monte Carlo Casinos. The same
gamble that you would take in the casino is used as a way to determine possible outcomes
of varying scenarios. Only with the Monte Carlo Simulation, you can make thousands of
gambles to calculate varying statistical data for scenarios such as rate of return on your
investments, potential product demand, revenue growth, or yield to maturity.
In this tutorial, we will use the simulation to calculate the outcomes of two different
scenarios: revenue forecasts, and the expected net present value of a marketing campaign.
Example 1: New Marketing Campaign
Suppose your firm is figuring out whether or not to spend $400,000 on a new marketing
campaign. The campaign is expected to bring in extra revenue over a five-year period. The
first year will bring in an extra $100,000, while the year after that will bring in the prior
year’s $100,000 plus 10% growth with a standard deviation of 0.1. Each year after that will
add a 10% growth with a standard deviation of 0.1 to prior year’s campaign revenue
number. What is the NPV (net present value) of the marketing campaign if the firm has a
discount rate of 12%? Should you accept the campaign?
Steps:
1. The information above is organized in the Excel document. Open the worksheet
titled “New Marketing Campaign.”
a. Cells C9 through F9 show how to calculate the growth rate.
b. Cells C10 through F10 show how to calculate the expected revenue from the
campaign year after year.
2. Monte Carlo Simulations rely on the Excel function RAND() to calculate expected
sales growth.
a. This function produces a random number between 0 and 1 each time you
press the keystroke F9 (recalculate).
b. For this exercise, we will use the function NORMSINV(RAND()), which
returns a random z-score with a normal distribution.
3. The formula for the expected growth rate is:
growth rate + [ standard deviation * NORMSINV(RAND()) ].
Page 3
a. Multiplying NORMSINV(RAND()) with the standard deviation returns a
random increase or decrease in the growth rate of the standard deviation.
b. In this exercise, the growth rate is 10%, and can be found in cell B4. The
standard deviation (σ = 0.1) is in cell B5. Our formula is :
= 10% + [0.1*NORMSINV(RAND())]
c. In Cell C9, insert the formula: =$B$4+$B$5*NORMSINV(RAND())
i. Using the bottom right corner of cell C9, drag to the right until cell F9.
You now have an expected growth rate for each year. The rate will
change each time you press recalculate (F9).
4. We will use the expected growth rate to obtain the expected revenue for each year.
To do this, multiply the prior year’s revenue (assume the first year has a guaranteed
$100,000 in revenue) by the calculated growth rate.
a. In cell C10 insert the formula: =B10*(1+C9)
b. Using the bottom right corner of cell C10, drag to the right until cell F10. You
now have an expected amount of revenue for each year. The expected
amount of revenue will change each time you press recalculate (F9).
5. The next step is to calculate the NPV of our expected revenue stream.
a. Use the =NPV formula in cell C13 to input the discount rate and the revenue
stream. We must also subtract the cost of the campaign in cell B2.
b. The formula is: =-B2+NPV(B3,B10:F10)
c. We now have an NPV of the project that will change each time we press
recalculate (F9)
6. Looking at a larger number of the randomized NPVs will give us a better idea of the
bigger picture. We can do this by using data tables.
a. First, we need to label the number of data points we will use. Enter the
number “1” into cell A14.
i. From the HOME tab, press the Fill button on the right.
ii. Select the Series… option.
iii. Select Columns and make the stop value 500. Press OK.
iv. You should now see a descending list of the numbers 1-500.
b. Highlight cells A13:B513.
Page 4
i. From the DATA tab, click What-If Analysis, and select Data Table.
ii. Leave the Row input cell blank. For the Column input cell, pick a cell
that is empty and will remain empty. For this exercise, pick cell B1.
Press OK.
iii. You should now see 500 corresponding NPVs that change each time
you press recalculate (F9).
7. Use the Data Analysis tool to determine statistics such as the Mean, Standard Error,
Median, Standard Deviation, and Range.
a. From the DATA tab, click Data Analysis and scroll to Descriptive Statistics
and press OK.
b. Highlight cells B14:B23 as the input range. Check the box Summary
Statistics and press OK.
i. You now have descriptive statistics for those 10 data points.
However, what’s great about using Monte Carlo Simulations is that we
can get a more accurate picture by using more data points.
c. Repeat this process, this time using all 500 of the data points created earlier.
You now have statistics that are reflective of a larger number of possibilities.
Note the differences between the two summary statistics, especially the
much smaller standard error.
8. Should we accept the marketing campaign project? If the NPV equals zero, we can
assume that the expected revenue will cover the initial cost. The mean NPV we
calculated is greater than 0, so we can confidently accept the marketing campaign
project since the company will most likely recoup its investment. However, note
that the Minimum NPV obtainable is a negative number, meaning that there will be
situations in which the marketing campaign is not worth the initial investment.
Page 5
VLOOKUP
Before proceeding to the next Monte Carlo Simulation example, it is important to
understand VLOOKUP. VLOOKUPs (vertical lookups) search for a value in the first column
of a table and return a value from the same row in another chosen column of the table.
We will use VLOOKUP to quickly search for how many total medals a country won in the
most recent Winter Olympics.
Steps:
1. Go to the worksheet “VLOOKUP.” You will see data from the 2014 Winter Olympics.
2. We will use cells D2 and E2 to search for how many total medals a country won.
The country in question will be in D2 and E2 will be the VLOOKUP formula.
3. VLOOKUP(lookup_value,table_array,col_index,[range_lookup])
a. The lookup_value is the value you’re searching for in the first column of
your data array. For this exercise, the lookup_value is D2.
b. The table_array must be two or more columns of data – the values in the
first column are the values searched by the “lookup value.” For this exercise,
the table_array is cells A6:E31.
c. The col_index refers to which column in the table array the matching value
will be found. For this example, our col_index is 5 because the number we
want to return is from the fifth column, Total.
d. The range_lookup specifies whether you want Excel to find an exact match
or an approximate match to the lookup_value. It can be true / blank
(returns an exact or approximate match) or false (returns an exact match).
e. VLOOKUPs require that the first column of your table array is sorted in
ascending order. If that is not possible, use false as your range_lookup.
4. Sort your data into ascending order by Column A.
5. In cell E2, type =VLOOKUP(D2,A6:E31,5)
6. Now, whatever country that you type into D2 will return a total medal count in E2.
While this may not seem useful for this amount of data, imagine the potential for
tables with thousands of data entries.
Page 6
Example 2: Revenue Forecast
Suppose your firm is trying to calculate the amount of revenue that can be expected in the
following year. You have a good idea of the amount of demand for your company’s product,
and know the corresponding dollar sales that would occur. You decide to use a Monte
Carlo Simulation to forecast the average amount of dollar sales your company can expect.
1. The above information is organized in to the Excel worksheet. For this exercise, use
the worksheet titled “Revenue Forecast Template.”
2. Use the function RAND() in cell G4 to create a random number between 0 and 1.
Notice that it changes each time you press recalculate (F9).
a. Type “=RAND()” in cell G4.
3. Now we have to organize the demand probabilities to work with the RAND()
function. This is done by creating a range for each demand probability.
a. In cell A4, type the number 0. In cell A5, type the number 0.05.
i. This creates a range so that if the RAND() produces a number
between 0 and 0.05, it will be associated with $100,000 sales forecast.
ii. We now need to create the ranges for the remaining sales forecasts by
entering in Column A the cumulative demand probability for each
sales forecast.
1. Cell A6 – add the demand probability (0.20) to the number in
A5 (0.05) to get the cumulative demand probability (0.25). In
cell A7, add the demand probability of 0.4 to the prior 0.25. In
Cell A8, add the demand probability (0.3) to the prior 0.65.
b. This is done to produce a randomly generated sales forecast based on the
demand probabilities. The lowest forecast of $20,000 has a probability of 5%
and the RAND() has a 5% probability of generating a number between 0.95
and 1, thus connecting the two. In the next step we will use a VLOOKUP to
link the RAND() function with the demand probabilities.
4. The VLOOKUP function returns the sales forecast that is associated with the
randomly generated number in G4.
a. Remember the syntax of the function is this:
Page 7
VLOOKUP(lookup_value,table_array,col_index,[range_lookup])
i. For this exercise, the lookup_value is the randomly generated number
in cell G4.
ii. For this exercise, the table_array is cells A4:C8.
iii. For this example, our col_index is 3 because the number we want to
return is in the third column of our highlighted table (Column C).
iv. The first column in the table array is already sorted in ascending
order, so we can leave the range_lookup blank.
b. Enter the information for your VLOOKUP in cell H4.
5. The next steps are to create a Data Table with a large number of entries, and to run
summary statistics on the table to determine a likely sales forecast.
a. Create the Data Table by typing 1 in cell A13, and type “=H4” into cell B12.
i. Create a table with 500 entries – refer to the Marketing Campaign
example for the steps – to create 500 sales forecasts for the year.
b.
Run Summary Statistics on the Data Table to determine the average
revenue, standard error, median, mode, and standard deviation.
i. Refer to the Marketing Campaign example for steps.
The average sales forecast hovers around $60,000. However, because this is not a normal
distribution, the sales forecast is actually a little lower than the most probable sales.
Page 8
Pivot Table
Pivot Tables help to organize and summarize your data. Open up the worksheet titled
“Pivot Tables.” I have included 2013/2014 basketball statistics in the template. These
include data for conference, division, team, and wins/losses. Suppose you want to organize
the data so that you can see the wins/losses of the entire conference of by each division.
This can be done using pivot tables.
Steps:
1. Highlight the entire table of data.
2. Click the INSERT tab on the ribbon and click on PivotTable all the way on the left.
Click Existing Worksheet at the bottom of the pop-up window, make the location
cell H1, and press OK.
3. All the way on the right of the new worksheet are all of your PivotTable options. We
will be looking at the Fields section. Check each box in the order of largest to
smallest (Conference, Division, Team) and then check the Wins and Losses boxes.
The Pivot Table now shows a summary of how many wins and losses each conference has,
each division has, and each team has. The Division and Conference are collapsible to hide
either the Teams or Divisions, respectively.
Page 9
Macros
Macros are a way to create shortcuts for frequently done actions. For example, if you found
that you needed to highlight certain numbers, a certain color, or sort data in a specific way
frequently, you might want to record a macro for performing this task. The recorded
macro is attached to a shortcut key and can be easily used again. Please note that macros
are not reversible using Excel’s Undo button.
Steps:
1. Since you are already in the worksheet titled “Pivot Table Basketball,” we will use it
to create a macro for creating a regular table.
2. Click the DEVELOPER tab in the ribbon.
3. Click Record Macro on the left. A popup window will appear
4. Name the Macro “Table” and assign the shortcut key Ctrl + Shift + N. It is very
important to assign a shortcut key that is not already used by a previous Macro or
another Excel shortcut key. Save the Macro in this Workbook and press OK.
5. It is very important that you do not do anything unnecessary while recording a
macro. Each step you take is being recorded and attributed to the shortcut key.
6. In the worksheet, highlight the basketball data and the headers (disregard anything
to do with the pivot table, we only want to use the data now).
7. Click the INSERT button on the ribbon and click Table on the left side.
8. Now on the table, sort the teams by their Wins from greatest to least.
9. Now that we are done with our table, go back to the DEVELOPER tab and click Stop
Recording on the left.
10. Now go to the worksheet titled “Hockey Standings”
11. Press Ctrl + Shift + N
12. You should see the same organized table for your hockey data as the table you
manually made for your basketball data.
Page 10
Regression Analysis
For this exercise, we will be using a regression analysis to calculate Apple’s (AAPL) beta. In
finance, the beta is how closely the share price of a company moves with the price of the
broader market price. In our example, we use the price of Apple and the S&P500. The
regression analysis allows us to compare 60 months of changes in price between Apple and
the S&P500 to determine how closely related they are. A beta of 1 means that the
company’s share price moves perfectly in tandem with the broader market’s share price.
1. For this exercise, use the worksheet titled “Regression Analysis.”
2. The past 60 months of share prices have been download from Yahoo! Finance and
are listed on the worksheet.
a. We need to determine the percentage change for each month in order to
compare Apple to the S&P500.
b. Click on cell C4 and insert the formula: =(B4-B5)/B5
c. Now change cell C4 to a percentage and drag it all the way down to cell C63.
d. Repeat the process for cell E4 to obtain the monthly percentage change in
price for the S&P500.
3. Now that we have the two varying percentage changes, we can run the Regression
Analysis Tool.
a. Click on the DATA tab and click on Data Analysis all the way on the right.
b. On the pop-up screen, scroll to Regression and click OK.
c. Make the Input Y Range the monthly percentage change in Apple stock price
and make the Input X Range the monthly percentage change in the S&P500’s
price. Press OK
4. In the new worksheet, the X Variable is the beta. The number should be 1.01. This
shows that Apple’s share price moves very closely with that of the S&P500’s.
Page 11
Important Formulas:
Formula
=RAND()
Description
A random number
between 0 and 1
=NORMSINV(RAND())
Returns a random zscore around a
standard normal
distribution
=NPV(rate,value1,value2,…)
Calculates the net
present value of an
investment
=VLOOKUP(lookup_value,table_array,col_index,[range_lookup]) Searches for a value in
the first column of a
table array and returns
a value in the same
row from another
column
Download