10.07.2015 Views

Statistics I Exercises

Statistics I Exercises

Statistics I Exercises

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Statistics</strong> I <strong>Exercises</strong>1. The general n × n Hilbert matrix has element (i, j) given by 1/(i + j − 1).(a) Write a function which gives the n × n Hilbert matrix as its output, for any positiveinteger n.(b) Are all of the Hilbert matrices invertible?(c) Use solve() and qr.solve() to compute the inverse of Hilbert matrices for n = 1 to10. Is there a problem?2. Let (x 1 , x 2 , x 3 , x 4 , x 5 , x 6 ) = (10, 11, 12, 13, 14, 15). Find the coefficients of the quintic polynomialp(x) for which (p(x 1 ), p(x 2 ), p(x 3 ), p(x 4 ), p(x 5 ), p(x 6 )) = (25, 16, 26, 19, 21, 20). Hint:the quintic polynomial p(x) = a 1 +a 2 x+a 3 x 2 +a 4 x 3 +a 5 x 4 +a 6 x 5 can be viewed as the matrixproduct of the row vector [1, x, x 2 , x 3 , x 4 , x 5 ] with the column vector [a 1 , a 2 , a 3 , a 4 , a 5 , a 6 ] ′ .Work out the matrix version of this to give [p(x 1 ), p(x 2 ), p(x 3 ), p(x 4 ), p(x 5 ), p(x 6 )] ′ .3. Create a 5 × 3 matrix X with elements drawn randomly from the uniform distribution on[0, 1].(a) Calculate H = X(X ′ X) −1 X ′ and the eigenvalues and eigenvectors if H.(b) Calculate the trace of H, and compare with the sum of the eigenvalues.(c) Calculate the determinant of H, and compare with the product of the eigenvalues.(d) Verify that the columns of X are eigenvectors of H.eigenvalues?What are the corresponding4. Obtain the 6 × 6 Hilbert matrix, and compute its eigenvalues and eigenvectors. Computethe inverse of the matrix. Is there a relation between the eigenvalues of the inverse and theeigenvalues of the original matrix? Is there supposed to be a relationship?5. Consider the following circulant matrix:⎡⎤0.1 0.2 0.3 0.4P = ⎢ 0.4 0.1 0.2 0.3⎥⎣ 0.3 0.4 0.1 0.2 ⎦0.2 0.3 0.4 0.1(a) P is an example of a stochastic matrix. Verify that the row sums add to one.(b) Compute P n for n = 2, 3, 5, 10. Is a pattern emerging?(c) Find a non-negative vector x whose elements sum to one and which satisfies P ′ x = x.Do you see any connection between P 10 and x?6. Consider the following matrix:⎡⎤0.1 0.2 0.3 0.4 0.0 0.0 0.00.1 0.1 0.1 0.1 0.1 0.1 0.40.2 0.2 0.2 0.2 0.2 0.0 0.0P =0.3 0.3 0.3 0.1 0.0 0.0 0.0⎢ 0.3 0.3 0.3 0.1 0.0 0.0 0.0⎥⎣ 0.3 0.3 0.3 0.1 0.0 0.0 0.0 ⎦0.3 0.3 0.3 0.1 0.0 0.0 0.0(a) P is an example of a stochastic matrix. Verify that the row sums add to one.(b) Compute P n for n = 2, 3, 5, 10. Is a pattern emerging?1


