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

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)
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, 1000The 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.