Home > code > main > pcsv_estimation.m

pcsv_estimation

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 cd('..');
0002 boot;
0003 cd(cgmm_config.directories.main);
0004 
0005 % Init parameters
0006 n = 2
0007 p = 2
0008 dt = 1/250;
0009 
0010 % load two-dimensional time series for estimation
0011 s = csvread(cgmm_config.time_series.file,1,0);
0012 y = log(s);
0013 r_real = diff(y);
0014 y_0 = y(1,:);
0015 
0016 % perform heuristic estimation of parameters
0017 [mu_heur, A_heur, lambda_0_heur, kappa_heur, theta_heur ...
0018   , sigma_heur, rho_heur] = heuristic_pcsv_param(y, dt, p)
0019 
0020 % encode parameters into flat parameter vector
0021 % call it theta_flat to avoid naming conflicts with the mean reversion
0022 % level parameter theta
0023 [theta_flat_0, decode] = encode_pcsv_param(mu_heur, A_heur, lambda_0_heur ...
0024   , kappa_heur, theta_heur, sigma_heur, rho_heur);
0025 
0026 % prepare characteristic function call with the encoded parameters
0027 cf = @(omega, th, y_t, tau) cf_pcsv_v_theta(decode, omega, th, y_t, tau);
0028 
0029 % prepare options for optimization routine
0030 options = optimset('Display', 'iter' ...
0031                   , 'Algorithm', 'interior-point');
0032 % contraint for all parameters of +-25% around heuristic estimate
0033 lb = theta_flat_0 - abs(theta_flat_0)*0.25;
0034 ub = theta_flat_0 + abs(theta_flat_0)*0.25;
0035 % except for correlation (where absolute constraints are more feasible)
0036 lb(end-1:end) = max(theta_flat_0(end-1:end)-0.6, -1);
0037 ub(end-1:end) = min(theta_flat_0(end-1:end)+0.6, 1);
0038 
0039 % test for the Feller condition
0040 feller_condition = @(kappa, theta, sigma) 2*kappa.*theta > sigma.^2;
0041 if ~all(feller_condition(kappa_heur, theta_heur, sigma_heur))
0042   error('Heuristic estimates do not satisfy the Feller condition!');
0043 end
0044 
0045 % set parameter constraints for kappa, theta and sigma
0046 % so that the Feller condition will still be satisfied after optimization:
0047 % -> set lower bounds for kappa and theta
0048 % -> set upper bounds for sigma
0049 % distribute constraints "relatively equal" among the parameters, i.e.
0050 % (1-alpha)^2 * 2 * kappa * theta > (1+alpha)^2 * sigma^2
0051 % If the Feller condition holds, alpha is positive.
0052 alpha = ( sqrt(2*kappa_heur.*theta_heur) - sigma_heur ) ./ ...
0053         ( sqrt(2*kappa_heur.*theta_heur) + sigma_heur );
0054 
0055 idx_kappa = 1:2;
0056 idx_theta = 3:4;
0057 idx_sigma = 5:6;
0058 
0059 lb(idx_kappa) = max(lb(idx_kappa), (theta_flat_0(idx_kappa)-abs(theta_flat_0(idx_kappa)).*alpha));
0060 lb(idx_theta) = max(lb(idx_theta), (theta_flat_0(idx_theta)-abs(theta_flat_0(idx_theta)).*alpha));
0061 ub(idx_sigma) = min(ub(idx_sigma), (theta_flat_0(idx_sigma)+abs(theta_flat_0(idx_sigma)).*alpha));
0062 
0063 % perform parameter estimation
0064 tic;
0065 [theta_flat_cgmm, theta_flat_first] = cgmm(y, dt, cf, theta_flat_0 ...
0066                                             , cgmm_config.cgmm.grid_min+1 ...
0067                                             , cgmm_config.cgmm.grid_max+1 ...
0068                                             , cgmm_config.cgmm.grid_res ...
0069                                             , lb, ub, options);
0070 toc;
0071 
0072 % decode parameters
0073 [mu_first, A_first, lambda_0_first, kappa_first, theta_first ...
0074   , sigma_first, rho_first] = decode_pcsv_param(theta_flat_first, decode);
0075 
0076 [mu_cgmm, A_cgmm, lambda_0_cgmm, kappa_cgmm, theta_cgmm ...
0077   , sigma_cgmm, rho_cgmm] = decode_pcsv_param(theta_flat_cgmm, decode);
0078 
0079 % save heuristic estimates, first step estimates and cgmm estimates
0080 save( ...
0081   cgmm_config.estimates.pcsv ...
0082   , 'theta_flat_0', 'mu_heur', 'A_heur', 'lambda_0_heur' ...
0083   , 'kappa_heur', 'theta_heur', 'sigma_heur', 'rho_heur' ...
0084   , 'theta_flat_first', 'mu_first', 'A_first', 'lambda_0_first' ...
0085   , 'kappa_first', 'theta_first', 'sigma_first', 'rho_first' ...
0086   , 'theta_flat_cgmm', 'mu_cgmm', 'A_cgmm', 'lambda_0_cgmm' ...
0087   , 'kappa_cgmm', 'theta_cgmm', 'sigma_cgmm', 'rho_cgmm' ...
0088 )

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