0
$\begingroup$

According to the Matlab help, Portvar will give the "Variance for portfolio of assets" by entering the returns of the Assets and the corresponding weight. However, it does not explain the parameters behind this formula.

For example, on which correlation matrix is Portvar based? What are the hidden "hypothesis" made by the function?

$\endgroup$
  • 3
    $\begingroup$ Without looking at the source, I would guess that they use the Matlab function cov on the returns to get the covariance matrix. The only thing I'm not sure of is if they use the population or sample covariance matrix. You can think of this like what would have been the variance of a portfolio rebalanced in each time period. $\endgroup$ – John Jan 20 '15 at 15:59
  • $\begingroup$ I think this may be off-topic because it belongs on stack exchange. $\endgroup$ – chollida Jan 20 '15 at 18:13
2
$\begingroup$

The code is

function v = portvar(asset,ws) 
%PORTVAR Portfolio variance. 
%   V = PORTVAR(ASSET,WS) returns the variance for a portfolio of assets
%   where ASSET is a matrix of asset data and WS are the corresponding
%   weights of each asset.  ASSET is an MxN matrix of N securities and  
%   WS is a 1xN vector where each column of ASSET is a time series of 
%   historical data for a single security and each column of WS is a 
%   corresponding weight for each security in ASSET.   If WS is a matrix  
%   of size RxN, the portfolio variance, V, is returned as an Rx1 vector 
%   with each row representing a variance calculation for each row of WS.  
% 
%   V = PORTVAR(ASSET) assigns each security an equal weight when 
%   calculating the portfolio variance. 
% 
%   See also FRONTCON, PORTROR, PORTRAND. 
% 
%   Reference: Bodie, Kane, and Marcus, Investments, Chapter 7. 

%       Copyright 1995-2006 The MathWorks, Inc.

[m,n] = size(asset); 
if nargin < 2 
  ws = ones(1,n)/n; 
end 
if nargin < 1 
  error(message('finance:portvar:missingInputs')) 
end 

[r,c] = size(ws); 
if n ~= c 
  error(message('finance:portvar:mismatchAssetsWeights')) 
end 

covmat = cov(asset);    % Calculate covariance of assets 
va = diag(covmat)';     % Get variance for each column  
ca = tril(covmat,-1);   % Get covariance values of columns 

v = zeros(r,1);         % Preallocate matrices 
for n = 1:r             % Weights are not always square matrix, using for loop 
  x = ws(n,:)'*ws(n,:);  
  v(n) = sum(ws(n,:).^2.*va)+2*sum(sum(x.*ca)); % Equation 7.11, pg. 217 
end

Hope that answers your covariance question .

$\endgroup$
  • $\begingroup$ why did you delete this? It answers the question: the covariance matrix is computed using historical returns. This is the only way given the input in any case. $\endgroup$ – SRKX Jan 21 '15 at 2:38
  • $\begingroup$ @SRKK , It was same as the comments by John . the use of cov function is already mentioned there so I thought it was redundant $\endgroup$ – ash Jan 21 '15 at 10:39
  • $\begingroup$ A comment is not an answer. Better to have both. $\endgroup$ – SRKX Jan 21 '15 at 11:16
  • $\begingroup$ @SRKX understood $\endgroup$ – ash Jan 21 '15 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.