Products & Services Solutions Academia Support User Community Company

Learn more about Econometrics Toolbox   

Examples

Presample Data

This example shows you how to specify your own presample data to initiate the estimation process. It highlights the formal column-oriented nature of the presample time series inputs.

  1. Load the nasdaq data set and convert prices to returns:

    load garchdata
    nasdaq = price2ret(NASDAQ);
  2. Segment the NASDAQ data to compare estimation results from a relatively stable period to those from a period of relatively high volatility:

    plot(nasdaq)
    axis([0 length(nasdaq) -0.15 0.15])
    set(gca,'XTick',[1 507 1014 1518 2025 2529 3027])
    set(gca,'XTickLabel',{'Jan 1990' 'Jan 1992' 'Jan 1994' ...
        'Jan 1996' 'Jan 1998' 'Jan 2000' 'Jan 2002'})
    ylabel('Return')
    title('Daily Returns')

    The NASDAQ returns show a distinct increase in volatility starting, approximately, in December 1997. This is roughly the 2000th observation.

  3. Create a specification structure to model the NASDAQ returns as an MA(1) process with GJR(1,1) residuals:

    spec = garchset('VarianceModel','GJR','M',1,'P',1,'Q',1,...
           'Display','off');
  4. Estimate the parameters, standard errors, and inferred residuals and standard deviations using the first 2000 observations, allowing garchfit to automatically generate the necessary presample observations. Then display the estimated coefficients and errors.

    [coeff,errors,LLF,eFit,sFit] = garchfit(spec,nasdaq(1:2000));
    garchdisp(coeff,errors)
    
      Mean: ARMAX(0,1,0); Variance: GJR(1,1)
      
      Conditional Probability Distribution: Gaussian
      Number of Model Parameters Estimated: 6
      
                                   Standard          T     
      Parameter       Value          Error       Statistic 
     -----------   -----------   ------------   -----------
               C    0.00056218     0.00023441       2.3983
           MA(1)    0.24968        0.024171        10.3296
               K    1.1778e-005    1.5178e-006      7.7598
        GARCH(1)    0.69678        0.033512        20.7921
         ARCH(1)    0.025176       0.017674         1.4245
     Leverage(1)    0.24384        0.030339         8.0371
  5. This conditional mean model has no regression component. Therefore, you can obtain the same estimation results by calling garchfit with an empty regression matrix, X = [], as a placeholder for the third input:

    [coeff,errors,LLF,eFit,sFit] = garchfit(spec,...
           nasdaq(1:2000),[]); 
  6. Specify your own presample data by specifying additional inputs. Because the inputs PreInnovations, PreSigmas, and PreSeries represent time series in a formal sense, provide required presample data in the form of column vectors of sufficient length.

    From the table in Presample Data:

    • The length of PreInnovations must be at least max(M,Q) = 1.

    • The length of PreSigmas must be at least P = 1.

    • and PreSeries can be empty or unspecified altogether because R = 0.

    Estimate the same model from the later high-volatility period, using the inferred residuals and standard deviations from the previous period as the presample data:

    [coeff,errors] = garchfit(spec,nasdaq(2001:end),[],eFit,sFit);
    garchdisp(coeff, errors)
    
      Mean: ARMAX(0,1,0); Variance: GJR(1,1)
      
      Conditional Probability Distribution: Gaussian
      Number of Model Parameters Estimated: 6
    
                                   Standard          T     
      Parameter       Value          Error       Statistic 
     -----------   -----------   ------------   -----------
               C    0.00065364     0.0006048        1.0807
           MA(1)    0.012687       0.035128         0.3612
               K    1.7805e-005    3.9083e-006      4.5557
        GARCH(1)    0.85819        0.026208        32.7452
         ARCH(1)    0.016099       0.022569         0.7133
     Leverage(1)    0.17418        0.0332           5.2464

    Comparing the estimation results from the two periods reveals a marked difference. The last input, PreSeries, is not needed and is left unspecified.

  7. Since the example uses only the most recent observations of PreInnovations, PreSigmas, and PreSeries, any of the following calls to garchfit produce identical estimation results:

    [coeff,errors] = garchfit(spec,nasdaq(2001:end),[],...
           eFit(end),sFit(end));
    [coeff,errors] = garchfit(spec,nasdaq(2001:end),[],...
           eFit(end),sFit(end),nasdaq(1:2000));
    [coeff,errors] = garchfit(spec,nasdaq(2001:end),...
           [],eFit,sFit,nasdaq(1999:2000));

    The first equivalent call passes in the minimum required presample observations of past residuals and standard deviations. In this case, it passes the last inferred observation of each. The last two equivalent calls specify an unnecessary presample return series, which garchfit ignores.

    If, for example, the original specification included an AR(2) model (that is, R = 2), then at least the last two NASDAQ returns are needed to initiate estimation. In this case, the last two calls to garchfit would produce identical results for conditional mean models with AR components up to 2nd order.

