HW 4: Programming StructuresHW 4: Programming StructuresStat 133, Fall 2022“Compound interest is the eighth wonder of the world. He who understands it,earns it . . . he who doesn’t . . . pays...

1 answer below »

Say you are going to invest $1000 in a
Certificate of Deposit
for 2 years, obtaining an annual


return of 2%. How much money will you have at the end of 2 years?


The answer to this question can be obtained with the following formula:




HW 4: Programming Structures HW 4: Programming Structures Stat 133, Fall 2022 “Compound interest is the eighth wonder of the world. He who understands it, earns it . . . he who doesn’t . . . pays it.” Quote attributed to Albert Einstein General Instructions In this assignment you will write code in R to simulate a handful of relatively basic savings investing/scenarios (ignoring inflation). • Write your narrative and code in an Rmd (R markdown) file. • Name this file as hw4-first-last.Rmd, where first and last are your first and last names (e.g. hw4-gaston-sanchez.Rmd). • Include a code chunk at the top of your file like the one in the following screen capture: • You will have to create some functions in this assignment. All functions must have Roxygen comments (e.g. @title, @description, @param, @return). • You are NOT allowed to use functions from any Finance (or other external) R packages. • You will also have to include the math equations (using latex syntax) in your report. • Submit your Rmd and html files to bCourses. To work on the last problem (num 4), we are assuming that you’ve read the tutorial Investment Simulations, available in bCourses (link below) https://bcourses.berkeley.edu/courses/1516876/files/folder/readings?preview=84322485 1 https://bcourses.berkeley.edu/courses/1516876/files/folder/readings?preview=84322485 1) Future Value (with compound interest) Say you are going to invest $1000 in a Certificate of Deposit for 2 years, obtaining an annual return of 2%. How much money will you have at the end of 2 years? The answer to this question can be obtained with the following formula: FV = P ( 1 + r k )nk (1) where: • FV = future value (amount accumulated) • P = principal (how much you start with) • r = annual interest rate (or annual rate of return) • n = number of years • k = number of compounding periods per year; e.g. yearly (k = 1), twice yearly (k = 2), quarterly (k = 4) and monthly (k = 12). 1.1) Function future_value() • Use the formula in equation 1 to write a function future_value(). • Give descriptive names to the arguments of the function. • Likewise, give default values to the arguments. • Don’t forget to include comments to document the arguments of the function. • Also, include the equation of Future Value in your report (with latex syntax). 1.2) Use future_value() to answer the following question Paul deposits $1,000 in a Certificate of Deposit for 3 years at 2.5% per year compounded annually. What will be the value of the money at the end of 3 years? 2) Future Value of Ordinary Annuity Mrs. Savingswood wants to save money for her daughter’s education. She plans to deposit $100 at the end of each month, for the next ten years, into a mutual fund that gives a 5% annual rate of return. How much money will Mrs. Savingswood have at the end of ten years? We can answer this question with the Future Value of an Ordinary Annuity formula: 2 https://www.investopedia.com/terms/c/certificateofdeposit.asp https://www.investopedia.com/terms/m/mutualfund.asp FV ordinary annuity −→ FV = PMT × ( 1 + r k )nk − 1 r/k (2) where: • FV = future value (amount accumulated) • PMT = periodic contribution made at the end of each period • r = annual interest rate (i.e. annual rate of return) • n = number of years • k = number of compounding periods per year; e.g. yearly (k = 1), twice yearly (k = 2), quarterly (k = 4) and monthly (k = 12). Notice that if r = 0 then: FV = PMT × nk 2.1) Function annuity() • Based on the formula from equation 2, write a function annuity(), that allows you to compute the future value of an ordinary annuity. • Make sure your function works with r = 0 • Give descriptive names to the arguments of the function. • Likewise, give default values to the arguments. • Don’t forget to include comments to document the arguments of the function. • Also, include the math equation of the future value of an ordinary annuity in your report (with latex syntax). 2.2) Use your function annuity() to find how much money Mrs. Savingswood will have at the end of 10 years. 3) Combo: Future Value and Ordinary Annuity Say you are going to start your investment with a lump-sum of $1000 in a U.S. total stock market index fund. Also, suppose you decide to make fixed periodic contributions, e.g. $30 at the end of each month, or $360 at the end of each year. If the annual rate of return is 3%, how much money would you expect to get at the end of a 10-year period? Or after 15 years? Or after 20 years? 3 https://www.thebalance.com/total-stock-market-index-funds-2466402 https://www.thebalance.com/total-stock-market-index-funds-2466402 To answer these questions, you can combine formula 1 for lump-sum future value, with formula 2 of ordinary annuity, that is: FV = P ( 1 + r k )nk ︸ ︷︷ ︸ future value + PMT ( 1 + r k )nk − 1 r/k︸ ︷︷ ︸ ordinary annuity 3.1) Investment table for a 10-year period Use your functions future_value() and annuity() to obtain a table (see diagram below) with the annual balance for this investment: • annual rate of return of 7.55% • initial investment of $1000 • contributions of $720 at the end of each year • total number of years: 10 year amount 0 1000.00 1 1795.50 2 2651.06 ... ... 10 etc initial investment end-year 1 end-year 10 Investment table for a 10-year period 4) Simulating Investing in a Total Stock Market index fund We are assuming that you’ve read the tutorial Investment Simulations, available at: https://bcourses.berkeley.edu/courses/1516876/files/folder/readings?preview=84322485 For this problem we are going to consider investing in a total stock market index fund, but unlike in the previous three problems, we are now going to assume variable annual rates of return. Like in problem 3, let’s suppose that you start your investment with a lump-sum of $1000 in a U.S. total stock market index fund, making periodic contributions to this fund, e.g. $360 at the end of each year. How much money would you expect to get at the end of a 10-year period? 4 https://bcourses.berkeley.edu/courses/1516876/files/folder/readings?preview=84322485 https://www.thebalance.com/total-stock-market-index-funds-2466402 For simulation purposes, and because annual rates of return when investing in the stock market fluctuate every year, we are going to assume a probability distribution on the rates of return. More specifically, we are going to assume that annual rates of return ry follow a normal distribution with mean µ = 10% and a standard deviation σ = 18%. ry ∼ N(µ = 10%, σ = 18%) With variable rates of return, we can no longer use the combo formula of future value of lump-sum and ordinary annuity (the one used in problem 3). Luckily, we can still do computations. Here’s a conceptual diagram illustrating the flow of the investment during the first three years, assuming annual contributions: 1000 0 1 1000(1 + r1) + 360 = amt1 year = 1 Annual return in year 1 r1 <- rnorm(1,="" μ,="" σ)="" initial="" amount="" amt0="" amount="" at="" the="" end="" of="" 1st="" year="" amt1="" (amt1)="" (1="" +="" r2)="" +="" 360="amt2" amt2="" annual="" return="" in="" year="" 2="" r2=""><- rnorm(1,="" μ,="" σ)="" 1="" 2="" year="2" 2="" 3="" year="3" (amt2)="" (1="" +="" r3)="" +="" 360="amt3" annual="" return="" in="" year="" 3="" r3=""><- rnorm(1, μ, σ) at the end of every year you contribute 360 amount at the end of 2nd year amount at the end of 3rd year … etc flow of the investment during the first three years 4.1) 50 simulations of a 10-year investment period write one or more for() loops to obtain 50 simulations of this kind of investment: • initial amount: $1000 • periodic contributions of $360 at the end of every year • total number of years: 10 • annual rates of return normally distributed: n(µ = 10%, σ = 18%) the ultimate goal is to create a tabular object containing the simulated investment amounts during a 10-year period, illustrated in the figure below 5 year sim1 sim2 … sim50 0 1000.00 1000.00 … 1000.00 1 1565.39 1507.79 … 1403.64 2 2281.84 1919.91 … 2333.03 ... ... ... ... ... 10 etc etc … etc initial investment end-year 1 end-year 10 simulation 1 simulation 50simulation 2 figure 1: hypothetical table with 50 simulations you can use either a data.frame, a tibble, or a matrix to store the values of these balances. display the first 3 columns of your table. 4.2) data visualization with the obtained simulations, make one graph that allows you to see timelines for every simulation. here’s a sketch of what this kind of graph could look like. what things would you add to the graph in order to improve the visualization of so many lines? make sure your graph follows standard recommendations: title, axis labels, axis scales, background, legends, colors, visual attributes, etc. 6 general instructions 1) future value (with compound interest) 1.1) function future_value() 1.2) use future_value() to answer the following question 2) future value of ordinary annuity 2.1) function annuity() 2.2) use your function annuity() to find how much money mrs. savingswood will have at the end of 10 years. 3) combo: future value and ordinary annuity 3.1) investment table for a 10-year period 4) simulating investing in a total stock market index fund 4.1) 50 simulations of a 10-year investment period 4.2) data visualization rnorm(1,="" μ,="" σ)="" at="" the="" end="" of="" every="" year="" you="" contribute="" 360="" amount="" at="" the="" end="" of="" 2nd="" year="" amount="" at="" the="" end="" of="" 3rd="" year="" …="" etc="" flow="" of="" the="" investment="" during="" the="" first="" three="" years="" 4.1)="" 50="" simulations="" of="" a="" 10-year="" investment="" period="" write="" one="" or="" more="" for()="" loops="" to="" obtain="" 50="" simulations="" of="" this="" kind="" of="" investment:="" •="" initial="" amount:="" $1000="" •="" periodic="" contributions="" of="" $360="" at="" the="" end="" of="" every="" year="" •="" total="" number="" of="" years:="" 10="" •="" annual="" rates="" of="" return="" normally="" distributed:="" n(µ="10%," σ="18%)" the="" ultimate="" goal="" is="" to="" create="" a="" tabular="" object="" containing="" the="" simulated="" investment="" amounts="" during="" a="" 10-year="" period,="" illustrated="" in="" the="" figure="" below="" 5="" year="" sim1="" sim2="" …="" sim50="" 0="" 1000.00="" 1000.00="" …="" 1000.00="" 1="" 1565.39="" 1507.79="" …="" 1403.64="" 2="" 2281.84="" 1919.91="" …="" 2333.03="" ...="" ...="" ...="" ...="" ...="" 10="" etc="" etc="" …="" etc="" initial="" investment="" end-year="" 1="" end-year="" 10="" simulation="" 1="" simulation="" 50simulation="" 2="" figure="" 1:="" hypothetical="" table="" with="" 50="" simulations="" you="" can="" use="" either="" a="" data.frame,="" a="" tibble,="" or="" a="" matrix="" to="" store="" the="" values="" of="" these="" balances.="" display="" the="" first="" 3="" columns="" of="" your="" table.="" 4.2)="" data="" visualization="" with="" the="" obtained="" simulations,="" make="" one="" graph="" that="" allows="" you="" to="" see="" timelines="" for="" every="" simulation.="" here’s="" a="" sketch="" of="" what="" this="" kind="" of="" graph="" could="" look="" like.="" what="" things="" would="" you="" add="" to="" the="" graph="" in="" order="" to="" improve="" the="" visualization="" of="" so="" many="" lines?="" make="" sure="" your="" graph="" follows="" standard="" recommendations:="" title,="" axis="" labels,="" axis="" scales,="" background,="" legends,="" colors,="" visual="" attributes,="" etc.="" 6="" general="" instructions="" 1)="" future="" value="" (with="" compound="" interest)="" 1.1)="" function="" future_value()="" 1.2)="" use="" future_value()="" to="" answer="" the="" following="" question="" 2)="" future="" value="" of="" ordinary="" annuity="" 2.1)="" function="" annuity()="" 2.2)="" use="" your="" function="" annuity()="" to="" find="" how="" much="" money="" mrs.="" savingswood="" will="" have="" at="" the="" end="" of="" 10="" years.="" 3)="" combo:="" future="" value="" and="" ordinary="" annuity="" 3.1)="" investment="" table="" for="" a="" 10-year="" period="" 4)="" simulating="" investing="" in="" a="" total="" stock="" market="" index="" fund="" 4.1)="" 50="" simulations="" of="" a="" 10-year="" investment="" period="" 4.2)="" data="">
Answered 6 days AfterOct 20, 2022

Answer To: HW 4: Programming StructuresHW 4: Programming StructuresStat 133, Fall 2022“Compound interest...

Mohd answered on Oct 27 2022
46 Votes
-
-
-
2022-10-27
Part 1 Say you are going to invest $1000 in a Certificate of Deposit for 2 year
s, obtaining an annual return of 2%. How much money will you have at the end of 2 years?
FutureValue <- function(p,r,n,k){
#FV = future value (amount accumulated)
#p= primary Investment
#r = annual interest rate (i.e. annual rate of return)
#n = number of years
#k = number of compounding periods
FV<- p*(1+(r/100*k))^(n*k)
return(FV)
}

FutureValue(1000,2,2,1)
## [1] 1040.4
Part 2: Mrs. Savingswood wants to save money for her daughter’s education. She plans to deposit $100 at the end of each month, for the next ten years, into a mutual fund that gives a 5% annual rate of return. How much money will Mrs. Savingswood have at the end of ten years?
annuity <- function(pmt,r,n,k){
#FV = future value (amount accumulated)
#PMT = periodic contribution made at the end of each period
#r = annual interest rate (i.e. annual rate of return)
#n = number of years
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here