(c) Find a non-negative vector x whose elements sum to one and which satisfies P ′ x = x.Do you see any connection between P 10 and x?7. The“vec”operator stacks the columns of a matrix one underneath the other. I.e., if A = [a ij ],thenvec(A) = (a 11 , . . . , a m1 , a 12 , . . . , a m2 , . . . , a 1n , . . . , a mn ).Implement vec.8. For symmetric matrices, e.g. the supradiagonal elements are redundant. The “vech” operatorextracts the non-supradiagonal elements of an n × n matrix A as follows:vech(A) = (a 11 , . . . , a n1 , a 22 , . . . , a n2 , . . . , a nn ).Implement vech.9. The duplication matrix D n is defined as the unique matrix satisfyingD n vech(A) = vec(A)for all symmetric n × n matrices A, and can be used to recover a symmetric A from itsnon-redundant vech elements. Write a function returning D n for given n.10. Investigate the singular values of the duplication matrix D n .11. The elimination matrix L n is the unique matrix satisfyingL n vec(A) = vech(A)for all n × n matrices A. Write a function returning L n for given n.12. What is the singular value decomposition of L n ?13. Let A be an arbitrary m × n matrix. Clearly, vec(A) and vec(A ′ ) contain the same elements,but arranged in different order. Hence, there exists a unique mn × mn matrix K mn , thecommutation matrix, for whichK mn vec(A) = vec(A ′ ).Write a function returning K mn for given m and n.14. Investigate the singular values of the commutation matrix K mn .15. The 2-norm of a matrix A is defined as‖A‖ 2 = maxx≠0‖Ax‖ 2‖x‖ 2.How can ‖ · ‖ 2 be expressed in terms of the singular values of A? Implement ‖ · ‖ 2 .16. The condition number of a regular square matrix A is defined as κ(A) = ‖A‖‖A −1 ‖. If the2-norm is used, how can κ be expressed in terms of the singular values of A? Implement κ.17. Consider a linear system Ax = b for a regular matrix A. We are interested in estimating theeffect of changes in the rhs b on the solutions x. Show that the relative error in x does notexceed the relative error in b multiplied by the condition number of A, i.e.,‖∆x‖‖x‖≤ κ(A)‖∆b‖ ‖b‖where ∆b and ∆x are the changes in b and x, respectively. (The bound is rather pessimistic.)(Hint: note that ∆x = A −1 ∆b and ‖b‖ = ‖Ax‖ ≤ ‖A‖‖x‖.)2


18. How can the generalized inverse (Moore-Penrose inverse) of a matrix A be expressed in termsof its singular value decomposition A = UDV ′ ? Implement the Moore-Penrose inverse,providing a tolerance parameter tol controlling when singular values are regarded as zero.19. Write an efficient function wcptrace computing trace(A ′ diag(w)A) for given A and w.20. The density of the multivariate normal distribution with mean m and regular covariancematrix V is given bydet(2πV ) −1/2 exp(−(x − m) ′ V −1 (x − m)/2).Write a computationally efficient function dmvnorm computing the density for a given matrixx containing the points as its rows, m and V. (E.g., try exploiting the potential of theeigendecomposition of V .)21. Write a function rmvnorm for generating n random points (collected in a matrix with n rows)from the multivariate normal distribution with mean m and regular covariance matrix V forgiven n, m and V . (Hint: if ξ has a multivariate normal distribution with m and V , then η =V −1/2 (ξ −m) has a multivariate normal distribution with mean zero and identity covariance,i.e., the components of η are independent, identically distribution standard normal variates,which can be generated using rnorm.)22. Generate 1000 uniform pseudorandom variates using runif(), and assign them to vector U,using an initial seed of 19908.(a) Compute the average, variance and standard deviation of the values.(b) Compare the results with the true mean, variance and standard deviations.(c) Compute the proportion of the values of U that are less than 0.6, and compare with theprobability that a uniform random variable U is less than 0.6.23. Simulate 10 000 values of a Uniform(0, 1) random variable U 1 using runif(), and another10 000 values of a Uniform(0, 1) random variable U 2 . Assign these to U1 and U2, respectively.Since the values in U1 and U2 are approximately independent, we can view U 1 and U 2 asindependent Uniform(0, 1) random variables.(a) Estimate E(U 1 + U 2 ). Compare with the true value, and compare with an estimate ofE(U 1 ) + E(U 2 ).(b) Estimate var(U 1 + U 2 ) and var(U 1 ) + var(U 2 ). Are they equal? Should the true valuesbe equal?(c) Estimate P(U 1 + U 2 ≤ 1.5).(d) Estimate P( √ U 1 + √ U 2 ≤ 1.5).24. Suppose U 1 , U 2 and U 3 are independent uniform random variables on the interval (0, 1). Usesimulation to estimate the following quantities:(a) E(U 1 + U 2 + U 3 ).(b) var(U 1 + U 2 + U 3 ) and var(U 1 ) + var(U 2 ) + var(U 3 ).(c) E( √ U 1 + U 2 + U 3 ).(d) P( √ U 1 + √ U 2 + √ U 3 ≥ 0.8).25. Suppose a class of 100 writes a 20-question True-False test, and everyone in the class guessesat the answers.(a) Use simulation to estimate the average mark on the test as well as the standard deviationof the marks.3


