Code covered by the BSD License  

Highlights from
MIDAS Matlab Toolbox

5.0
5.0 | 7 ratings Rate this file 77 Downloads (last 30 days) File Size: 1.03 MB File ID: #45150 Version: 2.0
image thumbnail

MIDAS Matlab Toolbox

by

Hang Qian (view profile)

 

21 Jan 2014 (Updated )

Repack of Mi(xed) Da(ta) S(ampling) regressions (MIDAS) written by Eric Ghysels and collaborators

| Watch this File

File Information
Description

The mixed frequency regression studies the explanatory power of high frequency variables on the low frequency outcome. The weights associated with high frequency regressors are usually assumed some functional form. This toolbox is a repack of the Mi(xed) Da(ta) S(ampling) regressions (MIDAS) programs written by Eric Ghysels. It supports ADL-MIDAS type regressions. The package also includes two functions for GARCH-MIDAS and DCC-MIDAS estimation. See the enclosed user guide for details.
Syntax:
[...] = MIDAS_ADL(DataY,DataYdate,DataX,DataXdate)
[...] = MIDAS_ADL(DataY,DataYdate,DataX,DataXdate,name,value,...)
[...] = GarchMidas(y, name,value,...)
[...] = DccMidas(Data, name,value,...)

Required Products Optimization Toolbox
MATLAB
MATLAB release MATLAB 8.6 (R2015b)
MATLAB Search Path
/
/MIDASv2.0
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (39)
02 Feb 2016 wang

wang (view profile)

Hi Hang Qian,
Thanks for your rely!
Best regards,
wang

Comment only
01 Feb 2016 Hang Qian

Hang Qian (view profile)

Hi Wang,

For volatility forecasting with a macroeconomic variable X, we need the value of X in the forecasting periods. Therefore, the length of y and X must be the same when we run the program GarchMidas. Otherwise, there will be an error message.

In your scripts, I saw 'X' is assigned a value xDay, which does not increases its size within the FOR loop. So you might want to expand the size of the variable xDay in order to match the size of yBig. For example, the codes would look like

xDayBig = [xDay;xNew];

where xNew is the value of the macroeconomic variable in a one-step forecasting period.

Thank you.

Comment only
31 Jan 2016 wang

wang (view profile)

Hi Hang Qian,
In out of sample forecast using direct marcoeconomic variable X, I encounter with an error message:
Error using GarchMidas (line 189)
Macroeconomic regressor must be a vector of the same length as y.
could you give me some advice
this code is shown as follows:
yBig = [y;0];
for t = 1:nForecast
[~,~,Variance,LongRunVar] = GarchMidas(yBig,'Period',period,'NumLags',numLags,'X',xDay,'LogTau',1,'ThetaM',1,'Beta2Para',1,'RollWindow',1,'Params',estParams);
yPseudo = estParams(1) + sqrt(Variance(end));
yBig = [yBig(1:end-1);yPseudo;0];
end

Comment only
03 Jan 2016 wang

wang (view profile)

Hi Hang qian,
Thank you very much for your rely.

Comment only
02 Jan 2016 Hang Qian

Hang Qian (view profile)

Hi Wang,

Thanks for your interests in the toolbox. In reply to your question about the out-of-sample forecast, the variable “yPseudo” is not an observation, but a mathematic construction such that its squared value can recover the conditional variance. Recall that the GARCH-MIDAS variances recursion is given by g(i,t) = (1-a-b) + a * (y(i-1,t)-mu)^2/tau + b*g(i-1,t). In an out-of-sample forecast, the squared yPseudo works as if it were the squared y(i-1,t) because the expected value of (yPseudo – mu)^2 equals the conditional variance. If you would like to add the residual “Resid”, you might want to find a variable whose squared value has the unit variance. Thank you.

Comment only
01 Jan 2016 wang

wang (view profile)

Hi Hang Qian,
thanks for your wondeful toobox. In Out-of-sample forecast, yPseudo = estParams(1) + sqrt(Variance(end)); why not is yPseudo = estParams(1) + sqrt(Variance(end))*Resid.

