ix containing the expected returns,
%     standard deviations and weights corresponding to points on the frontier.
%

%   Copyright 1995-2009 The MathWorks, Inc. 

% Check for input errors.

if nargin < 3
	opterror('Too few inputs were entered to PORTFOPT.');
	return;
end

AER = AssetExpectedReturns;
if size(AER, 2) > 1, AER = AER'; end
if size(AER, 2) > 1, opterror('The expected returns entered are not and Nx1 vector.'); return; end
if min(AER) <= 0, opterror('An expected return of 0 or less has been entered.'); return; end
NumAssets = size(AER, 1);

ASD = AssetStandardDeviations;
if size(ASD, 2) > 1, ASD = ASD'; end
if size(ASD, 2) > 1, opterror('The standard deviations entered are not an Nx1 vector.'); return; end
if size(ASD, 1) ~= NumAssets, opterror(['The number of standard deviations does not equal ',...
	'the number of expected returns.']); return; end

RHO = AssetCorrelationMatrix;
if size(RHO, 1) ~= NumAssets | size(RHO, 2) ~= NumAssets
	opterror('The size of the correlation matrix entered is not (number of assets)x(number of assets).');
	return;
end

AGCMEntered = 0;
if nargin > 4
	if ~isempty(AssetGroupConstraintMatrix)
		AGCMEntered = 1;
	end
end

if AGCMEntered
	AGCM = AssetGroupConstraintMatrix;

	if size(AGCM, 1) - 2 < 1 | size(AGCM, 1) - 2 > NumAssets
		opterror('The linear (group) constraint matrix is incorrectly given.');
	end

	NumLinearConstraints = size(AGCM, 2);
	NumAssetsIn = size(AGCM, 1) - 2;
	B = AGCM(NumAssetsIn+1:NumAssetsIn+2, :);
	B(1, :) = -B(1, :);
	B = reshape(B', 2*NumLinearConstraints, 1);

	A = AGCM(1:NumAssetsIn, :);

	if NumAssetsIn < NumAssets
		A = [A; zeros(NumAssets-NumAssetsIn, NumLinearConstraints)]';
	else
		A = A';
	end

	A = [-A;A];
else
	AGCM = [];
	A = [];
	B = [];
end

A = [ones(1, NumAssets); A];
B = [1; B];


GenericBounds = [0 1];
AULBEntered = 0;
if nargin > 3
	if ~isempty(AssetUpperLowerBounds)
		AULBEntered = 1;
	end
end
if AULBEntered
	AULB = AssetUpperLowerBounds;
	if size(AULB, 2) ~= 2, AULB = AULB'; end
	if size(AULB, 2) ~= 2, opterror('The bounds enter