(b) Estimate the proportion of students who would obtain a mark of 30% or higher.26. Simulate 10 000 binomial pseudorandom numbers with parameters 20 and 0.3. Let X be abinomial(20, 3) random variable. Use the simulated numbers to estimate the following:(a) P(X ≤ 5)(b) P(X = 5)(c) E(X)(d) var(X)(e) the 95th percentile of X (you may use the quantile() function)(f) the 99th percentile of X(g) the 99.9999th quantile of X.In each case, compare your estimates with the true values. What is required to estimateextreme quantities accurately?27. Consider the following function which is designed to simulate binomial pseudorandom variatesusing the inversion method:R> ranbin1


R> ranbin3


34. A simple electronic device consists of two components which have failure times which maybe modeled as independent exponential random variables. The first component has a meantime to failure of 3 months, and the second has a mean time to failure of 6 months. Theelectronic device will fail when either of the components fails. Use simulation to estimatethe mean and the variance of the time to failure for the device. Re-do the calculations forthe case where the device will fail only when both components fail.35. A χ 2 random variable with n degrees of freedom has the same distribution as the sum ofthe squares of n independent standard normal random variables. Simulate a χ 2 randomvariable with 8 degrees of freedom, and estimate its mean and variance. (Compare with thetheoretical values: 8 and 16.)36. The following function returns normal pseudorandom numbers:R> rannorm


