32 Savings Simulations

In this chapter we present a fairly simple example in financial math in which we apply some of the programming concepts covered so far.

32.1 Do you regularly save some money?

How much do you tend to save, and how often? A dollar per day? A few dollars per week? Maybe a few hundred dollars per year?

For what purpose(s) do you save? For traveling and vacations? For entertainment? For your retirement? To buy a house?

Where do you keep/invest (some of) your savings? Obviously this is a tricky question and the answer heavily depends on your savings goals.

The overarching aim of this chapter revolves around the following question:

If you were to save some of your annual income for a number of years, how much money could you expect to accumulate under different saving-investing cases (ignoring inflation)?

Some Considerations

In this chapter we will write code in R to simulate a handful of relatively basic savings investing/scenarios (ignoring inflation).

From the analytical point of view, you will practice writing functions, as well as implementing control flow structures such as conditionals and loops.

We will write functions using Roxygen comments to document what the function does (@title, @description), its parameters (@param), and the expected output (@return).

We won’t use functions from any Finance (or other external) R packages.

32.2 Future Value Function

Suppose you want to invest $1000 in a financial product (e.g. Savings Account, Money Market, Certificate of Deposit) that has an annual return rate of 5%. And you will keep this investment for 10 years. How much money would you expect to get at the end of this period? To answer this question, you can use a simplified version of the Future Value formula, assuming compound interest. Here are the ingredients: • $$\text{PV}$$ = present value amount (i.e. how much you invest) • $$r$$ = annual rate of return • $$t$$ = time (in years) • $$\text{FV}$$ = future value (i.e. what you’ll get) $\text{FV} = \text{PV} (1 + r)^t$ For example, investing $$\text{PV} = \1000$$ in an index fund that, on average, has an annual return rate of 5%, at the end of the first year, you would have: $\1000 (1 + 0.05)^1 = \1050$ If you keep those$1050 invested, at the end of the second year you will have:

$\1050 (1 + 0.05)^1 = \1102.50$

In 10 years, your initial $1000 investment will become: $\1000 (1 + 0.05)^{10} = \1628.895$ 32.2.1 Function future_value() Write a function future_value() that computes the future value of an investment, taking the following arguments • amount: initial invested amount • rate: annual rate of return • years: number of years You should be able to invoke future_value() as follows: future_value(amount = 100, rate = 0.05, years = 1) future_value(amount = 500, rate = 0.05, years = 5) future_value(amount = 1000, rate = 0.05, years = 10) 32.3 Future Value of Annuity Let’s make things a bit more interesting. Suppose that each year you decide to save$200, and deposit this amount into an account at the end of the year. Assuming that this account has a 5% rate of return, how much money will you get at the end of 10 years?

To answer this question, you can use a simplified version of the Future Value of Annuity formula. Here are the ingredients:

• $$\text{C}$$ = contribution (i.e. how much you deposit at the end of each year)
• $$r$$ = annual rate of return
• $$t$$ = time (in years)
• $$\text{FVA}$$ = future value of annuity (i.e. what you’ll get)

$\text{FVA} = \text{C} \left [ \frac{(1 + r)^t - 1}{r} \right ]$

For example, you begin saving $$\text{C} = \200$$ at the end of the first year. At the end of the second year, you will have:

$\200 \left [ \frac{(1 + 0.05)^2 - 1}{0.05} \right ] = \410$

At the end of 10 years your balance will be:

$\200 \left [ \frac{(1 + 0.05)^{10} - 1}{0.05} \right ] = \2515.579$

32.3.1 Function annuity()

Write a function annuity() that computes the future value of annuity, taking the following arguments

• contrib: contributed amount
• rate: annual rate of return
• years: number of years

You should be able to invoke annuity() as follows:

annuity(contrib = 200, rate = 0.05, years = 1)
annuity(contrib = 200, rate = 0.05, years = 2)
annuity(contrib = 200, rate = 0.05, years = 10)

32.4 Future Value of Growing Annuity

Let’s keep making things a little bit more complex. Suppose that, instead of saving a fixed amount of $200 each year, you expect to increase this amount by 3% each year, and deposit this amount into an account at the end of the year. Assuming that this account has an annual rate of return of 5%, how much money will you get at the end of 10 years? To answer this question, you can use a simplified version of the Future Value of Growing Annuity formula. Here are the ingredients: • $$\text{C}$$ = first contribution (i.e. how much you deposit at the end of year 1) • $$r$$ = annual rate of return • $$g$$ = growth rate • $$t$$ = time (in years) • $$\text{FVGA}$$ = future value of growing annuity (i.e. what you’ll get) $\text{FVGA} = \text{C} \left [ \frac{(1 + r)^t - (1 + g)^t}{r - g} \right ]$ In this case, at the end of 10 years your balance will be: $\200 \left [ \frac{(1 + 0.05)^{10} - (1 + 0.03)^{10}}{0.05 - 0.03} \right ] = \2849.782$ 32.4.1 Function growing_annuity() Write a function growing_annuity() that computes the future value of growing annuity, taking the following arguments • contrib: contributed amount • rate: annual rate of return • growth: annual growth rate • years: number of years You should be able to invoke growing_annuity() as follows: growing_annuity(contrib = 200, rate = 0.05, growth = 0.03, years = 1) growing_annuity(contrib = 200, rate = 0.05, growth = 0.03, years = 2) growing_annuity(contrib = 200, rate = 0.05, growth = 0.03, years = 10) 32.5 Investing Modalities In this part of the assignment we’ll consider three savings-investing modes: 1. future value of$1000 (no annuity)

