Table of Contents


File

quantile_regression.m

Name

quantile_regression

Synopsis

quantile_regression - calculates the q-quantile regression coefficients.

Introduction

NOTE: PART OF A SET OF 3 RELATED FILES:

The Co-Risk measure, first proposed in the IMFs 2009 Global Financial Stability Review (International Monetary Fund, 2009a), examines the co-dependence between the CDS of various financial institutions. It is more informative than unconditional risk measures because it provides a market assessment of the proportional increase in a firms credit risk induced, directly and indirectly, from its links to another firm. Note that the approach used is based on quantile regression, a concept also used in CoVaR (see Adrian and Brunnermeier (2010), a summary of which is presented in Section E.1). The quantile regression approach permits a more accurate estimation of the co-movements of financial institutions risk factors (or co-risk estimates) under distress, taking into account their nonlinear relationship.

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
Name:
y
Description:

The response variable.

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

Tx1 matrix 1. Rows represent dates. 2. The column represents a single firm.


X
Name:
X
Description:

The regressor variables

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

TxK matrix 1. Rows represent dates. 2. Columns represents all independent variables categories.


q
Name:
q
Description:

Indicates desired quantile of the distribution for regression. The paper uses q = 0.95 to indicate distressed regime.

Type:
float
Range:
(0,1)
Dimensions:

scalar


use_cvx
Name:
use_cvx
Description:

Flag to indicate usage of convex optimisation. Set to 0 unless cvx package is installed. Note: values are yes/no flags, represented as 1/0 values, respectively.

Type:
float
Range:
{0, 1}
Dimensions:

scalar


Outputs

betas
Name:
betas
Description:

Returns beta0 plus q-quantile beta regression coefficients

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

Kx1 matrix

  1. Row represents each independent variable.

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.']);


%
% Parameters:
% y The response variable n x 1 vector
% X the matrix of regressors n x k vector
% q the quantile i.e. 0.5 for median regression
% use_cvx  the method to use.

n = size(X,1);
k = size(X,2);
betas = 0;

if use_cvx
    % First way using CVX
    % You will need to install cvx and run cvx_setup
    cvx_begin
    cvx_quiet(true)
        variable u_pos(n)
        variable u_neg(n)
        variable betas(k)
        minimize q*sum(u_pos) + (1-q)*sum(u_neg)
        subject to
            u_pos>=0;
            u_neg>=0;
            X*betas+u_pos-u_neg == y;
    cvx_end
else 
    % Second way
    % LP in Matlab
    c = [q*ones(n,1); (1-q)*ones(n,1); zeros(k,1)];
    A = [-eye(n) zeros(n) zeros(n,k);
         zeros(n) -eye(n) zeros(n,k)
         zeros(k,2*n+k)];
     b = zeros(2*n+k,1);

     Aeq = [eye(n) -eye(n) X];
     beq = y;
     lin_betas = linprog(c,A,b,Aeq,beq);
     betas = lin_betas(end-k+1:end);
end

Examples

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

 output_cds_spreads = [0.04, 0.01, 0.08, 0.09, 0.01]';
 input_cds_spreads = [0.01, 0.01, 0.04, 0.03, 0.06]';
 risk_factors_series = ...
  [-1.2, 0.1; 
   -1.1, 0.7; 
   -0.8, 0.2; 
   -1.3, 1.8; 
   0.3,  2.3];

 q = 0.95
 num_dates = size(output_cds_spreads,1);
 X = [ones(num_dates,1) risk_factors_series input_cds_spreads];

 use_cvx = false;
 betas = quantile_regression(output_cds_spreads, X, q, use_cvx);

References

International Monetary Fund. (2009). Global Financial Stability Report: Responding to the Financial Crisis and Measuring Systemic Risks (working paper). Washington, DC: IMF.

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