11 Nov 2015 Di Mo

Di Mo (view profile)

 
10 Nov 2015 Hang Qian

Hang Qian (view profile)

The “nobs” you saw is a scalar variable that keeps track of the number of observations. I am not aware in the codes that the variable is used before it is defined. You might check the line number that generates the error message?

Comment only
10 Nov 2015 Di Mo

Di Mo (view profile)

Hi Hang Qian,

Thank you for the quick reply. I have received another wrong message when running the GARCH-Midas Command. The error is as follows:

Undefined function or variable 'nobs'.

Do you have any suggestions on this?

Kind Regards
Di

Comment only
09 Nov 2015 Hang Qian

Hang Qian (view profile)

Hi Di,

The error message you saw is most likely a problem of older version of MATLAB. A few years ago, the Optimization Toolbox of MATLAB migrated optimset to optimoptions. If your MATLAB version is older than 2014a, the software will not recognize optimoptions. You may change optimoptions(...) by something like options = optimset(...).

Comment only
09 Nov 2015 Di Mo

Di Mo (view profile)

Hi Hang Qian,

Thank you very much for this wonderful Midas Toolbox. I just started with GarchMidas model and an error appeared as follows:

??? Undefined function or method 'optimoptions' for input arguments of type 'char'.

Error in ==> GarchMidas at 294
options = optimoptions('fmincon','Algorithm','interior-point','Display','notify-detailed');

Could you give me some advice on this please?

Thank you very much!

Best,
Di

Comment only
30 Oct 2015 Hang Qian

Hang Qian (view profile)

Hi Muhammad,

If your MATLAB version is earlier than R2014b, you may see an error message from the input parser. You will have to replace the name “addParameter” by “addParamValue”. They are the same thing, but the former is its new name. Thank you.

Comment only
29 Oct 2015 Muhammad Yudhistira

Hi Qian,

Thanks a lot for this great toolbox. I just start with MIDAS model, and trying one of the example in the toolbox: appADLMIDAS2. I encounter with this problem.

Error in ==> MIDAS_ADL at 201
parseObj.addParameter('Xlag',9,@(x)validateattributes(x,{'numeric','char'},{},callerName));

Could you give any suggestion?

Best

Comment only
13 Sep 2015 Hang Qian

Hang Qian (view profile)

Hi Yijie,

When you adjust the parameter ”Horizon”, it will shift the dates of the high frequency regressors backward or forward. Setting the Horizon = -2 indicates shift the dates two periods ahead. Depending on how many high frequency periods equal to a low frequency period, this may give you a nowcasting effect. When you run the program, the screen will show how the dates of low and high frequency regressions match each other in a regression. This time frame will be the same for both estimation and forecast.

Also, if you want to verify how the dates match, you may look at the output struct MixFreqData, in which the variables OutYdate and OutXdate are the dates of the low and high variables in the forecasting periods, respectively.

Comment only
13 Sep 2015 Hang Qian

Hang Qian (view profile)

Hi Jennifer,

The error message you saw is a date format issue. The program relies on the MATLAB function datevec to translate string dates to vector dates. It supports 14 date formats, but “01.04.1947” is not one of them. Refer to the documentation of the MATLAB function datevec.

You will have to replace 01.04.1947 by 04/01/1947 (or perhaps 01/04/1947?) Both R2015b and earlier versions of MATLAB use the same date convention. Therefore, the easiest solution is to change the date format in your dataset.

Comment only
09 Sep 2015 jennifer

Thanks for sharing useful toolbox.

The program didnt work on MATLAB R2015b. It gives following errors. Could you give some advice ?

Best

error using datevec (line 276)
Cannot parse date 01.04.1947.

Error in MixFreqData (line 99)
DataYdateVec = datevec(DataYdate);

Error in MIDAS_ADL (line 255)
MixedFreqData = MixFreqData(DataY,DataYdate,DataX,DataXdate,xlag,ylag,horizon,estStart,estEnd,dispTime);

