def shrink(self):
x = np.nan_to_num(self.X.values)<EOL>t, n = np.shape(x)<EOL>meanx = x.mean(axis=<NUM_LIT:0>)<EOL>x = x - np.tile(meanx, (t, <NUM_LIT:1>))<EOL>xmkt = x.mean(axis=<NUM_LIT:1>).reshape(t, <NUM_LIT:1>)<EOL>sample = np.cov(np.append(x, xmkt, axis=<NUM_LIT:1>), rowvar=False) * (t - <NUM_LIT:1>) / t<EOL>covmkt = sample[<NUM_LIT:0>:n, n].reshape(n, <NUM_LIT:1>)<EOL>varmkt = sample[n, n]<EOL>sample = sample[:n, :n]<EOL>prior = np.dot(covmkt, covmkt.T) / varmkt<EOL>prior[np.eye(n) == <NUM_LIT:1>] = np.diag(sample)<EOL>if self.delta is None:<EOL><INDENT>c = np.linalg.norm(sample - prior, "<STR_LIT>") ** <NUM_LIT:2><EOL>y = x ** <NUM_LIT:2><EOL>p = <NUM_LIT:1> / t * np.sum(np.dot(y.T, y)) - np.sum(sample ** <NUM_LIT:2>)<EOL>rdiag = <NUM_LIT:1> / t * np.sum(y ** <NUM_LIT:2>) - sum(np.diag(sample) ** <NUM_LIT:2>)<EOL>z = x * np.tile(xmkt, (n,))<EOL>v1 = <NUM_LIT:1> / t * np.dot(y.T, z) - np.tile(covmkt, (n,)) * sample<EOL>roff1 = (<EOL>np.sum(v1 * np.tile(covmkt, (n,)).T) / varmkt<EOL>- np.sum(np.diag(v1) * covmkt.T) / varmkt<EOL>)<EOL>v3 = <NUM_LIT:1> / t * np.dot(z.T, z) - varmkt * sample<EOL>roff3 = (<EOL>np.sum(v3 * np.dot(covmkt, covmkt.T)) / varmkt ** <NUM_LIT:2><EOL>- np.sum(np.diag(v3).reshape(-<NUM_LIT:1>, <NUM_LIT:1>) * covmkt ** <NUM_LIT:2>) / varmkt ** <NUM_LIT:2><EOL>)<EOL>roff = <NUM_LIT:2> * roff1 - roff3<EOL>r = rdiag + roff<EOL>k = (p - r) / c<EOL>shrinkage = max(<NUM_LIT:0>, min(<NUM_LIT:1>, k / t))<EOL>self.delta = shrinkage<EOL><DEDENT>else:<EOL><INDENT>shrinkage = self.delta<EOL><DEDENT>sigma = shrinkage * prior + (<NUM_LIT:1> - shrinkage) * sample<EOL>return self.format_and_annualise(sigma)<EOL>
Calculate the Constant-Correlation covariance matrix.

:return: shrunk sample covariance matrix
:rtype: np.ndarray