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>sample = (<NUM_LIT:1.0> / t) * np.dot(x.T, x)<EOL>var = np.diag(sample).reshape(-<NUM_LIT:1>, <NUM_LIT:1>)<EOL>sqrtvar = np.sqrt(var)<EOL>_var = np.tile(var, (n,))<EOL>_sqrtvar = np.tile(sqrtvar, (n,))<EOL>r_bar = (np.sum(sample / (_sqrtvar * _sqrtvar.T)) - n) / (n * (n - <NUM_LIT:1>))<EOL>prior = r_bar * (_sqrtvar * _sqrtvar.T)<EOL>prior[np.eye(n) == <NUM_LIT:1>] = var.reshape(-<NUM_LIT:1>)<EOL>if self.delta is None:<EOL><INDENT>y = x ** <NUM_LIT><EOL>phi_mat = np.dot(y.T, y) / t - <NUM_LIT:2> * np.dot(x.T, x) * sample / t + sample ** <NUM_LIT:2><EOL>phi = np.sum(phi_mat)<EOL>term1 = np.dot((x ** <NUM_LIT:3>).T, x) / t<EOL>help_ = np.dot(x.T, x) / t<EOL>help_diag = np.diag(help_)<EOL>term2 = np.tile(help_diag, (n, <NUM_LIT:1>)).T * sample<EOL>term3 = help_ * _var<EOL>term4 = _var * sample<EOL>theta_mat = term1 - term2 - term3 + term4<EOL>theta_mat[np.eye(n) == <NUM_LIT:1>] = np.zeros(n)<EOL>rho = sum(np.diag(phi_mat)) + r_bar * np.sum(<EOL>np.dot((<NUM_LIT:1.0> / sqrtvar), sqrtvar.T) * theta_mat<EOL>)<EOL>gamma = np.linalg.norm(sample - prior, "<STR_LIT>") ** <NUM_LIT:2><EOL>kappa = (phi - rho) / gamma<EOL>shrinkage = max(<NUM_LIT:0.0>, min(<NUM_LIT:1.0>, kappa / 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