inducing correlation with contraints

1 view (last 30 days)
Michael
Michael on 29 Jun 2011
Hi, I'm busy doing my thesis but I keep running into this problem: I'm trying to generate several series that are correlated. One must be able to specify this correlation though (as a function input). However, there is the additional constraint that no value in any of the series can be less than -1. I need to also be able to specify the mean and variance of each series as a function input. Oh and the values should be drawn from a normal distribution. Can anyone help me? This has been holding me up for days! Thanks!! This is my code so far:
function [Returns,Z,C]= cholesky1(numberShares,numberReturns,varMatrixInput,inducedCorrInput,meanInput)
var_matrix = diag(varMatrixInput);
inducedCorr_matrix = inducedCorrInput;
A = randn(length(var_matrix),length(var_matrix));
%Creates a matrix that has a size determined by the number of shares. This
%matrix is used to create the variance-covariance matrix.
B = tril(A,-1);
%This creates a lower triangular matrix (the function tril does this)
%without the diagonals (the minus one does this).
for i = 2:length(var_matrix)
B(i,1) = inducedCorr_matrix(1,i)*sqrt(var_matrix(i,i))*sqrt(var_matrix(1,1));
end
var_cov_matrix = B+ B' + var_matrix;
C = chol(var_cov_matrix);
Z = randn(numberReturns,numberShares);
Returns = Z*C;
end
This does everything perfectly, inducing the correlation,, mean and variance, but allows values to be less than -1. Does anyone have any idea how to fix this without affecting the correlation etc? Any input would be appreciated!
  1 Comment
Walter Roberson
Walter Roberson on 29 Jun 2011
This is at least your fourth question asking the same thing. Please do not create duplicate questions. You can edit previous questions to add new information.

Sign in to comment.

Answers (1)

Sean de Wolski
Sean de Wolski on 29 Jun 2011
Add a scalar to your mean. It's impossible to fix a variance and a mean on a normal distribution and then constrain it to not include values that would appear under the bell curve.
E.g.
the_mean = 2;
the_var = 11;
You can't have a normal distribution without values less than negative one.

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!