Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

MATH377: Financial and Actuarial Modelling in R

Tutorial 1

Exercise 1. Write an R code to determine the result of the following computation:

eπ  log2 (10) +  −3  .

Exercise 2. Without using R, determine the result of the following logical computation

((!(4  ==  3)  |  (abs(-3)  <=  2)) &  ((2^2  > 4) &  (TRUE)))  |  ((!FALSE  |  (4+2)  ==  5) &  (0.5  >=  (1/2))) Verify your result by typing the code in R.

Exercise 3. Find the errors in the following lines of code:

a)

2  +         3  *4  +  sqrt[100]

b)

(2  +  i)   /  3   +  {1e1  + 4.0i}

c)

time.To.Maturity  <-  6

Interest.rate  <-  0.05

{1e-0  +  interest.rate}^{-time.To.Maturity}

Exercise 4. Without using R, determine the result of the following computation:

x  <-  c(1,  2,  3)

x[2]  /  x[2]^2  -  1  +  3  *  x[3]  -  x[2  -  1]

Verify your result by typing the code in R.

Exercise 5. Write an R code to calculate the amount of money owed after n years, where n varies from 1 to 10 in yearly increments, assuming that the money lent originally is 2350 and the interest rate remains constant throughout the period at 5%.

Exercise 6. Consider the vector 1:N, where N is a positive integer. Write an R code that determines how many elements in the vector are exactly divisible by 4. Test your code with N  <- 40.

Exercise 7. Create a vector containing the following student grades: 70, 80, 55, 67, 90, 92, 83, 74, 100, 87, 49. Using logical operators and vector functions, answer the following question:

a) What is the average grade of the whole group?

c) What is the average grade of those students with grades between 60 and 80 (including 60 and 80)?

 

Exercise 8. Write an R program to compute the alternating harmonic series

 

2     3     4              X      n      ,

up to a finite number of summands N. Test your code with N = 100 and compare with log(2).


Exercise 9. The function cov() computer the sample covariance of two vectors. Recall that for two vectors x = (x1, . . . , xn) and y = (y1, . . . , yn) the sample covariance is given by

Cov(x, y) =  X(xi − )(yi − y¯)

Write an R program to compute the sample correlation without using the cov() function. Test your code with the following vectors:  x  <-  c(1,  2,  3, 4) and y  <-  c(2,  2,  3,  5).  Verify your result using cov(x, y).