Serving the Quantitative Finance Community

 
User avatar
junbum
Topic Author
Posts: 0
Joined: May 23rd, 2005, 9:18 pm

correlation matrices for negative eigen values(not positive semi definite)

June 24th, 2005, 8:05 pm

Hello All,Is anyone aware of matlab codes that can condition a correlation matrix that is not positive semi definite as required by cholesky decomposition into a approximate matrix that could be used so that i can use to generate multi-varaiate numbers out of that.Help is required..
 
User avatar
JWD
Posts: 13
Joined: March 2nd, 2005, 12:51 pm
Contact:

correlation matrices for negative eigen values(not positive semi definite)

June 24th, 2005, 9:34 pm

Hi junbum,This is a classic problem. There are several threads on the Wilmott Forum that deal with this topic. Basically what you have to do is to construct a positive-definite matrix that approximates the non-positive-definite matrix that you have now. You can do this by applying the singular value decomposition SVD, throwing away the negative eigenvalues, and renormalizing. This is enough, but it is not optimal. To get an optimal solution you need to rotate the eigenfunctions appropriately. This can be done by using the N-sphere to parametrize the correlations in such a way that a positive definite matrix is assured. Using a least squares routine to move around on the N-sphere to minimize chisquare gives a numerically optimal solution. My book has the details. The optimization technique works in practice with matrices of dimension of up to at least 500x500.----------
Last edited by JWD on June 24th, 2005, 10:00 pm, edited 1 time in total.
Jan Dash, PhD

Editor, World Scientific Encyclopedia of Climate Change:
https://www.worldscientific.com/page/en ... ate-change

Book:
http://www.worldscientific.com/doi/abs/ ... 71241_0053
 
User avatar
junbum
Topic Author
Posts: 0
Joined: May 23rd, 2005, 9:18 pm

correlation matrices for negative eigen values(not positive semi definite)

June 25th, 2005, 7:48 pm

are there any popular coputer codes in matlab or something like that that can accomplish this.Hlp would be apprecaited as i have to deal with this immediately...
 
User avatar
JWD
Posts: 13
Joined: March 2nd, 2005, 12:51 pm
Contact:

correlation matrices for negative eigen values(not positive semi definite)

June 26th, 2005, 4:18 pm

For the baseline positive-definite approximation, you need to use an SVD routine. If Matlab has one, fine, otherwise there is one in the Numerical Recipes book. You will have to set the negative eigenvalues to a small positive number and do the renormalization yourself. It sounds like you won't have time to do the optimization, which requires a good deal of work. ---------
Jan Dash, PhD

Editor, World Scientific Encyclopedia of Climate Change:
https://www.worldscientific.com/page/en ... ate-change

Book:
http://www.worldscientific.com/doi/abs/ ... 71241_0053
 
User avatar
AlphaNumericus
Posts: 0
Joined: December 25th, 2004, 9:17 pm

correlation matrices for negative eigen values(not positive semi definite)

June 26th, 2005, 7:55 pm

A question you should ask is, why does your matrix have eigenvalues <= 0?You get 0 from rates that are a linear combination of other rates (which happens in real life). You may even get small negative eigenvalues from just numerical noise.But, suppose you have this situation: 3 years of daily quotes for A and B, and 3 months for C. If you use the full 3 years to calculate the historical correlation of A and B, and just the last 3 months to get the correlation of A and C and B and C, then you might have more than numerical noise... at which point you want to choose, do you just assume 0 correlation between C and everything else, and 3 years for A and B; or do you use 3 months for all the rates; or do you apply some procedure that will affect the correlation of A and B in some nasty way.
 
User avatar
rhmari
Posts: 0
Joined: May 27th, 2005, 10:12 am

correlation matrices for negative eigen values(not positive semi definite)

July 28th, 2005, 6:52 am

hii have a problem concerning the correlation matrixi need to find an algorithm which approximate or transform the non positive definite correlation matrix into a positive definite one,so i can apply cholesky decomposition.i need cholesky to price a basket optiondo u have a VBA code for this?it will help me a lotmy e-mail adress is : mohamed.rhmaritlemcani@epfl.chthank you very much for your help
 
User avatar
konovs
Posts: 0
Joined: February 6th, 2002, 8:26 am

correlation matrices for negative eigen values(not positive semi definite)

September 19th, 2005, 8:59 pm

This is quick and dirty, but not optimal.Function Chol(rMatrix) Dim c: c = rMatrix 'Correlation matrix Dim N As Long: N = UBound(c, 1) Dim d() As Double: ReDim d(1 To N, 1 To N) 'Decomposed matrix Dim i As Long, j As Long, k As Long Dim temp As Double For j = 1 To N For i = j To N If j = 1 Then d(i, j) = c(i, j) Else temp = 0 For k = 1 To j If i = j And temp + d(i, k) * d(j, k) > 1 Then d(i, k) = (1 - temp) / d(j, k) End If temp = temp + d(i, k) * d(j, k) Next k If i = j Then d(i, j) = Sqr(1 - temp) Else d(i, j) = (c(i, j) - temp) / d(j, j) End If End If Next i Next j Chol = dEnd Function
 
