Abstract
In this workshop we will learn how to write functions to solve problems related to time value of money and bond valuation.You will work in RStudio. It is strongly recommended to have the latest version of R and RStudio. Once you are in RStudio, do the following.
Create an R Notebook document (File -> New File -> R Notebook), where you have to write whatever is asked in this workshop. More specifically, you have to:
Replicate all the R Code along with its output.
You have to do whatever is asked in the workshop. It can be: a) Responses to specific questions and/or do an exercise/challenge.
Any QUESTION or any STEP you need to do will be written in CAPITAL LETTERS. For ANY QUESTION, you have to RESPOND IN CAPITAL LETTERS right after the question.
You have to keep saving your .Rmd file, and ONLY SUBMIT the .html version of your .Rmd file. Pay attention in class to know how to generate an html file from your .Rmd.
Regarding Challenge 1 of previous workshop, you have to find a peer and share your attempt. Improve your attempt with this feedback. If you solved the problem with an analytic formula, change the solution writing a loop.
Now modify your solution and write your code as a function. As any function, you need inputs, which are also called parameters of the function. Inside your function you need to process the inputs and then end up with an output or a set of outputs as results. It is said that each function also **returns* the values of the output.
For this challenge the inputs are:
Loan amount
Annual percentage rate
Frequency of annual compounding (we set as 12 a year, since we used months)
Fixed payment per period
The outputs have to be:
Number of periods needed to fully pay the loan
The amount of the last payment
Once you finish your function, test it with at least 2 different set of inputs, run your function and display your results.
For each of the following challenges, you need to include the following:
At the beginning of the challenge you need to WRITE YOUR GENERAL APPROACH to solve the challenge. You have to use CAPITAL LETTERS. Your general approach is the logic you will follow to solve the problem (at least 1 paragraph for the general approach). In addition, you must include a SEQUENCE OF STEPS needed to get the input(s) and end up with the correct output(s).
Write your R code in R chunks, and use the # character in the chunk to briefly document as comments what your lines of code do
You have to show/print the value(s) of the result of each challenge
An investor purchasing a special Bonus from the UK Government is entitled to receive annual payments from the Government forever. What is the price of the bonus that pays $1,500 US annually if the next payment occurs one year from today? The market interest rate is 12%
Find the bond value of the following 2 exercises:
The $1,000 face value if bond XYZ has a coupon rate of 6%, with interest paid semi-annually, and matures in 5 years. If the bond is priced to yield 8%, what is the bond’s value today?
The ABC bond has a 8% coupon rate (with interest paid semi-annually), a maturity value of $1,000, and matures in 5 years. If the bond is priced to yield 6%, what is the bond’s current price?
You have to write one FUNCTION to solve these 2 problems.
The HIJ bond has a current price of $800, a maturity value of $1,000, and matures in 5 years. If interest is paid semi-annually and the bond is priced to yield 8%, what is the bond’s annual coupon rate?
You have to write a function to solve this problem.
You are planning to save for retirement over the next 30 years. To do this, you will invest $6,000 a month in a stock account and $3,000 a month in a bond account. The return of the stock account is expected to be 12% compounded monthly, and the bond account will pay 5% annual interest rate also compounded monthly. When you retire, you will combine your money into an account with a 9% annual return. How much can you withdraw each month from your account assuming a 25-year withdrawal period? At the end of 25 years your balance must be zero.
Hint: check if you can use the functions you wrote in the previous challenges to solve this challenge.
You have to take (view and do the exercises) of the following chapters of the following datacamp courses:
Course 1: Intermediate R for Finance, complete chapter 4: “Functions”
Course 2: Bond Valuation and Analysis in R, complete chapter 2: “Yield to maturity”
Course 3: Bond Valuation and Analysis in R, complete chapter 3: “Duration and Convexity”
You have to submit your .html file of this workshop through Canvas BEFORE NEXT CLASS.
The grade of this Workshop will be the following:
Remember that you have to submit your .html file of your workshop.