PREVContentsINDEX

Section 11 Financial Modelling -- A Generalized Autoregressive Conditional Heteroskedastic or GARCH model

Time series models are often used in financial modeling. For these models the parameters are often extremely badly determined. With the stable numerical environment produced by AD Model Builder it is a simple matter to fit such models.

Consider a time series of returns where , which are available from some type of financial instrument. The model assumptions are

where the are independent normally distributed random variables with mean 0 and variance . We assume and There are four initial parameters to be estimated for this model, , , , and . The log-likelihood function for the vector is equal to a constant plus


DATA_SECTION
  init_int T
  init_vector r(0,T)
  vector sub_r(1,T)
  number h0
INITIALIZATION_SECTION
  a0 .1
  a1 .1
  a2 .1
PARAMETER_SECTION
  init_bounded_number a0(0.0,1.0)
  init_bounded_number a1(0.0,1.0,2)
  init_bounded_number a2(0.0,1.0,3)
  init_number Mean
  vector eps2(1,T)
  vector h(1,T)
  objective_function_value log_likelihood
PRELIMINARY_CALCS_SECTION
  h0=square(std_dev(r));   // square forms the element-wise square 
  sub_r=r(1,T);    // form a subvector so we can use vector operations
  Mean=mean(r);    // calculate the mean of the vector r 
PROCEDURE_SECTION
  eps2=square(sub_r-Mean);   
  h(1)=a0+a2*h0;
  for (int t=2;t<=T;t++)
  {
    h(t)=a0+a1*eps2(t-1)+a2*h(t-1);
  }
  // calculate minus the log-likelihood function
  log_likelihood=.5*sum(log(h)+elem_div(eps2,h));  // elem_div performs  
                                // element-wise division of vectors
RUNTIME_SECTION
  convergence_criteria .1, .1, .001
  maximum_function_evaluations 20, 20, 1000
We have used vector operations such as elem_div and sum to simplify the code. Of course the code could also have employed loops and element-wise operations. The parameter values and standard deviation report for this model appears below.

 index         value      std dev       1       2       3       4   
    1   a0    1.6034e-04 2.3652e-05  1.0000
    2   a1    9.3980e-02 2.0287e-02  0.1415  1.0000
    3   a2    3.7263e-01 8.2333e-02 -0.9640 -0.3309  1.0000
    4   Mean -1.7807e-04 3.0308e-04  0.0216 -0.1626  0.0144  1.0000
This example employs bounded initial parameters. Often it is necessary to put bounds on parameters in nonlinear modeling to ensure that the minimization is stable. In this example a0 is constrained to lie between and

  init_bounded_number a0(0.0,1.0)
  init_bounded_number a1(0.0,1.0,2)
  init_bounded_number a2(0.0,1.0,3)

Section 12 Carrying out the minimization in a number of phases

For linear models one can simply estimate all the model parameters simultaneously. For nonlinear models often this simple approach does not work very well. It may be necessary to keep some of the parameters fixed during the initial part of the minimization process and carry out the minimization over a subset of the parameters. The other parameters are included into the minimization process in a number of phases until all of the parameters have been included. AD Model Builder provides support for this multi-phase approach. In the declaration of any initial parameter the last number, if present, determines the phase of the minimization during which this parameter is included (becomes active). If no number is present the initial parameter becomes active in phase 1. In this case a0 has no phase number and so becomes active in phase 1. a1 becomes active in phase 2, and a2 becomes active in phase 3. In this example phase 3 is the last phase of the optimization.

It is often convenient to modify aspects of the code depending on which phase of the minimization procedure is the current phase or on whether a particular initial parameter is active. The function


current_phase()
returns an integer (object of type int) which is the value of the current phase. The function
 
last_phase()
returns the value ``true'' ( ) if the current phase is the last phase and false ( ) otherwise. If xxx is the name of any initial parameter the function
 
active(xxx) 
returns the value ``true'' if xxx is active during the current phase and false otherwise.

After the minimization of the objective function has been completed AD Model Builder calculates the estimated covariance matrix for the initial parameters as well as any other desired parameters which have been declared to be of sd_report type. Often these additional parameters may involve considerable additional computational overhead. If the values of these parameters are not used in calculations proper, it is possible to only calculate them during the standard deviations report phase.

 
sd_phase()
The sd_phase function returns the value ``true'' if we are in the standard deviations report phase and ``false'' otherwise. It can be used in a conditional statement to determine whether to perform calculations associated with some sd_report object. When estimating the parameters of a model by a multi-phase minimization procedure the default behavior of AD Model Builder is to carry out the default number of function evaluations until convergence is achieved in each stage. If we are only interested in the parameter estimates obtained after the last stage of the minimization it is often not necessary to carry out the full minimization in each stage. Sometimes considerable time can be saved by relaxing the convergence criterion in the initial stages of the optimization. The RUNTIME_SECTION allows the user to modify the default behavior of the function minimizer during the phases of the estimation process.

RUNTIME_SECTION
  convergence_criteria .1, .1, .001
  maximum_function_evaluations 20, 20, 1000
The convergence_criteria affects the criterion used by the function minimizer to decide when the optimization process has occurred. The function minimizer compares the maximum value of the vector of derivatives of the objective function with respect to the independent variables to the numbers after the convergence_criteria keyword. The first number is used in the first phase of the optimization, the second number in the second phase and so on. If there are more phases to the optimization than there are numbers the last number is used for the rest of the phases of the optimization. The numbers must be separated by commas. The spaces are optional. maximum_function_evaluations The maximum_function_evaluations keyword controls the maximum number of evaluations of the objective function which will be performed by the function minimizer in each stage of the minimization procedure.

NEXT