2. future value of $1000 with$200 annuity

3. future value of $1000 with$200 growing annuity

In mode 1, you invest $1000—at the beginning of the year—at an annual rate of return of 5%, during 10 years (without any other annual contribution). $\text{FV}(\1000) = \1628.895$ In mode 2, you begin with an initial investment of$1000—at the beginning of the year—at an annual rate of return of 5%, but you also decide to contribute a fixed amount of $200 at the end of every year. Assume an investment period of 10 years. Hint: it can be shown that at the end of ten years your balance will be: $\text{FV}(\1000) + \text{FVA}(\200) = \1628.895 + \2515.579 = \4144.474$ In mode 3, you begin with an initial investment of$1000—at the beginning of the year—at an annual rate of return of 5%, but you also decide to contribute a growing amount of $200 at the end of every year, growing at 3% every year. Assume an investment period of 10 years. Hint: it can be shown that at the end of ten years your balance will be: $\text{FV}(\1000) + \text{FVGA}(\200) = \1628.895 + \2849.782 = \4478.677$ 32.5.1 For-loop and Table Write one or more for() loops to compute the annual balances of each savings-investing modality. You can use any type of objects (vectors, matrices, lists, data.frames, etc) to store the values of these balances. The ultimate goal is to create a data frame called modalities, containing the annual balances in each modality (see diagram below). And display your data frame modalities. INSERT IMAGE (investing modalities) 32.5.2 Timeline Graph With the data obtained for each savings modality, make one graph, with lines as geometric objects, that allows you to compare the growth of these investment modes over the 10-year period. Make sure your graph follows standard recommendations: title, axis labels, axis scales, background, legends, colors, visual attributes, etc. 32.6 Savings Simulation The last part of this assignment involves a simple simulation taking into account different financial products, with “typical” rates of return. In this simulation we’ll consider three financial products available to most consumers: a) regular savings accounts, b) high-yield savings accounts, and c) index mutual funds. 1. Regular Savings Accounts: these are the traditional savings accounts offered by most banks. For illustration purposes, here’s some of the annual rate of returns offered in this type of accounts (as of 03/07/2019): • Chase Savings = 0.01% • Wells Fargo Savings = 0.01% • Bank of America Savings = 0.03% • Citibank Savings = 0.15% 2. High Yield Savings Accounts: these have to do with less traditional savings accounts offered by most online banks. For illustration purposes, here’s some of the annual rate of returns offered in this type of accounts: • Marcus by GS: 2.25% • Synchrony Bank: 2.25% • Ally Bank: 2.20% • Capital One: 2.00% 3. Low Cost Index Mutual Funds: an alternative investment product has to do with mutual funds. We will take into account a specific type of mutual fund: low-cost index funds that track the US stock market. For illustration purposes, here’s the average annual rate of returns offered by the following funds (since their inception date): • Vanguard Total Stock Market Index Fund (VTSAX): 6.62% • Fidelity Total Market Index Fund (FSKAX): 6.91% • Schwab Total Stock Market Index Fund (SWTSX): 5.87% 32.6.1 Simulation Variables In order to carry out the simulations, use the following specifications: • Initial investment amount of$10,000
• Investment period of 15 years

Three savings-investment modalities previously considered:

• future value with no other annual contributions.
• future value with fixed annual contributions (annuity) of $2,000 at the end of every year. • future value with annual growing contributions at 4% (growing annuity), starting with$2000 at the end of year 1.

Likewise, we will assume the following rates of return:

• regular savings: 0.10%
• high-yield savings: 2.25%
• index fund: 6.5%

32.6.2 Foor Loops

Use for() loops to compute the annual balances of each combination of savings-mode and financial product (see table below). In other words, you will have to perform a total of: $$9 \text{ combinations}= (3\text{ modalities} \times 3 \text{ financial products})$$.

INSERT IMAGE (simulation combinations)

32.6.3 Facet Timeline Graph

Make at least one faceted graph to display the timelines of the nine different savings scenarios (see a hypothetical example below; you can experiment with other versions). Likewise, make sure your graph follows standard recommendations: title, axis labels, axis scales, background, legends, colors, visual attributes, etc.