Produce an app that generate quotes for life annuities

Assignment Help Programming Languages
Reference no: EM132255280

Programming Project -

Instructions - The goal of this project is to produce an app that generate quotes for life annuities. This project is intended to be completed by each student individually.

Life Annuities - A life annuity is a stream of period payments that begin at a set time and continue for the rest of the beneficiary's life. For our purposes, we will assume that the payments are made annually. (In practice, payments are made monthly.) A life annuity is a model for a defined benefit pension plan with level benefits.

Since the actual number of payments is uncertain, the actual cost of a life annuity is a random variable. We can simulate the number of payments using the sample( ) function in a way that is similar to what you did in Lab 5 with unfair dice. The process works like this.

For a person of age a, the possible number of payments ranges from 0 to 119 - a (the maximum age in the table is 119). The probabilities assigned to these outcomes are the probability that the person dies at ages a through 119, assuming they are alive when they purchase the annuity. We can get these probabilities (that depend on gender) from a life table. The Social Security 2015 table is provided for you in LifeTable.csv. Next we look at how to use the information in the table.

The fields called "Male_lives" and "Female_lives" are the estimated number of 100,000 individuals born at the same time who are alive at the given age (say, on their birthday). You can use the diff function to determine how many of the original cohort are expected to die each year. This will be proportional to the probability that a member of the cohort dies in each year. To create a vector with the number of males who are alive each year beginning with age a, use lives <- LifeTable$Male_lives[(a+1):120] or the female version. Keep in mind that the table begins with age 0, so the index for age a is a+1.

To actually code this idea, you need to take two things into account:

  • The diff function will give you a vector with lives{k+1] - lives[k]. Since lives is decreasing with age [once a person dies, she stays dead], these values will all be negative. So, you actually want -diff(lives).
  • The diff function produces a vector that has length(lives) - 1. This will create a problem if you use the result as the probability parameter in sample( ). The solution is to add lives[120] to the vector: c(-diff(lives), lives[120]). In effect, you are saying that if anyone is alive at age 119, they will die in the next year. [You have the power to make this happen in a simulated world ... ]

If you want to convert this vector to probabilities, divide it by the number of lives at age a (= LifeTable$Male_lives[a+1], etc.).

Now, let's do something

Part 1 -

1. Write an r function, sim.lifeAnnuity, that generates n samples of the number of payments in a life annuity purchased by an individual at age a and gender g using the 2015 Social Security table. Use gender in c("Female", "Male"). The arguments are n, a and g. The function returns a vector of length n containing integers ranging from 0 to 119 - a. Test it on a few ages to see if it produces reasonable answers.