Inferring Residuals

This example shows how to:

  1. Simulate a return series, yTrue.

  2. Use the garchinfer function to infer {εt} and {σt} from the simulated return series.

First, you use automatically generated presample data to infer the approximate residuals and conditional standard deviation processes. You then use explicitly specified presample data to infer the exact residuals and conditional standard deviation processes. You then finally compare the approximate conditional standard deviation processes with the exact conditional standard deviations processes, to reveal the effect of transients in the approximate results. The effect of transients in the estimation, or inference, process parallels that in the simulations process described in Automatically Generating Presample Data.

To avoid introducing differences as a result of the optimization, this example uses garchinfer rather than garchfit. garchsim uses an ARMA model as a linear filter to transform an uncorrelated input innovations process {εt} into a correlated output returns process {yt}. garchinfer (and alternatively, garchfit) reverses this process by inferring innovations {εt} and standard deviation {σt} processes from the observations in {yt}.

  1. Specify a time series as an AR(2) conditional mean model and GARCH(1,2) conditional variance model:

    spec = garchset('C',0,'AR',[0.5 -0.8],'K',0.0002,... 
                    'GARCH',0.8,'ARCH',[0.1 0.05])
    spec = 
    
              Comment: 'Mean: ARMAX(2,0,?); Variance: GARCH(1,2)'
         Distribution: 'Gaussian'
                    R: 2
                    C: 0
                   AR: [0.5000 -0.8000]
        VarianceModel: 'GARCH'
                    P: 1
                    Q: 2
                    K: 2.0000e-004
                GARCH: 0.8000
                 ARCH: [0.1000 0.0500]

      Note   This is an elaborate specification, typically unwarranted for a real-world financial time series, and is meant for illustrative purposes only.

  2. Simulate 102 observations for each of 5 realizations and reserve the first 2 rows of observations for the presample data needed by garchinfer in step 4. The table in Running Simulations With User-Specified Presample Data shows that:

    • The PreInnovations array must have at least max(M,Q) = 2 rows.

    • PreSigmas must have at least P = 1 row.

    • PreSeries must have at least R = 2 rows.

    Add the initial state = 0 as a trailing input argument:

    strm = RandStream('mt19937ar','Seed',857142);
    RandStream.setDefaultStream(strm);
    [eTrue,sTrue,yTrue] = garchsim(spec,102,5);

  3. Call garchinfer without explicit presample data, using observations 3 and beyond as the observed return series input. This infers the approximate residuals and conditional standard deviations based on the default presample data inference approach:

    [eApprox,sApprox] = garchinfer(spec,yTrue(3:end,:));

    For more information, see the garchfit and garchinfer function reference pages.

  4. Call garchinfer again, but this time use the first two rows of the true simulated data as presample data. Use of the presample data allows you to infer the exact residuals and conditional standard deviations:

    [eExact,sExact] = garchinfer(spec,yTrue(3:end,:),[],...
                      eTrue(1:2,:),sTrue(1:2,:),yTrue(1:2,:));

  5. Compare the first realization of the approximate and the exact inferred conditional standard deviations reveals the distinction between automatically generated and user-specified presample data:

    plot(sApprox(:,1),'red')
    grid('on'),hold('on')
    plot(sExact(:,1),'blue')
    title('Approximate Versus Exact Inferred Standard Deviations')

    The approximate and exact standard deviations are asymptotically identical. The only difference between the two curves is attributable to the transients induced by the default initial conditions. If you were to plot the first realization of the original simulated conditional standard deviations, sTrue(3:end,1), on the current figure, it would lie on top of the blue curve.

    Although the previous figure highlights the first realization of conditional standard deviations, the comparison holds for any realization and for the inferred residuals.

Thus, this example reveals the link between simulation and inference: you can think of garchsim as a correlation filter capable of processing multiple realizations simultaneously. It is the complement of garchinfer, which you can think of as a whitening, or inverse, filter capable of processing multiple realizations simultaneously. The garchfit estimation engine can process only a single realization at a time. However, the transient effects highlighted in this example are the same when applied to the estimation.

Estimating ARMA(R,M) Parameters

