Home > code > main > pcsv_partial_estimation.m

pcsv_partial_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 % this is about the partial model, so truncate the heuristic parameters
0021 kappa_heur = kappa_heur(1)
0022 theta_heur = theta_heur(1)
0023 sigma_heur = sigma_heur(1)
0024 rho_heur = rho_heur(1)
0025 
0026 % encode parameters into flat parameter vector
0027 % call it theta_flat to avoid naming conflicts with the mean reversion
0028 % level parameter theta
0029 [theta_flat_0, decode] = encode_pcsv_param_partial(mu_heur, A_heur ...
0030   , lambda_0_heur, kappa_heur, theta_heur, sigma_heur, rho_heur);
0031 
0032 % prepare characteristic function call with the encoded parameters
0033 cf = @(omega, th, y_t, tau) cf_pcsv_partial_theta(decode, omega, th, y_t, tau);
0034 
0035 % prepare options for optimization routine
0036 options = optimset('Display', 'iter' ...
0037                   , 'Algorithm', 'interior-point');
0038 % contraint for all parameters of +-25% around heuristic estimate
0039 lb = theta_flat_0 - abs(theta_flat_0)*0.25;
0040 ub = theta_flat_0 + abs(theta_flat_0)*0.25;
0041 % except for correlation (where absolute constraints are more feasible)
0042 lb(end) = max(theta_flat_0(end)-0.6, -1);
0043 ub(end) = min(theta_flat_0(end)+0.6, 1);
0044 
0045 % test for the Feller condition
0046 feller_condition = @(kappa, theta, sigma) 2*kappa.*theta > sigma.^2;
0047 if ~all(feller_condition(kappa_heur, theta_heur, sigma_heur))
0048   error('Heuristic estimates do not satisfy the Feller condition!');
0049 end
0050 
0051 % set parameter constraints for kappa, theta and sigma
0052 % so that the Feller condition will still be satisfied after optimization:
0053 % -> set lower bounds for kappa and theta
0054 % -> set upper bounds for sigma
0055 % distribute constraints "relatively equal" among the parameters, i.e.
0056 % (1-alpha)^2 * 2 * kappa * theta > (1+alpha)^2 * sigma^2
0057 % If the Feller condition holds, alpha is positive.
0058 alpha = ( sqrt(2*kappa_heur.*theta_heur) - sigma_heur ) ./ ...
0059         ( sqrt(2*kappa_heur.*theta_heur) + sigma_heur );
0060 
0061 idx_kappa = 1;
0062 idx_theta = 2;
0063 idx_sigma = 3;
0064 
0065 lb(idx_kappa) = max(lb(idx_kappa), (theta_flat_0(idx_kappa)-abs(theta_flat_0(idx_kappa)).*alpha));
0066 lb(idx_theta) = max(lb(idx_theta), (theta_flat_0(idx_theta)-abs(theta_flat_0(idx_theta)).*alpha));
0067 ub(idx_sigma) = min(ub(idx_sigma), (theta_flat_0(idx_sigma)+abs(theta_flat_0(idx_sigma)).*alpha));
0068 
0069 % perform parameter estimation
0070 tic;
0071 [theta_flat_cgmm, theta_flat_first] = cgmm(y, dt, cf, theta_flat_0 ...
0072                                             , cgmm_config.cgmm.grid_min+1 ...
0073                                             , cgmm_config.cgmm.grid_max+1 ...
0074                                             , cgmm_config.cgmm.grid_res ...
0075                                             , lb, ub, options);
0076 %theta_flat_cgmm = theta_flat_first = theta_flat_0
0077 toc;
0078 
0079 % decode parameters
0080 [mu_first, A_first, lambda_0_first, kappa_first, theta_first ...
0081   , sigma_first, rho_first] = decode_pcsv_param(theta_flat_first, decode);
0082 
0083 [mu_cgmm, A_cgmm, lambda_0_cgmm, kappa_cgmm, theta_cgmm ...
0084   , sigma_cgmm, rho_cgmm] = decode_pcsv_param(theta_flat_cgmm, decode);
0085 
0086 % save heuristic estimates, first step estimates and cgmm estimates
0087 save( ...
0088   cgmm_config.estimates.pcsv_partial ...
0089   , 'theta_flat_0', 'mu_heur', 'A_heur', 'lambda_0_heur' ...
0090   , 'kappa_heur', 'theta_heur', 'sigma_heur', 'rho_heur' ...
0091   , 'theta_flat_first', 'mu_first', 'A_first', 'lambda_0_first' ...
0092   , 'kappa_first', 'theta_first', 'sigma_first', 'rho_first' ...
0093   , 'theta_flat_cgmm', 'mu_cgmm', 'A_cgmm', 'lambda_0_cgmm' ...
0094   , 'kappa_cgmm', 'theta_cgmm', 'sigma_cgmm', 'rho_cgmm' ...
0095 )

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