www.gusucode.com > risk 工具箱matlab源码程序 > risk/+risk/+internal/convertToModelWeights.m
function [W, idioW] = convertToModelWeights(OriginalWeights, FactorCorr) % Convert percentile weights to model weights. % Copyright 2016 The MathWorks, Inc. numLatent = size(OriginalWeights,1); % alpha represents the amount of latent variable variability that is % explained by the factors. alpha = 1 - OriginalWeights(:,end); % We scale the factor weights to sum to 1 (without the idiosyncratic % contribution). weights = OriginalWeights(:,1:end-1); weights = bsxfun(@rdivide,weights,sum(weights,2)); % Compute the variance of the weighted sum of factors for each asset. factorVariance = zeros(numLatent,1); for ii = 1:numLatent factorVariance(ii) = weights(ii,:) * FactorCorr * weights(ii,:)'; end % Compute the "raw" model weights W = bsxfun(@times,alpha,weights); W = bsxfun(@rdivide,W,sqrt(factorVariance)); % Weights of the idiosyncratic shocks idioW = sqrt(1 - alpha.^2);