def _calculate_weights_standalone_portfolio(self): """ For a standalone portfolio, calculates volatility weights Uses the candidate matching method :return: list of weights """ assert len(self.instruments) <= MAX_CLUSTER_SIZE assert self.sub_portfolios is NO_SUB_PORTFOLIOS raw_weights = get_weights_using_candidate_method( self.corr_matrix.values) self.raw_weights = raw_weights use_SR_estimates = self.use_SR_estimates if use_SR_estimates: SR_list = self.sharpe_ratio years_of_data = self.years_of_data avg_correlation = get_avg_corr(self.corr_matrix.values) adjusted_weights = adjust_weights_for_SR(raw_weights, SR_list, years_of_data, avg_correlation) else: adjusted_weights = raw_weights return adjusted_weights
def shrink_corr(corrmatrix, shrinkage_corr): """ >>> sigma=np.array([[1.0,0.0,0.5], [0.0, 1.0, 0.75],[0.5, 0.75, 1.0]]) >>> shrink_corr(sigma, 0.5) array([[ 1. , 0.20833333, 0.45833333], [ 0.20833333, 1. , 0.58333333], [ 0.45833333, 0.58333333, 1. ]]) >>> shrink_corr(sigma, 0.0) array([[ 1. , 0. , 0.5 ], [ 0. , 1. , 0.75], [ 0.5 , 0.75, 1. ]]) >>> shrink_corr(sigma, 1.0) array([[ 1. , 0.41666667, 0.41666667], [ 0.41666667, 1. , 0.41666667], [ 0.41666667, 0.41666667, 1. ]]) """ avg_corr=get_avg_corr(corrmatrix) prior_corr=boring_corr_matrix(corrmatrix.shape[0], offdiag=avg_corr) sigma_corr=shrinkage_corr*prior_corr+(1-shrinkage_corr)*corrmatrix return sigma_corr