Home > code > main > pcsv_monte_carlo.m

pcsv_monte_carlo

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 PCSV parameters estimated from the corresponding time series
0011 % to be used as 'true' parameters for simulation
0012 load(cgmm_config.estimates.pcsv);
0013 
0014 % rename estimates to make clear that they play the role of true parameters here
0015 mu = mu_cgmm
0016 A = A_cgmm
0017 lambda_0 = lambda_0_cgmm
0018 kappa = kappa_cgmm
0019 theta = theta_cgmm
0020 sigma = sigma_cgmm
0021 rho = rho_cgmm
0022 
0023 % prepare simulation parameters
0024 S_0 = [100 100];
0025 y_0 = log(S_0);
0026 time_steps = cgmm_config.monte_carlo.time_steps/dt;
0027 
0028 % encode true parameters into flat parameter vector
0029 [theta_flat_0, decode] = encode_pcsv_param(mu, A, lambda_0, kappa ...
0030                                            , theta, sigma, rho);
0031 % prepare characteristic function call with the encoded parameters
0032 cf = @(omega, th, y_t, tau) cf_pcsv_v_theta(decode, omega, th, y_t, tau);
0033 % prepare options for optimization routine
0034 options = optimset('Display', 'iter' ...
0035                   , 'Algorithm', 'interior-point');
0036 % contraint for all parameters of +-10% around true parameters
0037 lb = theta_flat_0 - abs(theta_flat_0)*0.1;
0038 ub = theta_flat_0 + abs(theta_flat_0)*0.1;
0039 
0040 simulation_runs = cgmm_config.monte_carlo.simulation_runs
0041 if exist(cgmm_config.monte_carlo.pcsv)
0042   load(cgmm_config.monte_carlo.pcsv);
0043   % loaded file contains cell arrays 'first_step_estimates' and 'cgmm_estimates'
0044   first_run = size(first_step_estimates{1},1)
0045 else
0046   first_step_estimates = {} % store a cell of first step estimates for each time step
0047   cgmm_estimates = {} % store a cell of cgmm estimates for each time step
0048   % each estimates{k} is a simulation_runs x number of params matrix
0049   for k = 1:length(time_steps)
0050     first_step_estimates{k} = theta_flat_0;
0051     cgmm_estimates{k} = theta_flat_0;
0052   end
0053   first_run = 1
0054 end
0055 
0056 for run = first_run:simulation_runs
0057   disp(strcat('Simulation run: ',num2str(run),'/',num2str(simulation_runs)));
0058   t = 0:dt:(time_steps(end)*dt);
0059   % simulate time series
0060   [y, lambda] = sim_pcsv(y_0, mu, A, lambda_0, kappa, theta, sigma, rho, t);
0061   for k = 1:length(time_steps)
0062     y_k = y(1:time_steps(k),:);
0063     % perform parameter estimation
0064     tic;
0065     [theta_flat_cgmm, theta_flat_first] = cgmm(y_k, 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     first_step_estimates{k} = [first_step_estimates{k}; theta_flat_first];
0072     cgmm_estimates{k} = [cgmm_estimates{k}; theta_flat_cgmm];
0073   end
0074   % save monte carlo estimates in each iteration
0075   save(cgmm_config.monte_carlo.pcsv, 'first_step_estimates' ...
0076        , 'cgmm_estimates', 'time_steps');
0077 end

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