Professional Documents
Culture Documents
Assignment_MEF_2_2018
Assignment_MEF_2_2018
• All assignments turned in late will be not graded. Non-graded assignments result in zero grade.
• The assignment must be done in groups of three or four students. Only one copy of solution per group is
submitted. Please attach the printout of your Matlab code as well if asked.
• Note: If a value cannot be computed, please briefly explain why.
1
Exercise 1
This exercise will guide you through the theoretical and practical aspects of estimating statistical parameters.
Please carry out explicitly (that is, by hand) all analytical derivations and attach the printout of your Matlab
codes when you use it.
Part 1
In finance and insurance we are often interested in modelling extreme events, that are large in magnitude but
also very rare. Distributions that allow for modelling such outcomes are said to have ‘heavy tails.’ One such
distribution is characterized by the following pdf:
η+1
η λ
f (X = x|η, λ) = , x ≥ λ, λ > 0, η > η0 .
λ x
Consider an i.i.d. sample of n random variables (X1 , X2 , . . . , Xn ), each following this distribution.
(a) Construct analytically estimators for η and λ using the method of moments (MM) and the method of
maximum likelihood (ML). Provide a condition on η0 such that the first two moments exist.
bM L think how the log-likelihood depends on λ and what the constraint on λ is.
Hint: to compute λ
Part 2
Now you will learn how to simulate any random variable with a given pdf by inverting its cdf. To do so, we will
apply the following theorem:
(b) Suppose we have a realization u of a uniformly distributed random variable U ∼ U(0, 1). Find the inverse
of FX (u).
Thus, if you have a random number u that is a realization of a uniformly distributed random variable, you can
−1
immediately generate the corresponding x: x = FX (u).
(c) To make sure you got it right, simulate a sample of 105 realizations of x and plot its distribution.
Part 3
Now you will investigate numerically the properties of the two η estimators using simulation. To do so, apply the
following Monte Carlo (MC) algorithm in Matlab. Assume that the true value of η is 2.85 and that λ is fixed
at 1.
• Generate N random vectors xi , i = 1, . . . , N , each containing n realizations of the random variable x.
Simulate the data using the true parameter value with the algorithm derived in Part 2. Do not forget to
fix the seed to generate the same random numbers each time you run your code. For this purpose, use the
routine below (keep the same seed):
2
% Set the seed
RandomSeed = 12321;
forsim = RandStream.create(’mrg32k3a’,’Seed’,RandomSeed);
% Generate realizations of uniform random variables of size (n,N) using the seed
u = rand(forsim,n,N);
(c) Compare the MM and ML estimators of η in terms of their relative efficiency (that is, the ratio of the Monte
Carlo estimates of their variances). Present your results. Do the results depend on n? Which estimator do
you prefer?
(d) Compute the Monte Carlo estimate of the mean-squared error of ηb (and both ML and MM) and each n.
Present your results. Comment on your results. Which estimator do you prefer?
(e) Compute analytically the standard error of ηbM L . Present your results. How does it compare to the numerical
ones for different n?
Exercise 2
Stephen has a hobby of building matchstick houses. His construction function is C(x, y) = A(xα + y β )γ , where
x is the number of matchboxes and y is the number of bottles of glue used. Stephen’s budget constraint is
W ≥ Rx + M y, where W is his budget, R is the price of a matchbox and M is the price of a bottle of glue. Let
G be the constraint set, that is, the set of all feasible construction bundles.
(a) Formulate the optimization problem.
(e) Solve the optimization problem for the following values of the parameters A = 1, α = 1, β = 0.5, γ =
1, R = 2, M = 4, W = 100. Is the solution unique?
(f) How does the solution and the value function depend on (R, M, W )? What are the properties of the value
function and the solution in terms of W ?
Now imagine that the match-making company starts its sales season and announces that every customer buying
25 matchboxes gets a special price offer of only R0 = 1 unit of money (instead of original 2) per box.
3
(g) Describe the new constraint set G0 and compare it with the initial set G. Provide an illustration.
(h) Using both Matlab and Excel, solve the initial and the new problems and compare the solutions. Provide
the printout of your Matlab code and send the Excel spreadsheet to jimmy.lerch@unil.ch.
(i) How does the solution and the value function depend on (R, R0 , M, W )? Does your result coincide with the
previous results? Support your statements with illustrations.
Bonus exercise 1
You have a dataset at your disposal (see the attached file on Moodle).
(a) Import the data to Matlab. Describe the data, that is provide summary statistics (at least mean, median,
std. deviation, Q1, Q3, min, max) as well as the histogram of the data and any other characteristics you
deem important.
Suppose now that you believe that the true distribution of the data is Y ∼ Γ(α, β), that is
β α y α−1 exp(−βy)
f (Y = y|α, β) = , y > 0, α > 0, β > 0.
Γ(α)
Note that this integral cannot be solved explicitly so we usually just say Γ(x).
(b) Derive analytically the log-likelihood function and the first-order conditions. Explain if it is possible to
provide a closed-form solution for the MLEs using the first-order conditions.
(c) Estimate numerically the parameters of the distribution in Matlab. Do not use the built-in function mle,
but rather write your own function to get the ML estimates. This means that you should write a function
that takes as arguments the data and the two parameters and returns the log-likelihood, and then use one
of Matlab’s build-in optimizers, such as fminunc to find the maximum of your likelihood function. Don’t
forget to change the sign of your objective as this function computes the minimum. You will need to use
the function gamma(x) that gives you the value of the Gamma function at x. Present your results.
(d) Compute the standard errors of your estimates using the asymptotic distribution of ML in two ways:
1. By using the observed Fisher Information matrix from fminunc (save the Hessian that it produces).
2. By computing your own Fisher Information matrix, evaluated at the estimated parameter values, using
the analytical log-likelihood function.
Hint: when you are at the stage of plugging in your estimates, use the function psi(1,x) to compute
d2 /dx2 log(Γ(x)), you should not compute it further analytically, however, when you get to this point.
Present your results in each case.
(e) Assess the quality of the estimates and your statistical model for the data. E.g. make a plot of the estimated
vs empirical distribution, a QQ plot, compute the MSE, comment on the standard errors etc.
Now assume that the true parameters of this Gamma distribution are α = 7 and β = 0.8.
(f) Compute the true standard errors of the ML estimator using these parameter values (Note that you already
carried out this computation by hand and plugged in your estimates in (d)–2.). Present your results.
4
(g) Create three data sets by simulating from the Gamma distribution, that have n = 500, 5000, and 50000
observations. Estimate α and β by using ML and compute the numerical standard erros from point (d).
Present your results. Comment how the point estimates and standard errors compare to the true ones as n
increases.
Note that, without knowing the true parameters governing the distribution, we could have also done the same by
using a procedure called bootstrapping, that generates samples from the actual data with replacement.