0% found this document useful (0 votes)
25 views

% T Test of Portfolio Returns: 'Sdata - Mat' 'Bdata - Mat'

This document contains MATLAB code for performing statistical analyses including t-tests and regressions on portfolio return and factor data. Specifically, it runs t-tests on portfolio returns, the returns of a betting against the market (BMS) strategy, and a high minus low (HML) factor. It then fits a five-factor model to excess returns data using time series and cross-sectional regressions. It calculates standard errors, t-statistics and variance-covariance matrices for the factor risk premia estimates.

Uploaded by

Eva Qin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

% T Test of Portfolio Returns: 'Sdata - Mat' 'Bdata - Mat'

This document contains MATLAB code for performing statistical analyses including t-tests and regressions on portfolio return and factor data. Specifically, it runs t-tests on portfolio returns, the returns of a betting against the market (BMS) strategy, and a high minus low (HML) factor. It then fits a five-factor model to excess returns data using time series and cross-sectional regressions. It calculates standard errors, t-statistics and variance-covariance matrices for the factor risk premia estimates.

Uploaded by

Eva Qin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Coding:

% t test of portfolio returns


t = (reshape(m,10,10)-0)./(reshape(s,10,10)./sqrt(629));
h = ttest(data1);
hReshape = reshape(h,10,10);
% t test of BMS
% Import data
sData = [];
bData = [];
% Copy and paste requested range of data into the corresponding matrixes
load('sData.mat');
load('bData.mat');
bmsData = bData-sData;
bmsMean = mean(bmsData);
bmsS = std(bmsData);
bmsT = (bmsMean-0)./(bmsS./sqrt(629));
bmsH = ttest(bmsData);
% t test of HML
% Import data
hData = [];
lData = [];
hData = data1(:,[10,20,30,40,50,60,70,80,90,100]);
lData = data1(:,[1,11,21,31,41,51,61,71,81,91]);
hmlData = hData-lData;
hmlMean = mean(hmlData);
hmlS = std(hmlData);
hmlT = (hmlMean-0)./(hmlS./sqrt(629));
hmlH = ttest(hmlData);
hmlTRe = hmlT';
hmlHRe = hmlH';



1.
Coding:
data2 = []
data3 = []
data4 = []
% Copy and paste requested range of data into the corresponding matrixes
% (1) The FF-Five Factor Model
load('data1.mat');
load('data2.mat');
dates = data2(:,1);
factors = data2(:,2:6);
riskfree = data2(:,7);

[T,K] = size(factors);
[T,W] = size(data1);

excessReturns = bsxfun(@minus,data1,riskfree);

% Time series regressions
X = [ones(T,1) factors];
fprintf('X = %.2f\n',X);
alphaBeta = X\excessReturns;
alpha = alphaBeta(1,:)';
beta = alphaBeta(2:6, :)';
avgExcessReturns = mean(excessReturns)';
% Cross-section regression
lam = beta\avgExcessReturns;

% Moment conditions
p = alphaBeta;
epsilon = excessReturns-X*p;
moments1 = kron(epsilon,ones(1,K+1));

moments1 = moments1 .* kron(ones(1,W),X);


u = bsxfun(@minus, excessReturns, lam'*beta');
moments2 = u*beta;

S = cov([moments1 moments2]);
G = zeros(W*K+W+K, W*K+W+K);
SigmaX = X'*X/T;
G(1:W*K+W, 1:W*K+W) = kron(eye(W),SigmaX);
G(W*K+W+1:end, W*K+W+1:end) = -beta'*beta;
for i = 1:W
temp = zeros(K, K+1);
values = mean(u(:,i))-beta(i,:).*lam';
temp(:,2:end) = diag(values);
G(W*K+W+1:end,(i-1)*(K+1)+1:i*(K+1)) = temp;
end
vcv = inv(G') * S * inv(G)/T;
riskPremia = lam;
vcvLam = vcv(W*K+W+1:end,W*K+W+1:end);
SE = sqrt(diag(vcvLam));
tRP = (riskPremia-0)./SE;
fprintf(' Mkt-RF SMB HML
RMW CMA\n')
fprintf('-------------------------------------------------------------------------------------------------\n')
fprintf('Risk
Premia %0.2f %0.2f %0.2f %0.2f
%0.2f\n', riskPremia)
fprintf('SE %0.2f %0.2f %0.2f
%0.2f %0.2f\n', SE)
fprintf('t
statistics %0.2f %0.2f %0.2f %0.2f
%0.2f\n', tRP)
fprintf('\n\n')

i = 1;
betaVar = zeros(49,6);
for j = 1:10
for k = 1:10
a = alpha(i);
b = beta(i,:);
offset = (K+1)*(i-1)+1:(K+1)*(i);
variances = diag(vcv(offset,offset))';
betaVar(i,:) = variances;
stdv = sqrt(variances);
c = [a b];
tstats = c./stdv;
fprintf('Size: %d, B/M: %d Alpha Beta(VWM) Beta(SMB)

You might also like