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_SpearmanRho.m
```% this script computes Spearman's rho in simulation
% for a log-normal distribution
% see "Risk and Asset Allocation"-Springer (2005), by A. Meucci

close all; clc; clear;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% input parameters
NumSimul=50000;

% input for bivariate normal distribution
r=.999;
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 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);
XX = exp(YY);                             % bi-variate log-normal simulation
UU=[UU_1 UU_2];                        % copula

% generate another independent copy
YYY = mvnrnd(Mu,Sigma,NumSimul);
XXX = exp(YYY);                             % bi-variate log-normal simulation
UUU=[UUU_1 UUU_2];                        % copula

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute rho

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