Good morning, I am a student and I have to analyse a dataset based on LOBSTER data, Microsoft level 5, 21st June 2012. I hope that someone in the community can help me because I don't know how to go on.
https://lobsterdata.com/info/DataSamples.php
I need to estimate a vecm model, but the function that I am using does not work at all.
https://it.mathworks.com/help/econ/modeling-the-united-states-economy.html
Any suggestions to improve my code? Please find attached the code I am developing.
In addition, I report a fact which might be linked to the problem, which might help to solve the problem.
Last saturday evening I tried again to run the code and after trying to manipulate the input data in order to transform data_vector in a sort of time-varying vector, I got some similar results in H1 and H2 Johansen test (rejection up to 7 for H2 and rejection up to 8 for H1), and the Likelihood ratio test worked. However, the vecm continued to return errors and I modified something, but now H1 rejects only up to 2 as before saturday evening and the LR test does not work at all.
The problem lies in this part of the code. Do not consider the section related to ADF and KPSS test. Please find below the faulty code.
data_vector = [log_book_1_ask log_book_1_bid lev_1_ask lev_2_ask lev_3_ask lev_1_bid lev_2_bid lev_3_bid BUY_t SELL_t];
P = 15 % number of lags
[h,pValue,stat,cValue,mleH2] = jcitest(data_vector, 'lags', P-1, 'Model', 'H2');
[h,pValue,stat,cValue,mleH1] = jcitest(data_vector, 'lags', P-1, 'Model', 'H1');
%the likelihood ratio test
r = 7; % Cointegrating rank
uLogL = mleH2.r7.rLL; % Loglikelihood of the unrestricted H2 model for r = 7
rLogL = mleH1.r7.rLL; % Loglikelihood of the restricted H1 model for r = 7
[h,pValue,stat,cValue] = lratiotest(uLogL, rLogL, r);
%higher value for uLogL
% %create the VEC model object
time_message = mess(:,1)
my_time = time_message(1:end)
%
[Mdl,se] = estimate(vecm(size(data_vector,2),r,P-1), data_vector, 'Model', 'H2');
toFit = vecm(Mdl.NumSeries, Mdl.Rank, Mdl.P - 1);
toFit.Constant(abs(Mdl.Constant ./ se.Constant) < 2) = 0;
toFit.ShortRun{1}(abs(Mdl.ShortRun{1} ./ se.ShortRun{1}) < 2) = 0;
toFit.Adjustment(abs(Mdl.Adjustment ./ se.Adjustment) < 2) = 0;
Fit = estimate(toFit, data_vector, 'Model', 'H2');
B = [Fit.Cointegration ; Fit.CointegrationConstant' ; Fit.CointegrationTrend'];
figure
plot(my_time, [data_vector ones(size(data_vector,1),1) (-(Fit.P - 1):(size(data_vector,1) - Fit.P))'] * B)
title('Cointegrating Relations')