Error in appADLMIDAS5 (line 49)
[OutputForecast1,OutputEstimate1,MixedFreqData,ExtendedForecast] = MIDAS_ADL(DataY,DataYdate,DataX,DataXdate,...

Comment only
05 Sep 2015 Yijie Huang

Hi Qian,

Thanks a million for this toolbox.

In your application 3, if setting the Horizon = -2,is it nowcasting GDP with monthly data? E.g. the forecast result is in 10/01/2009 is based one the 10/01/2009 - 12/01/2009 monthly data?

Thanks very much.

11 Aug 2015 Hang Qian

Hang Qian (view profile)

Hi David,

I guess the error message is most likely a MATLAB version issue. Double check that the Optimization Toolbox is installed and your MATLAB version is R2013b or newer.

If you have the Optimization Toolbox, the name-value pairs of the optimization options vary from version to version. If your software cannot recognize parameter names like 'LargeScale and 'Jacobian', simply remove it from the codes and use the default optimization setting.

If you do not have the Optimization Toolbox, the only way you can use this software is to change the solver. Replace the toolbox functions lsqnonlin or fmincon by fminsearch, which is available for the base MATLAB. Also remove the bounds constraints, as fminsearch does not support constrained optimization.

Thank you.

Comment only
10 Aug 2015 David Stephan

Thank you for a great toolbox. I am just getting started with MIDAS models and have been trying to follow the example in the user guide. Although everything works fine for models 4-6 I get a similar error for models 1-3.

For Models 1 and 2:
Error using optimset (line 219)
Unrecognized parameter name 'LargeScale'.

For Model 3 a similar error:
Error using optimset (line 219)
Unrecognized parameter name 'Jacobian'.

Any ideas what I am doing wrong?

Thanks again for a great toolbox

10 Aug 2015 Saeed

Saeed (view profile)

Thanks much Eric.

And yes I am using ExoReg to have couple of variables on the right hand side that have the same frequency as the dependent variable.

And yes you are totally correct, I can improve upon simple averaging by using more sophisticated forecast combination approaches.

Thanks,
Saeed

Comment only
10 Aug 2015 Eric

Eric (view profile)

Dear Saeed:

Thanks for your kind words about the MIDAS Matlab Toolbox.

You are correct that multiplicative MIDAS is not yet implemented. Empirical evidence seems to indicate that regular MIDAS specifications typically do better though.

Regarding your question of adding leads of another variable which you call var2. In principle you can use the ExoReg specification to do this, if you properly align the var2 series. So, you can do the direct estimation, assuming that the var2 is not a variable you estimate via a MIDAS polynomial.

Otherwise, if the var2 series is also high frequency it is much easier to run two MIDAS regressions with leads, one for var1 and one for var2, and do forecast combination. You mention that you simply take the average. That is typically not a good idea. Better forecast combination methods exist and are available in the Toolbox

EG

Comment only
09 Aug 2015 Saeed

Saeed (view profile)

Dear Eric and Hang:
First of all, I have found the toolbox extremely useful and the accompanying user guide quite detailed and very well written, and so many thanks for making this availabe to all.

Secondly, I am assuming that multiplicative MIDAS is still not implemented (page 16 of the userguide mentions it as well). I ask, because many papers published do seem to apply multiplicative MIDAS such as Andreou, Ghysels, and Kourtellos (2013): Should macroeconomic forecasters look at daily financial data? (JBES).

So currently, I am using daily series named var1 with leads to forecast a monthly series Y. But on the right hand side I also want to have leads of another variable, var2. Since I cannot use multiplicative MIDAS, so I run one MIDAS regression using only leads of var1, and then I run another MIDAS regression using only leads of var2. I average the two forecasts of Y. But it will be nice to just run "one" MIDAS regression that allows for leads of both variables var1, and var2.

Any help in that regard will be very much appreciated. Thanks in advance.

Comment only
30 Jul 2015 Eric

Eric (view profile)

Dear Philippe:

This is essentially a question about mixed frequency VAR models. There is a literature on this. See for example the paper entitled "Macroeconomics and the reality of mixed frequency data", forthcoming in the Journal of Econometrics which I wrote. Estimation can be done with standard VAR packages.

Regards,

EG

Comment only
29 Jul 2015 Philippe

Hello,
Is it possible with this code to run multivariate MIDAS regressions? If not, how could it be implemented?

Regards,
Philippe

Comment only
08 May 2015 Eric

Eric (view profile)

Dear Du-hyun:

The MIDAS Toolbox only covers MIDAS regression analysis. To my knowledge there is no user friendly MIDAS volatility model code publicly available. Still to be done, unfortunately. However, it is not so difficult to start from Matlab ARCH-type code and replace the volatility dynamics with a MIDAS polynomial specification. It would not be generic, but easy to tailor to a specific application you have in mind.

I agree that it would be useful to have generic MIDAS volatility code publicly available. I've had discussions with Hang on this topic.

Sincerely,

Eric Ghysels

Comment only
08 May 2015 Du-hyun Cho

It is honor to say to you Eric
Actually, I am deeply interested asymmetric MIDAS model in your paper "There is risk return tradeoff after all"

One of my focuses is finding empirical relations between risk and return though estimating ICAPM model in Asian Pacific stock market.

Anyway I found a related toolbox manual

the ULR is that
http://pages.stern.nyu.edu/~ehedegaa/PDFs/MidasManual.pdf

However, there was only manual of a toolbox but I couldn't find original toolbox still.

If I wouldn't be bothering you, I want to ask a help about the toolbox.

Anyway,thank you for giving a change to me describing my focus. I will wait your answer Thank you very much

Comment only
08 May 2015 Du-hyun Cho

It is honor to say to you Eric
Actually, I am deeply interested asymmetric MIDAS model in your paper "There is risk return tradeoff after all"

One of my focuses is finding empirical relations between risk and return though estimating ICAPM model in Asian Pacific stock market.

Anyway I finded a related toolbox manual

the ULR is that
http://pages.stern.nyu.edu/~ehedegaa/PDFs/MidasManual.pdf

However, there was only manual of a toolbox but I couldn't find original toolbox still.

If I wouldn't be bothering you, I want to ask a help about the toolbox.

Anyway,thank you for giving a change to me describing my focus. I will wait your answer Thank you very much

07 May 2015 Eric

Eric (view profile)

Dear Du-hyun:

Would you mind being more specific about asymmetric MIDAS - what exactly you are thinking of?

Thanks

Eric Ghysels

Comment only
07 May 2015 Du-hyun Cho

Thnak you very much for your kindness
I tried again as I mentioned before and there is no problem the error message has been completely removed.

If it wouldn't be annoying you, I want to ask one more question with respect to asymmetric MIDAS regression.

first, is this code available for asymmetric MIDAS? or needed to change some codes or syntax of this toolbox.

I tried to find asymmetric model form Eric Ghysels homepage and other authors of academic papers related to MIDAS model but this is not really easy task to find it.

could you give me an idea? I shall wait your answer

06 May 2015 Hang Qian

Hang Qian (view profile)

Hi Du-hyun,

Thank you for catching that.

The error message at Line 392 pops up after parameter estimation. The estimation results have displayed on the screen. This line just makes date display more beautiful. The error comes from reshaping a vectorized empty matrix; it changes the row/column dimension of an empty matrix.

I have updated the codes. The error message should disappear.

Comment only
06 May 2015 Du-hyun Cho

Hi Qian

firstly, Thanks for uploading the toolbox

Actually, I wander how to use DL MIDAS model in this tool box.

I tried several times Ylag = 0 in the toolbox because, in my research, autoregression terms do not needed.

unfortunately, there is several error massage in matlab like

Error : MIDAS_ADL (line 392)
MixedFreqData.EstLagYdate = reshape(cellstr(datestr(MixedFreqData.EstLagYdate)),size(MixedFreqData.EstLagYdate));

is there any method to clean that error?

Comment only
06 May 2015 Hang Qian

Hang Qian (view profile)

Hi Ruizhi,

I did not test and do not know whether the program can work properly using minute or second data, but you may have a try. DataXdate and DataYdate follow the MATLAB supported time format. For example, 01-Mar-2000 15:45:17 and 2000-03-01 15:45:17 can be recognized by MATLAB.

Thank you.

Comment only
05 May 2015 Ruizhi Ma

Hello! Really thanks for the upload! I'm curious about using intra-daily data to forecast daily stock returns by MIDAS, how can I write the DataXdate and DataYdate ? Thank you!

Comment only
05 May 2015 Anni208

Thank you for the very fast answer!
I will follow your advice!

Comment only
04 May 2015 Hang Qian

Hang Qian (view profile)

Hi Anni208,

The date string '01.04.1947' is not a supported MATLAB date format, so it cannot be parsed by the program. MATLAB has 14 supported formats, such as '01/04/1947', '1947-01-04', '04-Jan-1947', 'Jan.01,1947', etc.. If you could change your date format to one of the supported formats, the error message will disappear.

You may refer to this page for the MATLAB date string format:

http://www.mathworks.com/help/matlab/ref/datevec.html

Thank you.

Comment only
04 May 2015 Anni208

Hello!
I'm very cuurious to try your code unfortunately while running appADLMIDAS1.m I receive the following error message:

Error using datevec (line 277)
Cannot parse date 01.04.1947.

Why is there a problem with datevec? Can you please help me with this?
Thanks in advance!
Anni208

Comment only
27 Apr 2015 WMendieta89

Thank you very much for your reply! It worked!

Thanks again for this great toolkit.

William M.

Comment only
14 Apr 2015 Hang Qian

Hang Qian (view profile)

Hi WMendieta,
MIDAS uses a direct multi-step forecast. For example, if we want a 3-step ahead forecast, we specify a MIDAS model as
Y(t+3) = b0 + b1*Y(t) + b2*Y(t-1) + ... + high frequency regressor terms X(j,t-i), j=1,...,Nd, i = 0,1,2,...
Similarly, for a 5-step ahead forecast, we use a model like
Y(t+5) = b0 + b1*Y(t) + b2*Y(t-1) + ... + high frequency regressor terms X(j,t-i), j=1,...,Nd, i = 0,1,2,...
By direct forecast, we mean the left hand side of the model is the h-step ahead dependent variable. This is in contrast to the iterated forecast in an autoregressive model.
Please refer to Section 2.3 of the MIDAS user guide for the multi-step forecast:
http://www.unc.edu/~eghysels/papers/MIDAS_Usersguide_V1.0.pdf
For the software usage, put the lagged dependent variables in 'ExoReg' and then adjust the name-value pair 'Horizon' accordingly.
Thank you.

Comment only
13 Apr 2015 WMendieta89

Hi! Thanks for uploading this toolbox! I wonder how do you perform h-step ahead forecast using this toolbox? I have performed 1 step ahead out-of-sample forecast but i´ve been unable to do so for h-step ahead forecasts

thanks in advanced,

WMendieta

Updates
08 Apr 2014 1.1

Allow leads and lags specification 'horizon' be negative.

Add true out-of-sample forecast; results are restored in the last output argument 'Extended Forecast' struct.

06 May 2015 1.2

Support the special case DL_MIDAS by setting Ylag = 0

09 Jun 2015 1.2

Update the user guide (version Dec 21, 2014)

16 Jul 2015 1.5

Support Ylag as a cell array such as Ylag = {3,6,9} for flexible low frequency lagged regressors
Support Xlag = 0, so that the high frequency regressors are suppressed. OLS results will be produced.
User guide is updated to the version July 16, 2015

01 Nov 2015 2.0

Add GARCH-MIDAS and DCC-MIDAS functions

01 Nov 2015 2.0

Update the toolbox title from "MIDAS Regression" to "MIDAS Matlab Toolbox"

01 Nov 2015 2.0

Package written by Eric Ghysels and collaborators

Contact us