File Exchange

## Long Term Energy Forecasting with Econometrics in MATLAB

version 1.5.0.1 (7.23 MB) by
Dynamic energy demand forecasting using Econometrics (ARIMA/VAR/GARCH)

Updated 01 Sep 2016

View this example as a Recorded Webinar at:
http://mathworks.com/videos/long-term-energy-forecasting-with-econometrics-in-matlab-99301.html
Since 2008 energy demand in Australia has started to decline. The result, traditional regression based models that were being used to forecast long term energy load were now highly inaccurate in their predictions. Energy demand has since continued to fall, however will it increase again? If so, how can this be predicted? A dynamic model to forecast long term energy demand is needed.
In this example, we’ll demonstrate how using econometrics techniques, you can create a dynamic, self-tuning model for predicting long term energy load. We will look at building ARIMA/GARCH and Vector Autoregressive (VARX) forecasting models based of historical energy and economic data sets.

### Cite As

David Willingham (2021). Long Term Energy Forecasting with Econometrics in MATLAB (https://www.mathworks.com/matlabcentral/fileexchange/49279-long-term-energy-forecasting-with-econometrics-in-matlab), MATLAB Central File Exchange. Retrieved .

Abolfazl Nejatian

Nicely Written Code,
This is my forecasting code which allows you to predict your time series data with LSTM, CNN, and MLP Networks.

https://www.mathworks.com/matlabcentral/fileexchange/69506-time-series-prediction

RMan!

vgxset has been removed, not sure how to replace it with varm

polar

I'm following the script of the code "example1_foreceast_arima" and it seems reasonable and clear.
However I don't understand 2 things:
1)Why using a 6 sum of sines? I mean, my question is due to the fact I'm a newbye in sinusoidal models for temperature: I know that for understanding the "b1","b2" etc. coefficients I should use the formula: 2pi/DatesPeriod =b. But I see that dates have been normalized so I confess I'm not able to understand which are these 6 periods(daily,monthly,weekly etc.).

2)ARIMA model: I agree in saying it's hard to follow the thumb rule for determining MA and AR by looking at ACF and PACF graphs output. My dubt is about the choice for the Garch(1,1). In the script it has been determined by looking at the ACF/PACF of Diff(F)^2 but I thought we should use the error^2 for determining the GARCH.

polar

Hi David (and really thanks for your patience!).

Of course, I can run ALL others scripts, my problems are just related to "data_prep_example.m".

David Willingham

Hi Polar,

I've downloaded the code an amm running the code without error, so I'm not sure what is causing your issues.

Beside the data_prep_example.m script, are you able to run one of the other examples? Such as:

example0_foreceast_sde.m

What version of MATLAB are you using?

polar

yes David you're right about the fact that import_load_price is a script and not a ".mat" file. However In the code I downloaded (and as far as I remember I didn't changed) is writtem "load import_load_price". Anyway I deleted the word "load" and it moved on...until these next error messages

Warning: Usage of DATEVEC with empty date strings is not supported.
Results may change in future versions.
> In datevec (line 89)
In dataprep1_convert_monthly (line 9)
In data_prep (line 16)
In data_prep_example (line 19)
Index exceeds matrix dimensions.

Error in dataprep1_convert_monthly (line 67)
dvec = [datenum(dvecstr(1,:),'mm,yyyy'):1:datenum(dvecstr(end,:),'mm,yyyy')]';

Error in data_prep (line 16)
T = dataprep1_convert_monthly(ds,dE); % Energy Demand

Error in data_prep_example (line 19)
TEcon = data_prep(ds,dE);

David Willingham

Hi Polar,

I've looked at the code and there is not import_load_price mat file but a import_load_price.m (script file). I've also looked at the dataprep1 file and there the command isn't:

but just

polar

David, about your advice about the folder "dataprep": I indeed copied and pasted to my path some of its files such as :
1) function "data_prep"
2) function "dataprep1_convert_monthly"
Then, I re-run the "data_prep_example" and these are the error messages:

Error in dataprep1_convert_monthly (line 6)

Error in data_prep (line 16)
T = dataprep1_convert_monthly(ds,dE); % Energy Demand

Error in data_prep_example (line 19)
TEcon = data_prep(ds,dE);

So....I really don't know what to do.

Ahmed Sheikh

Thank you.I'll check again and see how it goes and get back to you later.I appreciate your prompt response.

David Willingham

Hi Ahmed, I'm using the table datatype which came out in 13b. So you'll need to use a newer version of MATLAB to run

Ahmed Sheikh

Warning: Variable 'T' originally saved as a table cannot be instantiated as an object and will be read in as a uint32.
> In example0_foreceast_sde at 12
Attempt to reference field of non-structure array.

Error in example0_foreceast_sde (line 14)
dates = [num2str(T.Months),repmat('/',length(T.Months),1),num2str(T.Years)];

how to resolve this issue? i am trying to get month and year but seems like there is something wrong with Matlab version.I am using Matlab 2013a.

David Willingham

Hi, Did you add the dataorep folder to the MATLAB path? The file is in there.

polar

Hi David this is list of error messages (sigh):

Error in dataprep1_convert_monthly (line 6)

Error in data_prep (line 16)
T = dataprep1_convert_monthly(ds,dE); % Energy Demand

Error in data_prep_example (line 19)
TEcon = data_prep(ds,dE);

David Willingham

What error messages do you receive?

polar

I tried on a friend's version (matlab 2015b) and now I made the code working.
Or better I still have a problem when trying to run "data_prep_example". In fact it recalls other two routines:1)"data_prep" and 2) "dataprep1_convert_monthly". It seems that the very original problem is related to the permission of the "fopen" command in the routine "import_load_price". I don't know what to do

David Willingham

What version of MATLAB are you using? To check type : >> ver

polar

Can anyone tell me how to run codes?
I mean, not only the order of files but what to do to avoid the error messages.
So far I tried with this ".m" files:
1)data_prep_example
2)example0_foreceast_sde

Thanks

##### MATLAB Release Compatibility
Created with R2014b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux