Home > code > core > estimation > heuristic_wasc_param_2d.m

heuristic_wasc_param_2d

PURPOSE ^

HEURISTIC_WASC_PARAM Obtains heuristic parameter estimates for a WASC model.

SYNOPSIS ^

function [mu, Sigma_0, M, Q, rho, beta] = heuristic_wasc_param_2d(y_t, dt)

DESCRIPTION ^

HEURISTIC_WASC_PARAM Obtains heuristic parameter estimates for a WASC model.

  [mu, Sigma_0, M, Q, rho, beta] = heuristic_pcsv_param(y_t, dt)
    calculates parameter estimates for a WASC model with the time series
    y_t using a heuristic approach. The results are supposed to be used
    as starting points for an iterative optimization algorithm.

    INPUT y_t: A Txn matrix representing the log prices
           dt: The time difference in the observed series y_t

 created by Benedikt Rudolph
 DATE: 17-Oct-2012

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mu, Sigma_0, M, Q, rho, beta] = heuristic_wasc_param_2d(y_t, dt)
0002 %HEURISTIC_WASC_PARAM Obtains heuristic parameter estimates for a WASC model.
0003 %
0004 %  [mu, Sigma_0, M, Q, rho, beta] = heuristic_pcsv_param(y_t, dt)
0005 %    calculates parameter estimates for a WASC model with the time series
0006 %    y_t using a heuristic approach. The results are supposed to be used
0007 %    as starting points for an iterative optimization algorithm.
0008 %
0009 %    INPUT y_t: A Txn matrix representing the log prices
0010 %           dt: The time difference in the observed series y_t
0011 %
0012 % created by Benedikt Rudolph
0013 % DATE: 17-Oct-2012
0014 
0015   [T, n] = size(y_t);
0016   r = diff(y_t);
0017   % Obtain mu and Sigma_0 == Sigma_infty
0018   Sigma_0 = cov(r)/dt;
0019   mu = mean(r)'/dt + (0.5*diag(Sigma_0));
0020   % Calculate a rolling time series of covariance matrices as a basis
0021   % for the calculation of Q, M and beta
0022   roll_period = 25;
0023   S = zeros(n, n, T-roll_period);
0024   for k=1:(T-roll_period)
0025     S(:,:,k) = cov(diff(y_t(k:(k+roll_period-1),:)))/dt;
0026   end
0027   % Calculate moments of dS and S
0028   dS = diff(S, 1, 3); % first-order difference along third dimension
0029   K = size(dS,3);
0030   E = @(a) a'*mean(dS,3)*a;
0031   V = @(a) mean( (arrayfun(@(k) a'*dS(:,:,k)*a, 1:K) - E(a)).^2 );
0032   Cov = @(a,g) mean( ...
0033                 (arrayfun(@(k) a'*dS(:,:,k)*a, 1:K) - E(a)) ...
0034             .*  (arrayfun(@(k) g'*dS(:,:,k)*g, 1:K) - E(g)) );
0035   KS = size(S,3);
0036   ES = @(a) a'*mean(S,3)*a;
0037   VS = @(a) mean( (arrayfun(@(k) a'*S(:,:,k)*a, 1:KS) - ES(a)).^2 );
0038   K = @(a) 2*ES(a)^2 / VS(a);
0039   a1 = [1;0];
0040   a2 = [0;1];
0041   a12 = [1;1];
0042   % Obtain beta
0043   beta = K(a12);
0044   beta = max(beta, 9);
0045   % Obtain Q
0046   Q = zeros(n);
0047   Q(1,1) = sqrt( V(a1) / (4*Sigma_0(1,1)*dt) );
0048   Q(2,2) = sqrt( V(a2) / (4*Sigma_0(2,2)*dt) );
0049   Q(1,2) = -Cov(a1,a2) / (4*Sigma_0(1,2)*Q(1,1)*dt);
0050   % Obtain M as solution to A*M = b
0051   A = zeros(3);
0052   A(1,1) = 2*Sigma_0(1,1);
0053   A(1,2) = 2*Sigma_0(1,2);
0054   A(2,2) = 2*Sigma_0(1,2);
0055   A(2,3) = 2*Sigma_0(2,2);
0056   A(3,1) = 2*(Sigma_0(1,1)+Sigma_0(1,2));
0057   A(3,2) = 2*(Sigma_0(1,1)+2*Sigma_0(1,2)+Sigma_0(2,2));
0058   A(3,3) = 2*(Sigma_0(2,2)+Sigma_0(1,2));
0059   b = zeros(3,1);
0060   b(1) = E(a1)/dt - beta*a1'*(Q'*Q)*a1;
0061   b(2) = E(a2)/dt - beta*a2'*(Q'*Q)*a2;
0062   b(3) = E(a12)/dt - beta*a12'*(Q'*Q)*a12;
0063   m = A \ b;
0064   M = [m(1), m(2); m(2), m(3)];
0065   % Obtain rho
0066   period_length = 50;
0067   number_of_periods = floor((T-1)/period_length)-1;
0068   dZ = zeros(number_of_periods*n, 1);
0069   dW = zeros(number_of_periods*n, n);
0070   S_last = Sigma_0;
0071   for k=1:number_of_periods
0072     idx = (k*period_length):((k+1)*period_length);
0073     period_returns = r(idx, :);
0074     S = cov(period_returns);
0075     dS = (S - S_last) / period_length;
0076     dY = mean(period_returns);
0077     sqrt_S = chol(S);
0078     dZ((n*(k-1)+1):(n*k)) = sqrt_S \ (dY' - (mu - diag(S))*dt);
0079     dW((n*(k-1)+1):(n*k), :) = (2*sqrt_S*Q) \ (dS-(beta*(Q'*Q)+2*M*S)*dt);
0080   end
0081   rho = (dW \ dZ);
0082 end

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