function f = APDcdf(alpha,lda,x); % APDCDF.M Asymmetric Power Distribution (APD) cumulative distribution function % F = APDCDF(ALPHA,LDA,X) computes the cdf of a standard APD random variable % with parameters ALPHA, 0 < ALPHA < 1, and LDA, LDA > 0, and evaluated at % some real value X. % % Inputs: % ALPHA = Nx1-vector of shape parameter alpha, 0 < ALPHA(n) < 1, for 1 <= n <= N; % LDA = Nx1-vector of shape parameter lda, LDA(n) > 0 for 1 <= n <= N; % X = Nx1-vector of real values. % % Outputs: % F = Nx1-vector of APD(ALPHA(n),LDA(n)), 1 <= n <= N, cdf evaluated at X; % % Comments: % a standard APD(alpha,lda) random variable X has probability density: % p(alpha,lda,x) = [A^(1/lda)/gamma(1+1/lda)]*... % *exp[-(A/alpha^lda)*abs(x)^lda], if x <= 0, % *exp[-(A/(1-alpha)^lda)*abs(x)^lda], if x > 0, % where A = (2*alpha^lda*(1-alpha)^lda)/(alpha^lda+(1-alpha)^lda). % % References: % [1] Komunjer, I. (2006): "Asymmetric Power Distribution: Theory and % Applications to Risk Measurement" % % Author: Ivana Komunjer - UCSD (komunjer@ucsd.edu) % Version: 2.1 Date: 06/07/2006 if nargin < 3, error('Requires three input arguments'); end [errorcode alpha lda x] = distchck(3,alpha,lda,x); if errorcode > 0 error('Requires non-scalar arguments to match in size.'); end % Computes A a = 2*(alpha.^lda).*((1-alpha).^lda)./(alpha.^lda+(1-alpha).^lda); % Initialize f to zero. f = zeros(size(a)); % Return NaN if the arguments ALPHA and LDA are outside their limits. f(alpha<=0 | alpha>=1 | lda<=0,:) = NaN; k = find(alpha>0 & alpha<1 & lda>0); ak = a(k); ldak = lda(k); alphak = alpha(k); xk = x(k); onek = ones(size(ak)); if any(k) fk = (xk<=0).*alphak.*(1-gammainc((ak.*(abs(xk)).^ldak)./(alphak.^ldak),1./ldak)) +... (xk>0).*(1-(1-alphak).*(1-gammainc((ak.*(abs(xk)).^ldak)./((1-alphak).^ldak),1./ldak))); end f(k) = fk; % Make sure that round-off errors never make f less than 0 or greater than 1. f(f < 0) = 0; f(f > 1) = 1;