+ max = c(length(probs) - 0.5, max(probs)))+ if(U[2] < probs[round(U[1]) + 1]) break+ }+ return(round(U[1]))+ }+ replicate(n, singlenumber())+ }Execute both functions using n = 100, 1000, and 10 000. Use system.time() to determinewhich method is faster.38. Generate a random sample of size 1000 from a normal location mixture. The componentsof the mixture have N(0, 1) and N(3, 1) distributions with mixing probabilities p 1 and p 2 =1 − p 1 . Graph the histogram of the sample with density superimposed for p 1 = 0.75. Repeatwith different values for p 1 and observe whether the empirical distribution of the mixtureappears to be bimodal. Make a conjecture about the values of p 1 that produce bimodalmixtures.39. Simulate a continuous Exponential-Gamma mixture. Suppose that the rate parameter Λ hasGamma(r, β) distribution and Y has Exp(Λ) distribution. That is, Y |Λ = λ ∼ f Y (y|λ) =λe −λy . Generate 1000 random observations of this mixture with r = 4 and β = 2. It can beshown that the mixture has a Pareto distribution with cdf( ) r βF (y) = 1 − , y ≥ 0.β + yCompare the empirical and theoretical (Pareto) distributions by graphing the density histogramof the sample and superimposing the Pareto density curve.40. Generate 200 random observations from the 3-dimensional multivariate normal distributionhaving mean vector m = (0, 1, 2) and covariance matrix⎡1.0 −0.5⎤0.5V = ⎣ −0.5 1.0 −0.5 ⎦0.5 −0.5 1.0using the Choleski factorization method. Use function pairs() to graph an array of scatterplots for each pair of variables. For each such pair, (visually) check that the locationand correlation approximately agree with the theoretical parameters of the correspondingbivariate normal distribution.41. A compound Poisson process is a stochastic process (X(t), t ≥ 0 which can represented asthe random sumX(t) =N(t)∑i=1Y i ,where (N(t), t ≥ 0) is a Poisson process and Y 1 , Y 2 , . . . are i.i.d. and independent of (N(t)).Write a program to simulate a compound Poisson(λ)–Gamma process. Estimate the meanand the variance of X(10) for several choices of the parameters and compare with the theoreticalvalues. Hint: show that E(X(t)) = λtE(Y 1 ) and var(X(t)) = λtE(Y1 2 ).42. Use Monte Carlo integration to estimate the following integrals, comparing with the exactanswer if known.∫ 31x 2 dx,∫ π0sin(x)dx,∫ ∞0e −x dx,∫ 30sin(e x )dx,∫ 201√2πe −x2 /2 dx.7


43. Compute a Monto Carlo estimate ˆθ ofθ =∫ 0.50e −x dxby sampling from Uniform(0, 0.5), and estimate the variance of ˆθ. Find another Monte Carloestimator θ ∗ by sampling from the exponential distribution. Which of the variances (of ˆθand θ ∗ ) is smaller, and why?44. Suppose a bank has a credit portfolio with 10 obligors with rating grade AA, 25 with A,and 96 rated BBB, respectively, with corresponding one-year probabilities of default (PDs)0.0001, 0.0005, and 0.0025, respectively. Simulate default scenarios, assuming that the defaultoccur independently.π 45. The following model has been used for the study of contagion. Suppose that there are Npersons some of whom are sick with influenza. The following assumptions are made:• when a sick person meets a healthy one, the chance is α that the latter will be infected• all encounters are between two persons• all possible encounters in pairs are equally likely• one such encounter occurs in every unit of time.(a) Write a function which simulates this model for various values of N (say, 10 000) andα (say, between 0.001 and 0.1). Monitor the history of this process, assuming that oneindividual is infected at the beginning.(b) Suppose that initially only one individual is infected. What is the expected length oftime until 1000 people are infected?(c) Now add the assumption that each infected person has chance β, say 0.01, of recoveringat each time unit. Monitor several histories of this new process, and compare themwith the histories of the old process.(d) Re-do with the assumption that the time between encounters is an exponential randomvariable with a mean of 5 minutes.(e) Re-do assuming that the time between encounters is the absolute value of a normalrandom variable with a mean of 5 minutes and a standard deviation of 1 minute.π 46. Simulate the following simple model of auto insurance claims:• Claims arise according to a Poisson process at a rate of 100 per year.• Each claim is random in size following a Gamma distribution with shape and rateparameters both equal to 2. This distribution has a mean of 1 and a variance of 1/2.Claims must be paid by the insurance company as soon as they arise.• The insurance company earns premiums at a rate of 105 per year, spread evenly overythe year (i.e., at time t measured in years, the total premium received is 105t).Write R code to do the following:(a) Simulate the times and amounts of all the claims that would occur in one year. Drawthe graph of the total number of money that the insurance company would have throughthe year, starting from zero: it should increase smoothly with the premiums, and dropat each claim time.(b) Repeat the simulation 1000 times, and estimate the following quantities:i. The expected minimum amount of money that the insurance company would have.ii. The expected final amount of money that the insurance company would have.8


π 47. For the German credit data, explore the relations between personal status (‘Status and sex’)and Age, Amount, Purpose and quality (‘Class’). Which patterns can you find?π 48. For the German credit data, explore the relations between credit history (‘History’), employmentlevel (‘Job’) and duration (‘Employment since’), and credit amount (‘Amount’) andquality (‘Class’). Which patterns can you find?49. The R standard data set islands is a vector containing the areas of 48 land masses.(a) Plot a histogram of these data.(b) Are there advantages to taking logarithms of the areas before plotting the histogram?(c) Compare the histograms that result when using breaks based on Sturges’ and Scott’srules. Make this comparison on the log-scale and the original scale.(d) Construct a boxplot for these data on the log-scale as well as on the original scale.(e) Construct a dot-chart of the areas. Is a log transformation needed here?(f) Which form of graphic do you think is most appropriate for displaying these data?50. For the islands data set, try out the following code.R> hist(log(islands, 10), breaks = "Scott", axes = FALSE, xlab = "Area",+ main = "Histogram of Island Areas")R> axis(1, at = 1 : 5, labels = 10 ^ (1 : 5))R> axis(2)R> box()(a) Explain what is happening at each step of the above code.(b) Add a subtitle to the plot such as “Base-10 Log-Scale”.(c) Modify the code to incorporate the use of the Sturges rule in place of the Scott rule. Inthis case, you will need to use the round() function to ensure that excessive numbersof digits are not used in the axis labels.51. The R standard data set stackloss is a data frame with 21 observations on four variablestaken at a factory where ammonia is converted to nitric acid. The first three variables areAir.Flow, Water.Temp and Acid.Conc. The fourth variable is stack.loss, which measuresthe amount of ammonia that escapes before being absorbed. (Read the help file for moreinformation about this data frame.)(a) Use scatterplots to explore possible relationships between acid concentration, watertemperature, and air flow and the ammount of ammonia which escapes. Do theserelationships appear to be linear or nonlinear?(b) Use the pairs() function to obtain all pairwise scatterplots among the four variables.Identify pairs of variables where the might be linear or nonlinear relationships.52. The R standard data set pressure is a data frame with two variables, temperature andpressure.(a) Construct a scatterplot with pressure on the vertical axis and temperature on thehorizontal one. Are the variables related linearly or nonlinearly?(b) The graph of the following function passes through the plotted points reasonably well:y = (0.168 + 0.007x) 20/3The differences between the pressure values predicted by the curve and the observedpressure values are called residuals, and can be computed via9


R> residuals curve((0.168 + 0.007 * x)^(20/3), from = 0, to = 400, add = TRUE)(b) Now, apply the power transformation y 3/20 to the pressure data values. Plot thesetransformed values against temperature. Is a linear or nonlinear relationship evidentnow? Use the abline() function to pass a straight line through the points. (See theprevious part of the exercise to obtain an intercept and a slope for this line.)(c) Add a suitable title to the graph.(d) Re-do the above plots, but use the mfrow mechanism to display them in a 2 × 1 layouton the graphics page. Repeat once again using a 1 × 2 layout.54. Write a function to “correctly” graph the amount of money that the insurance companywould have in the auto insurance simulation model in the following style:●−5 0 5 10 15● ●● ●●●●● ● ●●● ●●●● ● ● ● ● ●●●●● ●●● ● ● ●●●●● ●●● ●●● ● ●●●●●●● ●● ●●● ●● ●● ●●●●● ● ●●●● ●●● ●● ●● −5 0 5 10 15●●●●● ●● ●●●●● ●●●●●● ● ●● ● ●● ● ● ●●● ●●●●● ●●● ●● ●●0.0 0.2 0.4 0.6 0.8 1.00.00 0.05 0.10 0.15 0.2055. Create a sample of size N = 128 from the standard normal distribution and from theexponential distribution with parameter 1, and use Q-Q plots to assess the normality of thedata. Describe and explain the differences of the results.56. (a) Generate a sample of size N = 1024 from the exponential distribution with parameter(rate) λ = 0.2. Call x the vector containing the sample values.10


(b) Plot on the same graph, the exact (theoretical) density of the distribution of x, and ahistogram of x. It is recommended to try several values for the number of bins, and toreport only the result found most satisfactory.(c) Plot on the same graph, the same density as before, together with a kernel densityestimate of the the distribution of x. Again, it is recommended to try several values ofthe bandwith, and to report only the result found most satisfactory.(d) Compare the two plots and explain the reasons for the differences. Say which estimateof the density you prefer, and explain why.57. The goal of this problem is to design and use a home-grown random number generator forthe exponential distribution.(a) Compute the cdf F λ (x) = P(X ≤ x) of a random variable X with an exponentialdistribution with parameter λ > 0.(b) Compute its inverse F −1λand write an R function myrexp which takes the parameters N,and LAMBDA, and which returns a numeric vector of length N containing N samplesof random variates from the exponential distribution with parameter LAMBDA.(c) Use your function myrexp to generate a sample of size N = 1024 from the exponentialdistribution with mean 1.5, use the function rexp to generate a sample of the same sizefrom the same distribution, and produce a Q-Q plot of the two samples.Are you satisfied with the performance of your simulation function myrexp? Explain.π 58. This problem deals with the analysis of the daily S&P 500 closing values.(a) Load the data using quantmod.(b) Create a vector DSPRET containing the daily raw returns. Compute the mean andthe variance of this daily raw return vector, produce its eda.shape plot, and discuss thefeatures of this plot which you find remarkable.(c) Fit a Generalized Pareto Distribution (GPD for short) to the daily raw returns, givedetailed plots of the fit in the two tails, and discuss your results.(d) Generate a sample of size 10000 from the GPD fitted above. Call this sample SDSPRET,produce a Q-Q plot of DSPRET against SDSPRET, and comment.(e) Compute the VaR (expressed in units of the current price) for a horizon of one day, atthe level α = 0.005 in each of the following cases:• assuming that the daily raw return is normally distributed;• using the GPD distribution fitted to the data in the previous question;• compare the results (think of a portfolio containing a VERY LARGE number of contracts).π 59. Redo the above problem after replacing the vector DSP with a vector SDSP containing onlythe first 6000 entries of DSP. Compare the results, and especially the VaR’s. Explain thedifferences.π 60. This problem is based on the data matrix UTILITIES. Each row corresponds to a given day.The first column gives the log of the weekly return on an index based on Southern Electricstock value and capitalization, (we’ll call that variable X), and the second column gives, onthe same day, the same quantity for Duke Energy (we’ll call that variable Y ), another largeutility company.(a) Compute the means and the standard deviations of X and Y , and compute their correlationcoefficients.11


(b) We first assume that X and Y are samples from a jointly Gaussian distribution withparameters computed in question 1. Compute the q-percentile with q = 2% of thevariables X + Y and X − Y .(c) Fit a generalized Pareto distribution (GPD) to X and Y separately, and fit a copula ofthe Gumbel family to the empirical copula of the data.(d) Generate a sample of size N (where N is the number of rows of the data matrix) fromthe joint distribution estimated in question 3. Use this sample to compute the samestatistics as in question 1 (i.e., means and standard deviations of the columns, as well astheir correlation coefficients), and compute the results to the numerical values obtainedin question 1. Compute, still for this simulated sample, the two percentiles consideredin question 2, compare the results, and comment.61. Show that if X is a random variable with distribution symmetric about 0 and finite secondmoments, then X and |X| are uncorrelated.62. This elementary exercise is intended to give an example showing that lack of correlation doesnot necessarily mean independence. Let us assume that X ∼ N(0, 1) and let us define therandom variable Y by Y = (|X| − √ 2/π)/ √ 1 − 2/π.(a) Compute E(|X|).(b) Show that Y has mean zero, variance 1, and that it is uncorrelated with X.63. The purpose of this problem is to show that lack of correlation does not imply independence,even when the two random variables are Gaussian. We assume that X, ɛ 1 and ɛ 2 areindependent random variables, that X ∼ N(0, 1), and that P(ɛ i = −1) = P(ɛ i = +1) = 1/2for i = 1, 2. We define the random variable X 1 and X 2 by X 1 = ɛ 1 X, and X 2 = ɛ 2 X.(a) Prove that X 1 ∼ N(0, 1), X 2 ∼ N(0, 1) and that ρ(X 1 , X 2 ) = 0.(b) Show that X 1 and X 2 are not independent.(c) Determine the copula of X 1 and X 2 .64. The goal of this problem is to prove rigorously a couple of useful formulae for normal randomvariables.(a) Show that, if Z ∼ N(0, 1), if σ > 0, and if f is ANY function, then we have:E(f(Z)e σZ ) = e σ2 /2 E(f(Z + σ)),and use this formula to recover the well known factE(e X ) = e µ+σ2 /2 ,whenever X ∼ N(µ, σ 2 ).(b) We now assume that X and Y are jointly-normal mean-zero random variables and thath is ANY function. Prove that:E(e X h(Y )) = E(e X )E(h(Y + cov(X, Y ))).65. This problem concerns the computation in R of the square root of a symmetric nonnegativedefinitesquare matrix.Write a function, call it msqrt, with argument A which: Checks that A is a square matrix,is symmetric and diagonalizes the matrix by comupting the eigenvalues and the matrix ofthe eigenvectors (hint: eigen). Return a symmetric matrix of the same size as A, with thesame eigenvectors, the eigenvalue corresponding to a given eigenvector being the suare rootof the corresponding eigenvalues of A. The matrix returned is called the square root of thematrix A and will be denoted by A 1/2 .12


66. A d-dimensional copula is a distribution function on [0, 1] d with standard uniform marginaldistributions. I.e., if (U 1 , . . . , U d ) is a random vector such that U i ∼ U[0, 1], thenC(u 1 , . . . , u d ) := P(U 1 ≤ u 1 , . . . , U d ≤ u d )is the corresponding copula. Note that U 1 , . . . , U d do not need to be independent!Assume that F 1 , . . . , F d are arbitrary continuous and increasing distribution functions,let F1 −1 , . . . , F −1dbe their corresponding quantile functions, and let Z :=(F1 −1 (U 1 ) . . . , F −1 (U d)). Show thatdP(Z 1 ≤ z 1 , . . . , Z d ≤ z d ) = C(z 1 , . . . , z d ).Note. The converse statement is also true: for a given arbitrary random vector Z withmarginal distributions F 1 , . . . , F d we can find a copula C such thatP(Z 1 ≤ z 1 , . . . , Z d ≤ z d ) = C(F 1 (z 1 ), . . . , F d (z d )).This result is known as Sklar’s Theorem.67. Copulas are used to model dependence structures of multivariate random variables. Of particularimportance is the Gaussian copula, which is the corresponding copula to a multivariatenormal distribution with mean zero and correlation matrix V .In the spirit of Sklar’s theorem we use the following algorithm to simulate from the copula:(a) Generate (Z 1 , . . . , Z d ) ∼ N d (0, V ) using rmvnorm(b) Return U = (Φ(Z 1 ), . . . , Φ(Z d )), where Φ denotes the cdf of the standard normal distribution.The random vector U is now distributed according to the Gaussian copulawith parameter V .How does V influence the dependence structure of U? Generate 2000 samples each for for• cov(Z 1 , Z 2 ) = 0• cov(Z 1 , Z 2 ) = −0.8• cov(Z 1 , Z 2 ) = 0.8(note that var(Z 1 ) = var(Z 2 ) = 1). For each case, plot your results as a scatter plot. Whatcan you see? What happens if cov(Z 1 , Z 2 ) → ±1?π 68. An alternative to quandmod for loading limited free financial data is offered by the packageQuandl. Details can be found on http://www.quandl.com/help/packages/r. Using thispackage data can be obtained as follows. First one needs to generate a token (allowing for50 calls a day) byR> require("Quandl")R> Quandl.auth("yourauthenticationtoken")With the dataset code, which can be looked up on http://www.quandl.com, for examplethe USD/EUR exchange history can be loaded as follows.R> USDEUR


a) Compute the means for the WTI and Brent sample as well as their joint covariancematrix. Simulate a sample with the same size as the data from a bivariate normaldistribution with the corresponding parameteres. Compare scatterplots of the actualdata and the simulated data, compute qq-plots of actual data versus simulated dataand comment.b) To account for the heavier tails fit a multivariate t-distribution with location and scaleparameter to WTI and Brent. This multivariate distribution is defined as follows.We start with an R k -valued random vector T whose components are independent andfollow a t-distribution with ν degrees of freedom. With a vector µ ∈ R k and a matrixΣ ∈ R k×k with Cholesky decomposition Σ = LL ′ the multivariate t-distribution with νdegrees of freedom is defined as the distribution of X which is given byX = µ + LT.The expectation and the covariance matrix are then (ν > 2)E(X) = µV(X) = LV(T )L ⊤ =νν − 2 LL⊤ =νν − 2 Σ. (1)Write a function which generates a sample of arbitrary size from a multivariate t-distribution with the given parameters µ, Σ and ν. Then choose parameters for abivariate t-distribution with 4 degrees of freedom such that the resulting moments in(1) match the empirical moments. Simulate a sample with the same size as the data fromthis bivariate t-distribution with the corresponding parameteres. Compare scatterplotsof the actual data and the simulated data and/or analyze qqplots and comment.c) Now match one-dimensional t-distributions with 4 degrees of freedom and location andscale parameter to WTI and Brent seperately. Use these marginal distributions to fita copula of the Gumbel family to the empirical copula of the data. Simulate a samplefrom this distribution and compare the scatterplots again.d) Assume now that an investor holds a portfolio with a value of USD 10 million. Fiftypercent are invested in WTI and the remaining fifity percent are invested in Brent.Using simulation estimate the 1 percent quantile of the discrete daily return of thisportfolio for all the distributions of log-returns considered (use quantile). Use theseestimated quantiles to estimate the Value at Risk of the daily return. Compare thedifferent estimates you get.14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!