This example shows how you can use the Econometrics Toolbox software as a general-purpose univariate time series processor. It demonstrates how to estimate the parameters of ARMA(R,M) models. It uses an alternative technique and the presample inputs PreInnovations and PreSeries, and assumes a simple constant variance model.

Default Method

Estimation requires presample data to initiate the inverse filtering process. In the absence of explicit presample data, garchfit assigns the R required presample observations of yt, that is, Series, the sample mean of Series. It also assigns the M required presample observations of εt, that is, the innovations, or residuals, their expected value of zero. This method then calculates the loglikelihood objective function value using all the available data in Series, and is the default Econometrics Toolbox method.

Alternative Method

Another method also sets the M required presample observations of the residuals, εt, to zero, but uses the first R actual observations of Series as initial values. Thus, {y1, y2, ..., yR} are used to initiate the inverse filter, and the loglikelihood objective function value is based on the remaining observations. See Hamilton [31], page 132, or Box, Jenkins, and Reinsel [10], pages 236-237.

For example, assume that you have some hypothetical time series, xyz, and you want to estimate an ARMA(R,M) model with constant conditional variances. Using the alternative presample method, you would exclude the first R observations of xyz from the input Series, and reserve them for the input PreSeries. Specifically, you would set the input Series = xyz(R+1:end), PreInnovations = zeros(M,1), PreSigmas = [], and PreSeries = xyz(1:R).

Lower Bound Constraints

This example illustrates an active lower bound constraint, κ > 0, for the conditional variance constant κ. This constraint is required for GARCH and GJR variance models to ensure a positive conditional variance process. It also illustrates how to identify such active constraints, and what to do about this most commonly encountered active constraint. See Optimization Termination.

  1. Load the NYSE data set and convert prices to returns:

    load garchdata
    nyse = price2ret(NYSE);
    plot(nyse)
    axis([0 length(nyse) -0.08 0.06])
    set(gca,'XTick',[1 507 1014 1518 2025 2529 3027])
    set(gca,'XTickLabel',{'Jan 1990' 'Jan 1992' 'Jan 1994' ...
        'Jan 1996' 'Jan 1998' 'Jan 2000' 'Jan 2002'})
    set(gca,'YTick',[-0.08:0.02:0.06])
    ylabel('Return')
    title('Daily Returns')

  2. Estimate a default GARCH(1,1) model and print the estimation results. For this example, TolCon = 1e-6. Iterative display is disabled due to space constraints:

    spec = garchset('Display','off','P',1,'Q',1,'TolCon',1e-6);
    [coeff,errors,LLF,eFit,sFit,summary] = garchfit(spec,nyse);
    garchdisp(coeff,errors)
    
      Mean: ARMAX(0,0,0); Variance: GARCH(1,1)
      
      Conditional Probability Distribution: Gaussian
      Number of Model Parameters Estimated: 4
      
                                   Standard          T     
      Parameter       Value          Error       Statistic 
     -----------   -----------   ------------   -----------
               C    0.00051946     0.00013701       3.7914
               K    2e-006         2.8191e-007      7.0944
        GARCH(1)    0.87166        0.0095166       91.5935
         ARCH(1)    0.10419        0.0073769       14.1237
  3. Examination of these results reveals the estimated variance constant K = 2e-006 = 0 + 2*TolCon = 2*TolCon. That is, κ is equal to the theoretical lower bound plus 2*TolCon. You can see this by printing the summary structure and looking at the constraints message field:

    summary
    
    summary = 
             exitFlag: 4
              warning: 'No Warnings'
             converge: 'Function Converged to a Solution'
          constraints: 'Boundary Constraints Active: 
                        Standard Errors May Be Inaccurate'
            covMatrix: [4x4 double]
           iterations: 14
        functionCalls: 102
               lambda: [1x1 struct]
  4. Print the lower and upper bound Lagrange multipliers and examine them for nonzero values:

    [summary.lambda.lower  summary.lambda.upper]
    
    ans =
      1.0e+006 *
             0         0
        7.4552         0
             0         0
             0         0

    The garchdisp function determines the display order of the lower and upper bound Lagrange multipliers. This result shows that the lower bound constraint κ > 0 is active.

  5. Repeat the estimation with the default TolCon = 1e-7 and verify that the constraint is no longer active:

    spec = garchset('Display','off','P',1,'Q',1);
    [coeff,errors,LLF,eFit,sFit,summary] = garchfit(spec,nyse);
    garchdisp(coeff,errors)
    
      Mean: ARMAX(0,0,0); Variance: GARCH(1,1)
    
      Conditional Probability Distribution: Gaussian
      Number of Model Parameters Estimated: 4
    
                                   Standard          T     
      Parameter       Value          Error       Statistic 
     -----------   -----------   ------------   -----------
               C    0.00049332     0.00013109       3.7633
               K    8.4637e-007    1.5251e-007      5.5496
        GARCH(1)    0.91281        0.0067941      134.3532
         ARCH(1)    0.078639       0.0057612       13.6497
    summary
    summary = 
             exitFlag: 5
              warning: 'No Warnings'
             converge: 'Function Converged to a Solution'
          constraints: 'No Boundary Constraints'
            covMatrix: [4x4 double]
           iterations: 16
        functionCalls: 143
               lambda: [1x1 struct]
    [summary.lambda.lower  summary.lambda.upper]
    ans =
         0     0
         0     0
         0     0
         0     0

