The GARCH functionality in the econometric toolbox in Matlab cannot do univariate GARCH.
Kevin Sheppard's MFE toolbox is much better, while not as user friendly, it is much better written and is certainly more comprehensive. It can be downloaded here and the documentation here is quite detailed.
p = csvread('stocks.csv',1,0); p = p(:,[1,2]); % consider first two stocks y = diff(log(p))*100; % convert prices to returns y(:,1)=y(:,1)-mean(y(:,1)); % subtract mean y(:,2)=y(:,2)-mean(y(:,2)); T = length(y);
import numpy as np p = np.loadtxt('stocks.csv',delimiter=',',skiprows=1) p = p[:,[0,1]] # consider first two stocks y = np.diff(np.log(p), n=1, axis=0)*100 # calculate returns y[:,0] = y[:,0]-np.mean(y[:,0]) # subtract mean y[:,1] = y[:,1]-np.mean(y[:,1]) T = len(y[:,0])
%% create a matrix to hold covariance matrix for each t EWMA = nan(T,3); lambda = 0.94; S = cov(y); % initial (t=1) covar matrix EWMA(1,:) = S([1,4,2]); % extract var and covar for i = 2:T % loop though the sample S = lambda*S+(1-lambda)* y(i-1,:)'*y(i-1,:); EWMA(i,:) = S([1,4,2]); % convert matrix to vector end EWMArho = EWMA(:,3)./sqrt(EWMA(:,1).*EWMA(:,2)); % calculate correlations
EWMA = np.full([T,3], np.nan) lmbda = 0.94 S = np.cov(y, rowvar = False) EWMA[0,] = S.flatten()[[0,3,1]] for i in range(1,T): S = lmbda * S + (1-lmbda) * np.transpose(np.asmatrix(y[i-1]))* np.asmatrix(y[i-1]) EWMA[i,] = [S[0,0], S[1,1], S[0,1]] EWMArho = np.divide(EWMA[:,2], np.sqrt(np.multiply(EWMA[:,0],EWMA[:,1]))) print(EWMArho)
[par, Ht] = o_mvgarch(y,2, 1,1,1); Ht = reshape(Ht,4,T)'; %% Ht comes from o_mvgarch as a 3D matrix, this transforms it into a 2D matrix OOrho = Ht(:,3) ./ sqrt(Ht(:,1) .* Ht(:,4)); %% OOrho is a vector of correlations
## Python does not have a proper OGARCH package at present
[p, lik, Ht] = dcc(y,1,1,1,1); Ht = reshape(Ht,4,T)'; DCCrho = Ht(:,3) ./ sqrt(Ht(:,1) .* Ht(:,4)); %% DCCrho is a vector of correlations
## Python does not have a proper DCC package at present
## Python does not have a proper OGARCH/DCC package at present