Code covered by the BSD License  

Highlights from
Electricity Load and Price Forecasting Webinar Case Study

image thumbnail

Electricity Load and Price Forecasting Webinar Case Study



10 Sep 2010 (Updated )

Slides and MATLABĀ® code for the day-ahead system load and price forecasting case study.

genPredictors(data, term, holidays)
function [X, dates, labels] = genPredictors(data, term, holidays)
% GENPREDICTORS generates a matrix of predictor variables for the load
% forecasting model. 
% [X, dates, labels] = genPredictors(data, term, holidays)
% Inputs:
% data     : A Dataset array of historical weather and load information
% term     : 'long' or 'short' indicating the horizon of the forecast.
%            Predictors such as previous day load are not included in the 
%            long term forecast.
% holidays : A vector of holidays. If this is not specified, holidays are
%            generated by the function CREATEHOLIDAYDATES
% Outputs:
% X     : A matrix of predictor data where each row corresponds to an
%         observation (hourly load) and each column corresponds to a variable
% dates : A vector of dates for each observation
% labels: A cell array of strings describing each predictor

% Convert Dates into a Numeric Representation
    dates = data.NumDate;
catch %#ok<CTCH>
    dates = datenum(data.Date, 'yyyy-mm-dd HH:MM:SS') + (data.Hour-1)/24;
if all(floor(dates)==dates) % true if dates don't include any hour information
    dates = dates + (data.Hour-1)/24;

% Process Holidays
if nargin < 3 || isempty(holidays)
    holidays = createHolidayDates(min(dates), max(dates));
    holidays = datenum(holidays);

% Create Predictors

% Short term forecasting inputs
% Lagged load inputs
prevDaySameHourLoad = [NaN(24,1); data.SYSLoad(1:end-24)];
prevWeekSameHourLoad = [NaN(168,1); data.SYSLoad(1:end-168)];
prev24HrAveLoad = filter(ones(1,24)/24, 1, data.SYSLoad);
%prev24HrAveLoad = filter(ones(1,24)/24, 1, [NaN(24,1); data.SYSLoad(1:end-24)]);

% Date predictors
dayOfWeek = weekday(dates);

% Non-business days
isWorkingDay = ~ismember(floor(dates),holidays) & ~ismember(dayOfWeek,[1 7]);
%[~,~,isWorkingDay] = createHolidayDates(data.NumDate);

if strncmpi(term, 'long', 4);
    % Long Term Forecast Predictors
    X = [data.DryBulb data.DewPnt daily5dayHighAve daily5dayLowAve data.Hour dayOfWeek isWorkingDay];
    labels = {'DryBulb', 'DewPoint', 'Prev5DayHighAve', 'Prev5DayLowAve', 'Hour', 'Weekday', 'IsWorkingDay'};
    % Short Term
    X = [data.DryBulb data.DewPnt data.Hour dayOfWeek isWorkingDay prevWeekSameHourLoad prevDaySameHourLoad prev24HrAveLoad];
    labels = {'DryBulb', 'DewPoint', 'Hour', 'Weekday', 'IsWorkingDay', 'PrevWeekSameHourLoad', 'prevDaySameHourLoad', 'prev24HrAveLoad'};

function y = rep24(x)
y = repmat(x(:), 1, 24)';
y = y(:);

Contact us