In-class exercises for August 23
Introduction
As discussed in the first lecture, a simple model for your children’s college fund is the difference
equation
𝑥𝑗+1=(1+𝑟)𝑥𝑗+𝐴, (1)
where 𝑥𝑗is the size of the fund at the start of year 𝑗,𝑟is the annual rate of return, and 𝐴is your
annual contribution. Conceptually, we imagine that you contribute 𝐴dollars on Dec. 31 of year 𝑗
and the interest is credited all at once on the same day.
Download the Matlab file collegefund.m from the Files tab on the course Canvas page. (You
may wish to create a separate folder for in-class exercises and point Matlab to it.) You can run
the file either by opening the file in the Editor and pressing the green Run button or by typing
collegefund into the command window. Either way, you should see a plot of 𝑥𝑗versus year 𝑗,
𝑗=0,1,2, . . . , 18. Under the assumptions in the Matlab file (no money initially, 3% annual rate
of return, and $3,000 contributed annually), you should see that the account will contain about
$70,000 after 18 years.
Practice problems
Practice problems are intended for your personal investigation and in-class discussion. They are
not graded, and you do not need to turn them in.
1. Modify the collegefund.m script to try different rates of return and annual contributions to
get an idea of what combinations yield a total of $250,000 after 18 years.
2. Suppose that, instead of a fixed rate of return, you invest the money in an index fund whose
yield equals that of the Standard & Poor’s 500 index. The file sp.txt, which you can download
from the Files tab on Canvas, contains historical rates of return of the S&P 500 from 1928
to the present as provided by www.macrotrends.net, expressed as percentages. (Negative
values correspond to years in which the stock market fell.) Read the data with the command
sp = importdata(’sp.txt’);
(The semicolon suppresses a printout of all of the values, but you can omit it if you want to
see all the data on your screen.) Here sp is a 95×2 array whose first column contains the year
and the second contains the rate of return (as a percentage). Plot the data with the command
plot(sp)
(no semicolon necessary).
1
3. Of course, nobody can predict future returns of the stock market. Instead, the objective of
this modeling exercise is to get an idea of the range of outcomes that are possible under
certain assumptions. For this purpose, we will suppose that the next 18 years’ returns of the
stock market are similar to those that have been observed since 1928. One way to do this is
to generate a random shuffle of the observed returns, as follows:
n = size(sp, 1); number of years of data
ix = randperm(n); a random shuffle
plot(sp(:,1), sp(ix,2))
This plot command shows a random permutation of the S&P 500 returns since 1928. You
may wish to repeat these commands a few times to see different realizations. Notice how the
intervals of market increases and decreases are different each time.
4. The file randomfund.m, which you can download from the Files section, is an example of
a Matlab function (as opposed to a script). The function generates a vector yof length
trials; each element of yis one realization of the college savings plan where 𝐴dollars are
deposited each year, but the returns are a random selection of 18 years of observed S&P 500
performance. In this simulation, model (1) is modified to be
𝑥𝑗+1=(1+𝑟𝑗)𝑥𝑗+𝐴, (2)
where 𝑟𝑗is the rate of return in year 𝑗. You can generate 600 realizations of the college fund,
assuming contributions of 𝐴=$3,000 per year, with the command
y = randomfund(sp, 600, 3);
Here sp is the list of S&P 500 returns that you obtained in Problem 2. (You must run the
importdata command before you run randomfund; otherwise, you will get an error message
about an undefined variable.) Each element of yis the value of the fund, in thousands of
dollars, for one particular random shuffle of stock market returns. The commands min(y),
max(y), and mean(y) return the range and mean of outcomes. What are they? (Note: you
will get slightly different answers each time you run randomfund. You may wish to see how
much the values vary each time you run the function. Feel free to investigate the effects of
different choices of 𝐴, too.)
5. The command
histogram(y)
generates a histogram of the returns. The horizontal axis gives a range of account values, and
the vertical axis gives the frequency. (In my simulations, the horizontal axis divides the fund
values into $25,000 ranges.) Based on your simulations, what is the most frequently observed
outcome, assuming contributions of $3,000 per year? (In other words, what $25,000 range
of account values is most likely, under the assumptions of the previous problem?)
2
6. The command
z = sort(y);
returns a sorted list, in ascending order, of the simulated account values. Which two elements
of zlet you determine the range of account values that are observed 2/3 of the time? After
18 years, how likely are you to have less money than you contributed?
Homework problems
Due date: Tuesday, Aug. 30. Upload a PDF file of your answers to Canvas. You may create a
Matlab Live record of your work, or you may cut-and-paste Matlab results into a word-processed
document. Either way, save your work as a PDF file. This assignment is worth 20 points (5 points
per problem). You may turn in a joint paper with up to two other people; each of you will receive
the same grade. Please be sure to put each of your names on the paper.
1. Modify the model (2) to reflect an initial contribution of $3,000 per year that increases by
5% per year. Write down the resulting equation.
2. Edit the randomfund script to reflect your revised model and run it 600 times. Include a
printout of your revised function.
3. Generate a histogram of the results and perform a simple statistical analysis as in Problem 6
above.
4. Imagine that you are a financial planner and are talking to a pair of new parents who want to
start a college fund for their child. What advice would you give them?
3