naginterfaces.library.correg.corrmat_nearest_bounded(g, opt, alpha=None, w=None, errtol=0.0, maxits=0, maxit=0)[source]

corrmat_nearest_bounded computes the nearest correlation matrix, in the Frobenius norm or weighted Frobenius norm, and optionally with bounds on the eigenvalues, to a given square, input matrix.

For full information please refer to the NAG Library document for g02ab

gfloat, array-like, shape

, the initial matrix.

optstr, length 1

Indicates the problem to be solved.

The lower bound problem is solved.

The weighted norm problem is solved.

Both problems are solved.

alphaNone or float, optional

The value of .

If , need not be set.

wNone or float, array-like, shape , optional

Note: the required length for this argument is determined as follows: if : ; otherwise: .

The square roots of the diagonal elements of , that is the diagonal of .

If , is not referenced and may be None.

errtolfloat, optional

The termination tolerance for the Newton iteration. If , is used.

maxitsint, optional

Specifies the maximum number of iterations to be used by the iterative scheme to solve the linear algebraic equations at each Newton step.

If , is used.

maxitint, optional

Specifies the maximum number of Newton iterations.

If , is used.

xfloat, ndarray, shape

Contains the nearest correlation matrix.


The number of Newton steps taken.


The number of function evaluations of the dual problem.


The norm of the gradient of the last Newton step.

(errno )

On entry, .

Constraint: .

(errno )

On entry, the value of is invalid.

Constraint: , or .

(errno )

On entry, .

Constraint: .

(errno )

On entry, all elements of were not positive.

Constraint: , for all .

(errno )

Newton iteration fails to converge in iterations. Increase or check the call to the function.

(errno )

The machine precision is limiting convergence. In this instance the returned value of may be useful.

(errno )

An intermediate eigenproblem could not be solved. This should not occur. Please contact NAG with details of your call.


Finds the nearest correlation matrix by minimizing where is an approximate correlation matrix.

The norm can either be the Frobenius norm or the weighted Frobenius norm .

You can optionally specify a lower bound on the eigenvalues, , of the computed correlation matrix, forcing the matrix to be positive definite, .

Note that if the weights vary by several orders of magnitude from one another the algorithm may fail to converge.


Borsdorf, R and Higham, N J, 2010, A preconditioned (Newton) algorithm for the nearest correlation matrix, IMA Journal of Numerical Analysis (30(1)), 94–107

Qi, H and Sun, D, 2006, A quadratically convergent Newton method for computing the nearest correlation matrix, SIAM J. Matrix AnalAppl (29(2)), 360–385