Gabriel Perez-Quiros, Allan Timmermann(2000)
Gabriel Perez-Quiros, Allan Timmermann(2000)
Hi, Tom, Is there a RATS code to replicate the Perez-Quiros and Timmermann(2000),Firm Size and Cyclical Variations in Stock Returns? Many thanks. There are example codes for Matlab but I would prefer to run it in RATS. Thanks a lot.
Re: Gabriel Perez-Quiros, Allan Timmermann(2000)
Could you include the link to the Matlab codes (and I assume data).
Re: Gabriel Perez-Quiros, Allan Timmermann(2000)
Hi, Tom, I just wonder do you have the codes for replicating Perez-Quiros and Timmermann(2000),Firm Size and Cyclical Variations in Stock Returns? JF.
I completely stuck on creating Bi-variate Markov Model and Testing for the symmetry.
I completely stuck on creating Bi-variate Markov Model and Testing for the symmetry.
Re: Gabriel Perez-Quiros, Allan Timmermann(2000)
The previous poster said that there were Matlab codes, but I wasn't able to find them.
The likelihood for the bivariate model for regime St would be computed with exp(%logdensity(sigma(St),||u1(St),u2(St))). The asymmetry tests are done by pegging the slope coefficients to be equal to generate the LR test for changes in the variance and to set the variance coefficients to be equal to generate the LR test for changes in the regression.
The likelihood for the bivariate model for regime St would be computed with exp(%logdensity(sigma(St),||u1(St),u2(St))). The asymmetry tests are done by pegging the slope coefficients to be equal to generate the LR test for changes in the variance and to set the variance coefficients to be equal to generate the LR test for changes in the regression.
Re: Gabriel Perez-Quiros, Allan Timmermann(2000)
Hi, Tom, thank you for the fast reply.
I find the following matlab code
In addition, although I do not have the exact portfolios used in the paper, but I think Fama French Size Portfolios could be used as substitute. I have attached this as well.
Please let me know if there is any way to replicate this paper in RATS since this is my favorite software for research. Thank you.
Eric
I find the following matlab code
Code: Select all
% Function for forecasting in t+1 an Markov Switching regression model
% estimated with MS_Regress_Fit.m
%
% Input: Spec_Output - Specification output from estimation (check MS_Regress_Fit.m)
% newIndepData - New information that has arrived for t+1 and beyond (maybe lagged variables ?)
% newpxData - New information that has arrived for t+1 and beyond for macro state variables
%
% Output: meanFor - Forecast for the mean equation (column iterating over equations of system)
% stdFor - Forecast for the standard deviation (columns iterating over
% equations of system)
%
% Author: Marcelo Perlin
% Email: marceloperlin@gmail.com
%
% Author: Marcelo Perlin (UFRGS/BR) for the constant transition probability version.
% Contact: marceloperlin@gmail.com
%
% Author: Zhuanxin Ding for the time varying transition probability version.
%
% Modified by Zhuanxin Ding based on the original code by Marcelo Perlin to incorporate the
% time-varying transition probability matrix that depends on state variables, May 21,2012.
% (see paper by Gabriel Perez-Quiros and Allan Timmermann, Journal of Finance, June 2000)
%
function [meanFor,stdFor]=MS_Regress_For_tvtp(Spec_Out,newIndepData,newpxData)
% Retrieving variables from Spec_Output
nEq=size(Spec_Out.condMean,2);
k=Spec_Out.k;
S=Spec_Out.S;
Coeff=Spec_Out.Coeff;
if ~iscell(newIndepData)
temp=newIndepData;
clear newIndepData;
for iEq=1:nEq
newIndepData{iEq}=temp;
end
end
if ~iscell(newpxData)
temp=newpxData;
clear newpxData;
for i=1:k-1
for j=1:k
newpxData{i,j}=temp;
end
end
end
% forecast horizon;
h=size(newIndepData{1},1);
for ik=1:k
Std{ik}=sqrt(diag(Coeff.covMat{ik}));
end
distrib=Spec_Out.advOpt.distrib;
for iEq=1:nEq
switch distrib
case 'Normal'
S_Std{iEq}=S{iEq}(end);
n_dist_param=1; % Number of d
case 't'
S_Std{iEq}=S{iEq}(end-1);
n_dist_param=2; % Number of distributional parameters
case 'GED'
S_Std{iEq}=S{iEq}(end-1);
n_dist_param=2; % Number of distributional parameters
end
end
indep_S=cell(nEq,1);
indep_nS=cell(nEq,1);
for iEq=1:nEq
count_S=0;
count_nS=0;
for i=1:length(S{iEq})-n_dist_param
if S{iEq}(i)==1
count_S=count_S+1;
indep_S{iEq}(:,count_S)=newIndepData{iEq}(:,i);
else
count_nS=count_nS+1;
indep_nS{iEq}(:,count_nS)=newIndepData{iEq}(:,i);
end
end
if count_nS==0
indep_nS{iEq}=zeros(h,1);
end
end
% Building Forecasts
% future time varying transition probability matrix;
pa=Spec_Out.Coeff.pa;
p=ones(k,k,h);
tvtp=ones(k,k,h);
for t=1:h
for i=1:k-1
for j=1:k
tvtp(i,j,t)=normcdf(newpxData{i,j}(t,:)*pa{i,j});
p(i+1,j,t)=p(i,j,t)*(1-tvtp(i,j,t));
end
end
p(:,:,t)=p(:,:,t).*tvtp(:,:,t);
end
% state probability;
firstProb=Spec_Out.filtProb;
for t=1:h
if t==1
E(t,:)=p(:,:,t)*firstProb(end,:)'; % Eq (9) of Hamilton's paper
else
E(t,:)=p(:,:,t)*E(t-1,:)'; % Eq (9) of Hamilton's paper or (22.4.6) of Hamilton's book
end
end
for t=1:h
for iEq=1:nEq
for j=1:k
meanFor_S{iEq}(t,j)=indep_nS{iEq}(t,:)*Coeff.nS_Param{iEq}+indep_S{iEq}(t,:)*Coeff.S_Param{iEq}(:,j); % mean forecast for each state
stdFor_S{iEq}(t,j)=Std{j}(iEq); % sigma forecast for each state
end
meanFor{iEq}(1,t)=meanFor_S{iEq}(t,:)*E(t,:)'; % mean t+1 forecast
stdFor{iEq}(1,t)=stdFor_S{iEq}(t,:)*E(t,:)'; % std t+1 forecast
end
endIn addition, although I do not have the exact portfolios used in the paper, but I think Fama French Size Portfolios could be used as substitute. I have attached this as well.
Please let me know if there is any way to replicate this paper in RATS since this is my favorite software for research. Thank you.
Eric
- Attachments
-
- Size Portfolios.xlsx
- (153.52 KiB) Downloaded 706 times
Re: Gabriel Perez-Quiros, Allan Timmermann(2000)
That's actually for forecasting, not for fitting, though the site has the code for fitting the model instead. However, all that really does is reference the Perez-Quiros-Timmerman paper for the time-varying transition probabilities. The 2000 paper does two "non-standard" things: TVTP and the switching semi-structural variance process.
Re: Gabriel Perez-Quiros, Allan Timmermann(2000)
I know it is similar to Gray (1996), however, I am still having problem of setting up the bi variate estimation. Is there a sample code to set up bi variate MS switching ? Thank you.
Re: Gabriel Perez-Quiros, Allan Timmermann(2000)
That's what the MSSysRegression routines are for.