File
my_trirnd.m
Name
my_trirnd
Synopsis
my_trirnd - creates a sample of random variables from a triangular distribution.
Introduction
NOTE: PART OF A SET OF 2 RELATED FILES:
The Distressed Insurance Premium (DIP) is proposed as an ex ante systemic risk metric by Huang, Zhou, and Zhu (2009b) and it represents a hypothetical insurance premium against a systemic financial distress, defined as total losses that exceed a given threshold, say 15%, of total bank liabilities. The methodology is general and can apply to any pre-selected group of firms with publicly tradable equity and CDS contracts. Each institutions marginal contribution to systemic risk is a function of its size, probability of default (PoD), and asset correlation. The last two components need to be estimated from market data.
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:
% min_val The min value of the support function of the triangular
% distribution
% mode The mode of the distribution
% max_val The max value of the support function of the triangular
% distribution
% n The number of samples will be created
% This is the cdf for the mode. For a symmetric triangular distribution
% will be 0.5
F_mode = (mode-min_val)^2/((max_val-min_val)*(mode-min_val));
% Create a uniform random vector
u = rand(n,1);
r = zeros(n,1);
% Create the random sample
for i=1:n
if u(i)<F_mode
r(i) = min_val + sqrt(u(i)*(max_val-min_val)*(mode-min_val));
else
r(i) = max_val - sqrt((1-u(i))*(max_val-min_val)*(max_val-mode));
end
end
Examples
NOTE: Numbers used in the examples are arbitrary valid values.
They do not necessarily represent a realistic or plausible scenario.
min_val = 0.5;
mode = 1;
max_val = 1.5;
n = 8;
r = my_trirnd(min_val, mode, max_val, n);
References