Codes in Matlab and others

Codes for nearest (covariance) correlation matrix problems

  • Codes for the Nearest Correlation Matrix problem (the problem was initially introduced by Prof. Nick Higham): CorrelationMatrix.m is a Matlab code written for computing the nearest correlation matrix problem (first uploaded in August 2006; last updated on August 30, 2019). This code should be good enough for most Matlab users. If your Matlab version is very low and you really need a faster code, you can download mexeig.mexw64 (for win64 operating system) and if use win32 or Linux system, you need to download the installmex file installmex.m and the c-file mexeig.c by running the installmex.m first. For a randomly generated 3,000 by 3,000 pseudo correlation matrix (the code is insensitive to input data), the code needs 24 seconds to reach a solution with the relative duality gap less than 1.0e-3 after 3 iterations and 43 seconds with the relative duality gap less than 1.0e-10 after 6 iterations in my Dell Desktop with Intel (R) Core i7 processor and for an invalid 10,000 by 10,000 pseudo correlation matrix, the code needs 15 minutes to reach a solution with the relative duality gap less than 1.0e-4 after 4 iterations and 24 minutes with the relative duality gap less than 1.0e-12 after 7 iterations. For practitioners, you may set the stopping criterion (relative duality gap) to stay between 1.0e-1 and 1.0e-3 to run the code (typically, 1 to 3 iterations). If you need a C/C++ code, download main.c and main.h, which were written by Pawel Zaczkowski under a summer research project. If you are a client to The Numerical Algorithms Group (NAG), you may also enjoy their commercialized implementations. The code in R CorrelationMatrix.R was written by Ying Cui (last updated on August 31, 2019; for efficiency, please use Microsoft R open) and the code in Python CorrelationMatrix.py was written by Yancheng Yuan (last updated on May 11, 2017), respectively.
  • CorNewton3.m Computing the Nearest Correlation Matrix with fixed diagonal and off diagonal elements (uploaded on September 14, 2009). The code in R CorNewton3.R was provided by Professor Luca Passalacqua (luca.passalacqua@uniroma1.it) (uploaded on October 7, 2016; for efficiency, please use Microsoft R open).
  • CorNewton3_Wnorm.m Computing the W-norm Nearest Correlation Matrix with fixed diagonal and off diagonal elements Testing example: testCorMatWnorm.m(uploaded on September 14, 2009).
  • CorMatHdm.m Calibrating the H-weighted Nearest Correlation Matrix Testing example: testCorMatHdm.m (uploaded in June 2008; last updated on September 10, 2009).
  • CorMatHdm_general.m Computing the H-weighted Nearest Correlation Matrix with fixed elements and lower and upper bounds [H should not have too many zero elements for better numerical performance; otherwise, see CaliMatHdm] Testing example: testCorMatHdm_general.m (uploaded on September 14, 2009).
  • LagDualNewton.m (this is superseded by CorNewton3.m) Testing example: testLagDualNewton.m (LagDualNewton method for the Band Correlation Stress Testing, “CorNewton1.m” will be called).
  • CorNewtonSchur.m Testing example: testCorNewtonSchur.m (Schur decomposition based method for the Local Correlation Stress Testing, “CorNewton1.m” will be called).
  • AugLagNewton.m (this is superseded by CorMatHdm_general.m) Testing example: testAugLagNewton.m (AugLagNewton method for the Band Correlation Stress Testing, “CorNewton1.m” will be called). (uploaded in March 2007).
  • CaliMat1Mex.zip (Codes and testing example for) Calibrating Covariance Matrix Problems with Inequality and/or Equality Constraints (uploaded in April 2010).
  • CaliMatHdm.zip Calibrating the H-weighted Nearest Covariance Matrix [H is allowed to have a large number of zero elements] (uploaded in April 2010).
  • Rank_CaliMat.zip Calibrating the Nearest Correlation Matrix with Rank Constraints (uploaded in April 2010).
  • Rank_CaliMatHdm.zip Calibrating the H-weighted Nearest Correlation Matrix with Rank Constraints (uploaded in April 2010; last updated in October 2010 by including the refined Major codes).

Codes under the Matrix Optimization (MatOpt) Project


Codes under the Statistical Optimization (StaOpt) Project


Codes for rank constrained problems

  • Rank_CaliMat.zip Calibrating the Nearest Correlation Matrix with Rank Constraints (uploaded in April 2010).

  • Rank_CaliMatHdm.zip Calibrating the H-weighted Nearest Correlation Matrix with Rank Constraints (uploaded in April 2010; last updated in October 2010 by including the refined Major codes).


Codes for other problems