Home > code > core > estimation > cgmm.m

cgmm

PURPOSE ^

CGMM Performs continuum of moments estimation for the model specified by cf.

SYNOPSIS ^

function [theta_cgmm, theta_first] = cgmm(y, tau, cf, theta_0, grid_min, grid_max, grid_res, lb, ub, options)

DESCRIPTION ^

CGMM Performs continuum of moments estimation for the model specified by cf.

  [theta_cgmm, theta_first] = cgmm(y, tau, cf, theta_0, grid_min, grid_max
    , grid_res, lb, ub, options) performs conditional continuum of moments
    estimation for the model specified by its characteristic function cf,
    based on the time series of log prices y and a start parameter theta_0
    for the optimization.

    INPUT       y: log prices of the assets
              tau: real valued time difference
               cf: characteristic function. cf is supposed to expect omega, 
                   theta, y_t, tau with
                   - omega a size(y,2) x grid_res matrix
                   - theta the flat parameter vector (interpretation by cf)
                   - y_t a (size(y,1)-1) x size(y,2) matrix
                   - tau a real valued time difference
                   cf is supposed to calculate to characteristic function
                   of the continuous returns conditional on the log prices.
          theta_0: initial parameter vector
         grid_min: left end of marginal evaluation grid
         grid_max: right end of marginal evaluation grid
         grid_res: resolution of marginal evaluation grid
               lb: lower bounds for the parameters
               ub: upper bounds for the parameters
          options: structure (or vector) of options for the optimization

    OUTPUT  theta_cgmm: CGMM parameter estimate
           theta_first: first step parameter estimate

 See also CF_PCSV_V_THETA, CF_WASC_THETA.

 created by Benedikt Rudolph
 DATE: 20-Aug-2012

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [theta_cgmm, theta_first] = cgmm(y, tau, cf, theta_0 ...
0002     , grid_min, grid_max, grid_res, lb, ub, options)
0003 %CGMM Performs continuum of moments estimation for the model specified by cf.
0004 %
0005 %  [theta_cgmm, theta_first] = cgmm(y, tau, cf, theta_0, grid_min, grid_max
0006 %    , grid_res, lb, ub, options) performs conditional continuum of moments
0007 %    estimation for the model specified by its characteristic function cf,
0008 %    based on the time series of log prices y and a start parameter theta_0
0009 %    for the optimization.
0010 %
0011 %    INPUT       y: log prices of the assets
0012 %              tau: real valued time difference
0013 %               cf: characteristic function. cf is supposed to expect omega,
0014 %                   theta, y_t, tau with
0015 %                   - omega a size(y,2) x grid_res matrix
0016 %                   - theta the flat parameter vector (interpretation by cf)
0017 %                   - y_t a (size(y,1)-1) x size(y,2) matrix
0018 %                   - tau a real valued time difference
0019 %                   cf is supposed to calculate to characteristic function
0020 %                   of the continuous returns conditional on the log prices.
0021 %          theta_0: initial parameter vector
0022 %         grid_min: left end of marginal evaluation grid
0023 %         grid_max: right end of marginal evaluation grid
0024 %         grid_res: resolution of marginal evaluation grid
0025 %               lb: lower bounds for the parameters
0026 %               ub: upper bounds for the parameters
0027 %          options: structure (or vector) of options for the optimization
0028 %
0029 %    OUTPUT  theta_cgmm: CGMM parameter estimate
0030 %           theta_first: first step parameter estimate
0031 %
0032 % See also CF_PCSV_V_THETA, CF_WASC_THETA.
0033 %
0034 % created by Benedikt Rudolph
0035 % DATE: 20-Aug-2012
0036   
0037   p = size(y,2); % dimension of the model
0038   T = size(y,1); % number of observations
0039   
0040   % choose a fixed grid according to the model's dimension for integration
0041   grid_margin = grid_min:(grid_max-grid_min)/(grid_res-1):grid_max;
0042   omega = mgrid(grid_margin, p);
0043   
0044   % prepare fixed parameters
0045   r = diff(y);
0046   s = (grid_max-grid_min)/6;
0047   % mv std normal
0048   w_kernel = @(x) exp(-0.5*diag(x'*x)/(s^2))/((2*3.1415*s)^(p*0.5));
0049   pi = w_kernel(omega)'; % weighting for L^2(pi) norm
0050   pi = pi/sum(pi);
0051   sqrt_pi = sqrt(pi);
0052   
0053   % precalculate empirical characteristic function (independent from theta)
0054   ecf = exp(1i*r*omega);
0055   
0056   % obtain the theoretical characteristic function as a function of theta
0057   phi = @(theta) cf(omega, theta, y, tau);
0058   
0059   % define the moment function depending on the parameters (theta)
0060   H = @(theta) ecf - phi(theta);
0061   
0062   % define the error function for the first step estimator
0063   % i.e. the I_{T-1} matrix as weighting matrix
0064   first_step_error = @(theta) norm(mean(H(theta)).*sqrt_pi);
0065   
0066   % perform first step optimization
0067   disp('Calculating first step estimator...');
0068   first_step_opt = prepare_nl_opt_call(first_step_error, theta_0 ...
0069                                       , lb, ub, options);
0070   theta_first = first_step_opt();
0071   theta_first = reshape(theta_first, 1, length(theta_first));
0072   disp('done');
0073   
0074   % CGMM estimation for correlated moment functions
0075   disp('Calculating optimal weighting matrix...');
0076   H_first = H(theta_first);
0077   H_first_weighted = H_first.*repmat(sqrt_pi,T-1,1);
0078   S = T/6;
0079   ph_kernel = @(x) exp(-0.5*diag(x'*x))/((2*3.1415*s)^(p*0.5));
0080   ph = ph_kernel((0:T)/S);
0081   ph = ph/sum(ph);
0082   UH_first = ph(1)*conj(H_first);
0083   ph = repmat(ph, 1, size(H_first,2));
0084   for t=1:(T-1)
0085     UH_first(t,:) = UH_first(t,:) ...
0086                     + sum(ph(2:t,:).*conj(H_first(1:(t-1),:)), 1) ...
0087                     + sum(ph(2:(T-t),:).*conj(H_first((t+1):(T-1),:)), 1);
0088   end
0089   UH_first_weighted = UH_first.*repmat(sqrt_pi,T-1,1);
0090   C = (UH_first_weighted*H_first_weighted')/(T-length(theta_first));
0091   alpha = 0.02; % regularization parameter
0092   opt_weighting = inv(alpha*eye(T-1)+C^2);
0093   disp('done');
0094   w = @(mean_H_theta) H_first_weighted * (mean_H_theta.*sqrt_pi)';
0095   v = @(mean_H_theta) UH_first_weighted * (mean_H_theta.*sqrt_pi).';
0096   % define the second step error function for the efficient estimator
0097   % wrap the call to mean(H(theta)) to prevent calling it twice (expensive!)
0098   wrap_second_step_error = @(mean_H_theta) real(w(mean_H_theta)' ...
0099                       *opt_weighting*v(mean_H_theta));
0100   second_step_error = @(theta) wrap_second_step_error(mean(H(theta)));
0101   
0102   % prepare CGMM optimization
0103   second_step_opt = prepare_nl_opt_call(second_step_error, theta_first ...
0104                                       , lb, ub, options);
0105   
0106   disp('Calculating second step cgmm estimator...');
0107   % call to optimization function
0108   theta_cgmm = second_step_opt();
0109   
0110   theta_cgmm = reshape(theta_cgmm, 1, length(theta_cgmm));
0111   disp('done');
0112 end

Generated on Mon 29-Apr-2013 19:29:13 by m2html © 2005