Determining Convergence Status

There are two ways to determine whether an estimation achieves convergence:

  1. To illustrate these methods, use the DEM2GBP (Deutschmark/British pound foreign-exchange rate) data:

    load garchdata
    dem2gbp = price2ret(DEM2GBP);
    [coeff,errors,LLF,eFit,sFit,summary] = ...
       garchfit(dem2gbp);
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       Diagnostic Information 
    
    Number of variables: 4
    
    Functions 
     Objective:                            garchllfn
     Gradient:                             finite-differencing
     Hessian:                              finite-differencing (or Quasi-Newton)
     Nonlinear constraints:                armanlc
     Gradient of nonlinear constraints:    finite-differencing
    
    Constraints
     Number of nonlinear inequality constraints: 0
     Number of nonlinear equality constraints:   0
     
     Number of linear inequality constraints:    1
     Number of linear equality constraints:      0
     Number of lower bound constraints:          4
     Number of upper bound constraints:          4
    
    Algorithm selected
       medium-scale
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     End diagnostic information 
    
                                    Max     Line search  Directional  First-order 
     Iter F-count        f(x)   constraint   steplength   derivative   optimality
                                                                       Procedure 
        0      5     -7915.72   -2.01e-006                                         
        1     27     -7916.01   -2.01e-006    7.63e-006   -7.68e+003    1.41e+005   
        2     34     -7959.65  -1.508e-006         0.25         -974    9.85e+007   
        3     42     -7964.03  -3.102e-006        0.125         -380     5.1e+006   
        4     48      -7965.9  -1.578e-006          0.5        -92.8    4.43e+007   
        5     60        -7967  -1.566e-006      0.00781         -520     1.6e+007   
        6     67     -7967.28  -2.407e-006         0.25         -231    2.23e+007   
        7     75     -7972.64  -2.711e-006        0.125         -177    8.62e+006   
        8     81     -7981.52  -1.356e-006          0.5         -150    1.33e+007   
        9     93     -7981.75  -1.473e-006      0.00781        -72.7    2.59e+006   
       10     99     -7982.65  -7.366e-007          0.5        -45.5    1.89e+007   
       11    107     -7983.07  -8.324e-007        0.125        -79.7    4.93e+006   
       12    116     -7983.11  -1.224e-006       0.0625        -20.5    7.44e+006   
       13    121      -7983.9  -7.634e-007            1        -32.5    1.42e+006   
       14    126     -7983.95  -7.982e-007            1        -7.62    6.66e+005   
       15    134     -7983.95  -7.972e-007        0.125        -13.1    5.73e+005   
    Optimization terminated: directional derivative predicts change in
      objective value less than options.TolFun and maximum constraint violation
      is less than options.TolCon.
    No active inequalities.

    The optimization details indicate successful termination.

  2. Now examine the summary output structure:

    summary
    summary = 
             exitFlag: 5
              warning: 'No Warnings'
             converge: 'Function Converged to a Solution'
          constraints: 'No Boundary Constraints'
            covMatrix: [4x4 double]
           iterations: 16
        functionCalls: 148
               lambda: [1x1 struct]

    The converge field indicates successful convergence. If the estimation failed to converge, the converge field would contain the message Function Did NOT Converge. If the number of iterations or function evaluations exceeded its specified limits, the converge field would contain the message Maximum Function Evaluations or Iterations Reached. The summary structure also contains fields that indicate the number of iterations (iterations) and loglikelihood function evaluations (functionCalls).

  


Free Interactive Computational Finance CD

View demos and recorded presentations led by industry experts.

Now On Demand
Network with industry peers and learn the latest applications of the leading software product for computational finance.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS