Code covered by the BSD License

# Risk and Asset Allocation

### Attilio Meucci (view profile)

16 Nov 2005 (Updated )

Software for quantitative portfolio and risk management

S_KendallTau.m
```% this script simulates and computes analytically Kendall's tau
% for a log-normal distribution
% see "Risk and Asset Allocation"-Springer (2005), by A. Meucci

close all; clc; clear;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% input parameters
NumSimul=1000;

% input for bivariate normal distribution
r=-.99;
Mu=[1 3]';      % NOTE: this input plays no role in the final output
s=[2 5]';    % NOTE: this input plays no role in the final output

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate bivariate normal distribution
Sigma = diag(s)*[1 r;r 1]*diag(s);

Y = mvnrnd(Mu,Sigma,NumSimul);
X = exp(Y);                         % bi-variate log-normal simulation
U=[U_1 U_2];                        % copula

% generate independent copy
YY = mvnrnd(Mu,Sigma,NumSimul);      % bi-variate normal simulation
XX = exp(YY);                             % bi-variate log-normal simulation
UU=[UU_1 UU_2];                        % copula

% sample-based equivalent representation
Concord_Up=(X(:,1)-XX(:,1)).*(X(:,2)-XX(:,2))>0;
Concord_Down=(X(:,1)-XX(:,1)).*(X(:,2)-XX(:,2))<0;
Tau_Sample=sum(Concord_Up-Concord_Down)/NumSimul

% sample-based integration
Tau_Integr=4*mean(NormalCopulaCDF(U,Mu,Sigma)-1/4)

% analytical
Tau_Anal=2/pi*asin(r)

```