%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Data and codes (MatLab, Gauss, R) for reproducing results from the paper: 
"Are multifractal processes suited to forecasting electricity price volatility? Evidence from Australian intraday data"
(Mawuli Segnon, Chi Keung Lau, Bernd Wilfling, Rangan Gupta)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I. Data description:

The Excel file "elec_bernd.xls" in the folder "Data" contains two worksheets:
- Worksheet #1 contains the returns for the five states: NSW, QLD, SA, TAS and VIC.
- Worksheet #2 contains the realized variances for all five states: NSW, QLD, SA, TAS and VIC.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

II. Seasonality: 

- The MatLab code "Seasonality.m" removes seasonalities from the data. 
- After having removed seasonalities, you obtain the new Excel file "elec_bernd_sea.xls" in the folder "Data". The file
  has two worksheets:
  * Worksheet #1 contains the seasonally adjusted returns for the five states: NSW, QLD, SA, TAS and VIC.
  * Worksheet #2 contains the seasonality adjusted realized variances for the five states: NSW, QLD, SA, TAS and VIC.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

III. Data analysis

(a) Volatility spillover analysis (Granger causality):
    R code: "granger_causality_test.R" provides Granger-causality tests in multivariate and bivariate VAR frameworks 
            for different sample sizes.

(b) Descriptive statistics:
    Matlab code: - "insample_elect.m" provides descriptive statistics from Table 1.
                 - "multifractalplot.m" provides the multifractal detrented fluctuation analysis from Figures 3 and 4.
                 - "lags.m" provides the the optimal lag lengths in the STARFIMA model.

    Gauss code: - "Structural_break" provides the structural break points.
                  (To get the code running, you need the GAUSS source files "icss" and "variance".)

(c) Estimation of the mean process:
    Matlab code: - "Istar.m" estimates STAFRIMA.
    Gauss code: - "MSARFIMA" estimates MSARFIMA.
            
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

IV. Forecasting procedures

(a) GARCH-type and Markov-switching GARCH-type volatility processes:
- Matlab code: "for_garch.m", "for_egarch.m", "for_gjr.m" in folder "GARCH_EGARCH_GJR" produce forecasts for 
               the standard GARCH, EGARCH, GJR models.
- Matlab code: "for_aparch.m" in folder "APARCH" produces forecasts for the APARCH model.
- Matlab code: "for-figarch.m" in folder "FIGARCH" produces forecasts for the FIGARCH model.
- Matlab code: "for-fiaparch.m" in folder "FIAPARCH" produces forecasts for the FIAPARCH model.
- Matlab code: "for-stfigarch.m" in folder "STFIGARCH" produces forecasts for the STFIGARCH model.
- Matlab code: "for-stfiaparch.m" in folder "STFIAPARCH" produces forecasts for the STFIAPARCH model.
- Matlab code: "for-msgarch.m" in folder "MSGARCH" produces forecasts for the MSGARCH model.
- Matlab code: "for-msfigarch.m" in folder "MSFIGARCH" produces forecasts for the MSFIGARCH model.
- Matlab code: "for-msfiaparch.m" in folder "MSFIAPARCH" produces forecasts for the MSFIAPARCH model.

(b) Markov-switching multifractal (MSM) model:
-Gauss codes:  "MSM_elec_forecasts" produces forecasts for the Markov-switching multifractal (MSM) model.
              
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

V. Forecast evaluation: 

Gauss code: - "elec_loss" produces the results for RMSE and MAE loss functions.
            - "dm_elec" produces the results of the Mariano and Diebold (1995) test. 
              (Equal Predictive Ability, EPA)
            - "spa_elec_MSE" and "spa_elec_MAE" produces the results of the Hansen (2005) test.
              (Superior Predictive Ability, SPA)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Feel free to contact us in case of running problems (email to: segnon@uni-muenster.de).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