User avatar
skphang
Posts: 0
Joined: July 14th, 2002, 3:00 am

correlation matrices for negative eigen values(not positive semi definite)

September 21st, 2005, 11:43 am

I am having the same problem as the first poster, and used SVD to create sets of correlated random numbers for Monte Carlo analysis.However, I have found that the covariance matrix derived from the simulated paths does not match the original covariance matrix used to generate the random numbers. Although the variances match quite closely, some of the covariances differ greatly (>50%). This implies that the simulated paths are not correctly correlated. I seem to be able to reduce the covariance differences by increasing the number of simulations. However, I need the analysis to be completed by a certain time, so I hit an upper limit on the number of simulations that may be used.I would be grateful for any comments/suggestions. Thanks very much.
 
User avatar
JWD
Posts: 13
Joined: March 2nd, 2005, 12:51 pm
Contact:

correlation matrices for negative eigen values(not positive semi definite)

September 21st, 2005, 12:03 pm

Hi skphang,Interesting. I have a few questions that may help to clarify things.When you use the SVD, do you wind up with any negative eigenvalues that are subsequently reset to small positive values? Note that at least one version of the SVD (Numerical Recipes) does not exhibit any negative eigenvalue, and hides the minus sign in the right eigenfunction (see my book, p. 326). Are you using anything in addition to the SVD algorithm?Are you using real data to get the correlations? How many variables do you have? Which are the correlations that you find are unstable? Do these have relatively small values?-----------
Jan Dash, PhD

Editor, World Scientific Encyclopedia of Climate Change:
https://www.worldscientific.com/page/en ... ate-change

Book:
http://www.worldscientific.com/doi/abs/ ... 71241_0053
 
User avatar
skphang
Posts: 0
Joined: July 14th, 2002, 3:00 am

correlation matrices for negative eigen values(not positive semi definite)

September 22nd, 2005, 1:33 am

Hi JanDash,I suspect the SVD algorithm may be the cause of the differences. Because everything here revolves around Excel, I am using the SVD function provided by the PopTools Add In - http://www.cse.csiro.au/poptools/. In other words, I am using a black box for SVD...I do not see any negative eigenvalues. I am using real data (implied vols + interest rates) to generate the correlations. The VCV matrix is 26x26. And you are right, most of the correlations that are unstable are relatively small (1E-6, 1E-7).Looking forward to your reply.
 
User avatar
JWD
Posts: 13
Joined: March 2nd, 2005, 12:51 pm
Contact:

correlation matrices for negative eigen values(not positive semi definite)

September 22nd, 2005, 2:03 am

Hi skphang,I don’t know the Excel SVD. Could it be that a negative eigenvalue is being somehow set to a small positive value internally in the routine? Or perhaps very small eigenvalues may be causing the problem. You might try a sample case where you explicitly put in a negative eigenvalue and a very small positive eigenvalue and see what the routine returns. Also look at the right and left eigenfunctions returned by the SVD to see if they are identical or if they differ by a sign in some cases (may be a tell-tale mark of a negative eigenvalue).To check for sure that your correlation matrix from data is positive definite, you might just run it through good old Cholesky and see if you get an answer or if the routine blows up.Another thing you can do to get some insight is look at the convergence of the eigenvalues and eigenfunctions of the correlation matrix from the paths you simulate as a function of the number of paths.Anyway if you have a correlation 10^-6 and a 50% error in that correlation, I would guess it’s not going to affect any physical numbers very much.----------
Jan Dash, PhD

Editor, World Scientific Encyclopedia of Climate Change:
https://www.worldscientific.com/page/en ... ate-change

Book:
http://www.worldscientific.com/doi/abs/ ... 71241_0053
 
User avatar
skphang
Posts: 0
Joined: July 14th, 2002, 3:00 am

correlation matrices for negative eigen values(not positive semi definite)

September 22nd, 2005, 3:07 am

Hi JanDash,I don't know if the eigenvalues are too small - they range from 10^-3 to 10^-9. However, the eigenfunctions are identical - which probably confirms your theory about negative eigenvalues. Unfortunately, good old Cholesky doesn't work because the VCV matrix is only positive semi-definite at best. The covariance errors actually go up to 1000%, these are for covariances that are in the 10^-7 range. The variances are in the 10^-4 range. However, I really appreciate your comments about not affecting the physical numbers very much - the correlation is so weak that any correlation errors will probably not matter to the final result.
 
User avatar
skphang
Posts: 0
Joined: July 14th, 2002, 3:00 am

correlation matrices for negative eigen values(not positive semi definite)

September 22nd, 2005, 5:11 am

Oops... asked a question with an obvious answer here.
Last edited by skphang on September 22nd, 2005, 10:00 pm, edited 1 time in total.