Table of Contents


File

fit_ar_model.m

Name

fit_ar_model

Synopsis

fit_ar_model - Fits an AR model to the y-series representing GDP data. It selects the order that is less than max_order and minimizes the BIC.

Introduction

NOTE: PART OF A SET OF 2 RELATED FILES:

Alfaro and Drehmann (2009) propose a macroeconomic stress test using a simple AR model of GDP growth which is assumed to depend only on its past behavior. The reason the authors focus on GDP is they observe that domestic macroeconomic conditions as measured by GDP growth typically weaken ahead of banking crises. Furthermore, output drops substantially in nearly all of the observed crises once stress emerges. Their approach to stress testing uses this as a starting point to construct GDP scenarios, independently of whether falls in output truly reflect or cause crises. Their guiding principle in creating their GDP shocks is that stress scenarios should be severe yet plausible.

License

=============================================================================

Copyright 2011, Dimitrios Bisias, Andrew W. Lo, and Stavros Valavanis

COPYRIGHT STATUS: This work was funded in whole or in part by the Office of Financial Research under U.S. Government contract TOSOFR-11-C-0001, and is, therefore, subject to the following license: The Government is granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license to reproduce, prepare derivative works, distribute copies to the public, perform and display the work.
All other rights are reserved by the copyright owner.

THIS SOFTWARE IS PROVIDED "AS IS". YOU ARE USING THIS SOFTWARE AT YOUR OWN RISK. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS, OR THE UNITED STATES GOVERNMENT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=============================================================================

Inputs

y_series
Name:
y_series
Description:

N x 1 matrix indicates quarterly real GDP growth data.

Type:
float
Range:
(-1,+inf)
Dimensions:

Nx1 matrix

  1. Rows represent quarters (dates are ascending).

max_order
Name:
max_order
Description:

The maximum number of regressor coefficients.
max_order = 1 + # beta coefficients. This is passed a fixed value of [2] from the stress_scenario_selection.m function.

Type:
integer
Range:
{2,...,floor(N/2)-1}
Dimensions:

scalar


Outputs

order
Name:
order
Description:

The order that produces the lowest Bayesian Information Criterion (BIC).

Type:
integer
Range:
{2,...,max_order}
Dimensions:

scalar


regressor_coefficients
Name:
regressor_coefficients
Description:

Displays calculated beta coefficients.

Type:
float
Range:
(-inf,+inf)
Dimensions:

Nx1 matrix

  1. Rows represent different orders.

Code

% Run warning message
warning('OFRwp0001:UntestedCode', ...
    ['This version of the source code is very preliminary, ' ...
     'and has not been thoroughly tested. Users should not rely on ' ...
     'these calculations.']);





n = length(y_series);
BIC = zeros(max_order,1);
betas = zeros(max_order+1,max_order);

for order = 1:max_order
    % Form the response variables and covariates
    y = y_series(order+1:end);
    X = zeros(n-order,order); 
    for j = 1:order
        X(:,j) = y_series(order+1-j:end-j);   
    end

    whichstats = {'beta', 'r'};
    % The constant term is added automatically
    stats = regstats(y,X,'linear',whichstats);
    betas(1:order+1,order) = stats.beta;
    r = stats.r;

    % Instead of s^2 we use the maximum likelihood estimate of variance
    % i.e. we divide r'*r by n instead of n - num_regressors
    BIC(order)=n*log(r'*r/n)+order*log(n);
end

% Find the minimum bic and the corresponding regressor coefficients
[bic_min, min_order] = min(BIC);
regressor_coefficients = betas(1:min_order+1,min_order);
order = min_order;

Examples

NOTE: Numbers used in the examples are arbitrary valid values.
They do not necessarily represent a realistic or plausible scenario.

 y_series = [5.3, 3.4, -1.1, 2.3, 2.3, 4.8, 3.3, 4.5]';

 max_order = 3;

 [regressor_coefficients, order] = fit_ar_model(y_series, max_order);

References

Alfaro, R., & Drehmann, M. (2009). Macro stress tests and crises: what can we learn?. BIS Quarterly Review.

Bisias et al. (2012). A survey of systemic risk analytics (Working paper #0001). Washington, DC: Office of Financial Research, 100-101.