2. Use n = 100,000 and a = your age (and gender) to create some simulated output. Then make a histogram of the results, using the parameter probability = TRUE. Overlay the density plot using lines(density(x), col = "your favorite color" [put in the name of your output variable for x and an actual color name.] Does this curve look like any distribution you have seen before?

3. The insurer's cost will be the present value of the payments. In the context of the simulation, we know exactly how many payments are made. So, we can use a fixed annuity formula to evaluate the present value of each simulated annuity. R has a function in the FinCal package called pv.annuity(r, n, pmt, type). This is a vectorized function. If you make the n parameter a vector (of integer values), the result will be a vector of annuity values with n payments. Write a function called sim.pv.lifeAnnuity to simulate present values of a life annuity using this approach. Set pmt = -1 in pv.annuity. The arguments for your function are n, a, and g (as before) and interest rate r.

4. Run sim.pv.lifeAnnuity on the same input you used for problem 2 with r = .05. Create a histogram and density plot for the present values of your simulation. Does the shape of this density make sense in relation to the graph you produced in #2? Explain the change. It might facilitate the comparison if you put the graphs on the same page using par(mfrow=c(2, 1)) and align the x axes using the same xlim range for both. Use par(mfrow=c(1, 1)) to restore the default plot settings.

5. Compute the mean and median of the distribution of present values. Which one is higher? Using the function abline(v = c(mean(x),median(x)), col = c("green", "blue")), add vertical lines to your plot to visualize these statistics. Insurance rates are often based on the expected value of losses. Does that create any issues here? What would you recommend that the company charge for a life annuity?

6. In our course on life contingencies, you will learn a different way to calculate the expected value of a life annuity. The formula that applies there is: t=a+1119pt(1+r)-(t-a), where pt = probability that the subject is alive at time t. [The actuarial notation used is a little different because pt should also reflect the starting age, a. A symbol like apt might be better.] Write a function that calculates the actuarial expected value for a life annuity issued at age a, gender g, and interest rate r. Use the same Life Table data. [Hint: the formula can be written as the sum of p*v, where p is a vector of probabilities and v is of the form (1+r)^-(1:n). Here you want the probability that the person is alive at various times, so the probability vector (for males) will be proportional to LifeTable$Male_lives[(a+2):120], etc.]

7. Plot another vertical line on the plot you made in #5 the shows the actuarial present value. Compare the mean of simulated present values with the actuarial present value at several ages. What did you find?

8. To complete this project, you will write an app in R that prompts the user for some information and issues a quote for a life annuity. This code should be in a function called Quote.annuity that has no arguments. Here are some suggestions for writing this function:

  • Use variable_name <- readline("message") to prompt the user for input. This function reads input from the keyboard as type = character and stores it in variable_name. You may need to convert it to some other type.
  • You can use a while loop to keep offering to provide a quote until the user declines.
  • The first question (inside the loop) might be "Do you want an annuity quote? (Y/N)". If the response is a variable called Continue, set cond <- Continue %in% c("Y","y") as the condition in the while loop. If cond is false, print "Bye" and exit the loop with break().
  • Ask for a name.
  • Ask for date of birth in form mm/dd/yyyy.
  • Convert date of birth to a Date variable using as.Date (see text for more details).
  • Ask for gender (as m/f) and convert to the form needed for your annuity functions.
  • Ask for annual payment desired and convert to numeric.
  • Compute age from given date of birth. (Sys.date() will give you today's date.) Caution: the Date class measures the number of days from the starting point. So the difference in date values will be in days. You will need to convert that difference to years in order to get age. I suggest rounding age to the closest integer.
  • Compute expected value of the annuity (= payment*actuarial.pv).
  • Print the expected value (rounded to even dollars) with a message that includes the name. You can use the cat( ) function for this. Make sure to add "\n" to the end of the message to make sure it moves the cursor to the next line after printing this message.

Submit your file on Canvas to Project, part 1.

Part 2 -

The life table was provided in an Excel format. On a separate worksheet, create an input block to capture:

Name


Date of Birth


Gender


Annual payment


Compute the actuarial present value of the life annuity using the above information. You may want to set up a table that constructs the same vectors you produced in your R code. The VLOOKUP function may be helpful for extracting the values you need from the life table. Verify that your Excel code produces the same answer as your R code.

Submit this file on Canvas (Project, part 2).

Attachment:- Assignment Files.rar

Reference no: EM132255280

Questions Cloud

The design of a clinical database for your organization : As a DNP-prepared nurse, you may be called upon to assist in the design of a clinical database for your organization.
What is the goal of the brand campaign : What is the goal of the brand's campaign? Who is the intended target audience?
Determine the cardinality ratio : Determine the cardinality ratio for each intuitive relationship shown below, Example Answers: (1:1), (1,M), (M,1), (M,N) and explain why:
Cyprus to protect its monitory turkish population : Turkey invaded Cyprus to protect its monitory Turkish population, occupying approximately the northern third of the island nation.
Produce an app that generate quotes for life annuities : ACT 394 Programming Project - The goal of this project is to produce an app that generate quotes for life annuities
How the identified telehealth technology can be used : Telehealth encompasses a wide range of basic to complex health care delivery options, with an equally expansive array of technologies to employ.
Display an image that has a border of size : Can someone help me to create these HTML documents / images please:
In the attribution leadership model : In the Attribution Leadership model, to what does low consensus refer? which of House’s four leader behaviors could you perform least well?
Write methods in java for a program : Your task is to write methods in JAVA for a program that analyzes an arbitrary number of strings passed as arguments on the command line

Reviews

Write a Review

Programming Languages Questions & Answers

  Create a solution that allows manager to enter up food items

Create an object-oriented solution that allows the restaurant manager to enter up to 10 food items. An error message must display if the manager tries to enter more than 10 food items.

  Implement a lexical and syntax analyzer

Implement a lexical and syntax analyzer based on the following grammar. Your analyzer should read an input test program from a file and then determine if it contains a syntax error. It does not have to show where the syntax error occurs or what ki..

  Write loop header to hold odd number between a range

Suppose the int variables i and result have been declared but not initialized. Write down for loop header, that is something of form.

  Calculates the total number of votes received by a candidate

Calculates the total number of votes received by a candidate - the function updateVotesByRegion (of the class candidateType) updates only the number of votes for a particular region.

  Modify the inventory program by creating a subclass

Modify the Inventory Program by creating a subclass of the selected product's class that uses one additional unique feature of the product that has been selected for you. You must use the subclass name and additional unique feature

  Write spark program that load data and analyze data quality

Write a Spark program that loads the data, analyzes data quality, provides a summary report, and reports your findings, abc is an eCommerce company

  Write application layer protocols to permit through firewall

As part of your own planning process, write the application layer protocols which you would permit through the firewall, those you would block and your reasons for doing so.

  Write function that produces a stream prime numbers

Write a function that produces a stream of positive prime numbers . Use that stream to create a list of the product of all pairs of consecutive prime numbers up to a given value.

  Draw a line joining the first two points

Write a program that allows the user to specify a triangle with three mouse presses - Draw a line joining the first two points. After the third mouse press, draw the entire triangle.

  Calculate the annual cost of owning the car.

Programming Assignment - Car Cost Calculator. Calculate the annual cost of owning the car. How much money was spent of gas

  Use that function to output each line of the countdown

Write code to create a web page that uses a JavaScript program to output a NASA style count down:

  Provide summary of the program and version of the program

Provide summary of the program and version of the program you are using. Design that reveals to the reader how your information is organized.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd