Positive Semi-Definite Matrix Example
To illustrate @POSD, suppose we have a covariance matrix for three stocks, AAPL, AMZN and GOOG. This covariance matrix was "computed" by making an educated guess of what the covariances are amongst our three stocks. A requirement for covariance matrices is that they be positive semi-definite (POSD). It turns out that by estimating the covariance matrix, it's possible that the resulting matrix is not truly POSD. To resolve this problem, we will find a new matrix that is close to our original matrix, but with the requirement that the new matrix be positive semi-definite. The model follows:
MODEL:
SETS:
STOCK;
SXS( STOCK, STOCK): XG, XP, ERROR;
ENDSETS
DATA:
STOCK= AAPL GOOG AMZN;
! We have some "guesstimates" of individual entries
of a covariance matrix, however, taken together,
the resulting matrix happens to not be Positive Definite
and thus not a valid covariance matrix;
XG =
.011 -.013 .012
-.013 .061 .07
.012 .07 .06 ;
ENDDATA
! Find a symmetric matrix XP that is close to XG
but is positive definite;
! Minimize some measure of difference between XG and XP;
MIN = @SUM( SXS( I, J): ERROR( I, J)^2);
! Measure the errors;
@FOR( SXS( I, J):
ERROR( I, J) = XP( I, J) - XG( I, J);
@FREE( ERROR);
);
! Off diagonal terms can be negative;
@FOR( SXS( I, J) | I #NE# J: @FREE( XP( I, J)));
! The new matrix must be positive semi-definite;
@POSD( XP);
DATA:
@TEXT() = 'Our initial guess matrix:';
@TEXT() = @TABLE(XG);
@TEXT() = '';
@TEXT() = 'A Positive Semi-Definite matrix close to our guess:';
@TEXT() = @TABLE(XP);
@TEXT() = '';
ENDDATA
END
Model: POSDCOVMTX
The basic idea behind the model is that the solver should find a new matrix, XP, that is close to our guess matrix, XG, as measured by the sum of the squared differences of each of the matrix elements, and that XP must be POSD. The following use of @POSD forces the POSD requirement on XP:
! The new matrix must be positive semi-definite;
@POSD( XP);
The data section of the model uses the @TABLE function to display both the original non-POSD matrix and the new POSD matrix:
Our initial guess matrix:
AAPL GOOG AMZN
AAPL 0.1100000E-01 -0.1300000E-01 0.1200000E-01
GOOG -0.1300000E-01 0.6100000E-01 0.7000000E-01
AMZN 0.1200000E-01 0.7000000E-01 0.6000000E-01
A Positive Semi-Definite matrix close to our guess:
AAPL GOOG AMZN
AAPL 0.1590567E-01 -0.6982941E-02 0.5975522E-02
GOOG -0.6982941E-02 0.6838027E-01 0.6261064E-01
AMZN 0.5975522E-02 0.6261064E-01 0.6739848E-01