R Programming Exam: Instructions
R Programming Exam: Instructions
20/09/2020
Instructions
The exam consists on writing an R script following the instructions. At the beginning of your R script, you
should write the following commands:
NIS <- # YOUR STUDENT ID NUMBER
set.seed(NIS)
Each problem requires creating an R object with a specific data structure. The object should be assigned to a
symbol A1 for problem 1, A2 for problem 2, and so on.
Example:
Problem 1: Create a 2 x 2 identity matrix. The output should be a 2x2 matrix.
Problem 2: Create the “hello world!” function. The output should be a function.
Your full R script should read
NIS <- # YOUR STUDENT ID NUMBER
set.seed(NIS)
# Problem 1
A1 <- diag(2)
# Problem 2
A2 <- function() print('hello world!')
You must assume that the data files are placed in the same directory as your R script.
Submission instructions You must save your R script with the name exam_[YOUR NIS].R. For example,
if your student number is 12345, the file must be named exam_12345.R. You must submit your exam script
as an attachment to this assignment.
Problems
1
Problem 3: Interpret the previously generated matrix as the returns of 3 different assets recorded during
100 days, and use it to compute the minimum variance portfolio. Recall that this is a 3 x 1 vector
S−1 1
w= ,
10 S−1 1
where S−1 is the inverse of the sample covariance matrix of the data and 1 is a 3-dimensional vector of ones.
Note that if you do this correctly, the sum of the entries should be equal to 1.
The output A3 must be a 3 x 1 matrix.
Problem 4: Simulate the process
where S is the price of the underlying asset, K is the strike price, M is the time to maturity, N (·) is the
standard normal cumulative distribution function, σ is the volatility, and r is the risk-free rate.
The output A9 should be the function C.
Problem 10: Suppose that S = 100, r = 0, and σ = 1. For each strike price in {80, 90, 100, 110, 120} and
time to maturity in