function y = FitGEVRight(beta, a0, a1, Ka0, Ka1, fKa1, fKa0)
% Fit GEV distribution to right tail of RN density
%
% Minimizes squared error between GEV CDF/PDF and target values at two
% strike points, used by rn_probs_altsmooth2.m for tail extrapolation

Mean  = beta(1);
sigma = beta(2);
phi   = beta(3);

y = ((gevcdf(Ka0,phi,sigma,Mean) - a0))^2 + ...
	((gevpdf(Ka0,phi,sigma,Mean) - fKa0))^2 + ...
	((gevpdf(Ka1,phi,sigma,Mean) - fKa1))^2 ;

if sigma<0 | isreal(y)==0
	y = 1e100;
end



