Contents
function [Pi,omega,nCstates] = markov(omegaCenter,omegaWidth,omegaStep,rho,sigma,approximateARG,varargin)
markov.m
Creates the Markov transition matrix
and discrete support
approximating a reflected AR(1) with innovation distribution
Two levels of approximation are involved. First, the innovation distribution is approximated with a mixture of uniform distributions using approximate.m. For each of these mixing uniform distributions, a Markov transition matrix over a finite grid is created. These are averaged using the relevant mixing probabilities to create the Markov transition matrix.
Rip out parameters from approximateARG
F = approximateARG.F; Frange = approximateARG.Frange; k = approximateARG.k;
Input argument "approximateARG" is undefined. Error in ==> markov at 22 F = approximateARG.F;
Calculate mixing probabilities.
This section calls the script approximate.m.
When finished, the ranges of the mixing distributions are in the vector rangeVec, the mixing probabilities are in the vector mixProb, and the number of mixing distributions is in k.
[rangeVec,mixProb] = approximate(F,Frange,k);
Set up state space,
omega=(omegaCenter-0.5*omegaWidth):omegaStep:(omegaCenter+0.5*omegaWidth); nCstates=max(size(omega));
Calculate the Markov transition matrix
where
is the Markov transition matrix associated with the i th mixing distribution.
%Adjust the uniform distributions' ranges. rangeVec=sigma*rangeVec; %Allocate the transition matrix. Pi=zeros(nCstates,nCstates); %Cycle through the mixing probabilities. for i=1:k Pii=zeros(nCstates,nCstates); ri=rangeVec(i); for j=1:nCstates %Calculate the transition probabilities for each state. %Calculate the conditional mean and support of the underlying continuous distribution. rhoC=rho*(omega(j)-omegaCenter)+omegaCenter; lowlim=rhoC-ri; highlim=rhoC+ri; %If the implied support would leave omega, then bounce it back in. if lowlim<omega(1); lowlim=omega(1); highlim=omega(1)+2*ri; elseif highlim>omega(end); lowlim=omega(end)-2*ri; highlim=omega(end); end %Find the states with positive %probability, count them, and set the %appropriate elements of Pii. cindx=find((lowlim<=omega).*(highlim>=omega)); nMoves=max(size(cindx)); Pii(j,cindx)=1/nMoves; end %Multiply Pii by the mixing probability %and add it to Pi. Pi=Pi+mixProb(i)*Pii; end
Plot the transition densities.
if nargin > 6 figure(1) set(gcf,'Color',[1 1 1],'Units','inches','Position',[0 0 6 7]) indxvec=1:round(nCstates/11):nCstates; ylimhigh=max(max(Pi)); for i=1:12; subplot(6,2,i) set(gca,'FontSize',16) plot(omega,Pi(indxvec(i),:),'-k','LineWidth',2.5); xlim([omega(1) omega(end)]); ylim([0 ylimhigh]); if i==5; ylabel('Probability'); end set(gca,'XTick',omega(indxvec(i))); set(gca,'XTickLabel',num2str(omega(indxvec(i)),'%2.2f')) set(gca,'YTick',0.0); set(gca,'YTickLabel',' '); if i==11 || i==12 xlabel('ln(C_t)'); end box off; end end
Calculate and plot ergodic distribution.
The ergodic distribuition solves
if nargin > 6 [p,d,flag]=eigs(Pi',1); if abs(d-1)>10e-10 || flag~=0 error('Calculation of ergodic distribution failed.') end %Normalize the eigen vector to have unit %length. p=p/sum(p); figure(2) plot(omega,p','-k','LineWidth',2.5) set(gca,'FontSize',16) box off set(gcf,'Color',[1 1 1]); xlim([omega(1) omega(end)]); ylim([0 1.01*max(p)]); ylabel('Probability') xlabel('ln(C_t)') end
End of File
end