MATH377: Financial and Actuarial Modelling in R Tutorial 1R

Java Python MATH377: Financial and Actuarial Modelling in R

Tutorial 1

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

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% compounded annually.

Exercise 6.

a) Is there any difference between 10:6*3 and 10:(6*3)? Explain why. Compute all the multiples of 3 between 3 to 30.

b) Is there any difference between 10:4ˆ3 and 10:(4ˆ3)? Explain why. Compute the square of the numbers 10,. . . ,4.

Exercise 7. Consider the vector 1:N, where N is a positive integer. Write an R code that determines how m MATH377: Financial and Actuarial Modelling in R Tutorial 1R any elements in the vector are exactly divisible by 4. Test your code with N <- 40.

Exercise 8. 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?

b) How many students have grades less than 65?

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

d) Assume that we add three new students with grades 65, 98, 54. Repeat questions a)-c) with the new vector of grades.

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

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

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

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).

Exercise 11. Using only rep() and seq() (or :) as needed, create the vectors

a)

0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4

b)

1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5

c)

1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9

Hint: Look into the help of rep() (?rep). You will find that the argument times can be a vector and that there are additional arguments named each and length.out         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值