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

ECMT2130: Financial econometrics

Solutions for tutorial 01

1    Excel optimisation

1. Newton-Raphson in Excel. See the supplied Excel spreadsheet for numerical solutions. Note the user of the built in Solver to “double check” the answer.

(a) The supplied function is f (x) = x4x2 x 3x + 2 which has a first derivative f / (x) = x8x x 3 and second derivative f // (x) = x8, which is negative, guaranteeing a single global maximum.  All derivatives thereafter, are zero.  The second-order Taylor- series expansion is approximating the function with a quadratic, and the function is a quadratic so the approximation turns out to be exact. The first and second derivative provide all the information we need about the curvature of the function, regardless of the initial value of x and the Newton-Raphson method adjusts the evaluation point to get to the extremum in one step under the assumption that the function is quadratic. This is why only one step is required, regardless of the starting value.

(b) The supplied function is f (x) = x4 +3x2 xx +2. It has 3rd and 4th order derivatives

so the second-order Taylor-series approximation to the function is no longer exact. This approximation causes the algorithm to require additional steps to reach the minimum.  Starting at -4, the algorithm took 9 steps.  Starting at 1, the algorithm took 6 steps. Note the second derivative is positive at the extremum, indicating that it is a minimum.

 

2    R assignment

See the solution script in the canvas module for coding details. Additional comments about the R assignment follow:

● An identity matrix is a square matrix with zeros off the main diagonal and ones on the main diagonal.  The trace of a square matrix is the sum of the elements along its main diagonal. Thus, the trace of a 10 · 10 identity matrix would be 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 10. In R we could compute this as:

identityMatrix  <-  diag(10)

traceOfIdentityMatrix  <-  sum(diag(identityMatrix))

Note that m is a matrix, that we have already generated earlier. diag(m) gets the vector that is the main diagonal of m. By summing it, we compute the trace of matrix m. 10 is just a scalar so sum(diag(10)) actually adds up all the elements of a 3 by 3 identity matrix. This does give the right answer, but only because the off-diagonal elements are all zero.

 The code to generate the mean of the vector should be:

mean(v)

We can compute this manually by summing and dividing by the number of rows in v and check that we get the same value:

mean(v)  ==  sum(v)/nrow(v)

It should return a value of TRUE to indicate that the two values are equal.

 The code to do a matrix multiplication of row 5 of m by v is:

m[5,]  %*%  v

Recall that matrix m has 2 dimensions.  Thus, we index into the matrix by rows, then columns. We want the 2nd row, so the index information is 2. The comma indicates that the next part of the indexing information is for another dimension, in this case columns. We want all columns so we specify no limitations on the chosen column indexes. That selects all columns. If we had instead just wanted the first 2 columns, we could have used m[23 1 : 2]. The snippet of code “1:2” creates a sequence from 1 to 2. Try it yourself. This

kind of sequence generation is often handy when working in R. For example a sequence from 1 to 100 would be “1:100”.