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
Outputs
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