# Generating time series for electricity demand

I'm working on a project, trying to model electricity consumption and generation from a bunch of PV generators to see how much of the demand can be satisfied by the production in the "town". Most models use a fixed demand and production profile in an hourly time-series.

I'd like to see how variations in both production and demand would influence the outcome. So basically a Monte Carlo simulation of the whole system.

Is there a relatively easy way to vary a given demand and production profile with a sort of random factor? Obviously the diurnal and annual variations should still be similar to the "measured" dataset.

I played around with something called Iterative Amplitude Adapted Fourier Transform, but the variations are totally out of whack (maybe because I didn't adjust the parameters correctly). Sadly my education in statistics is not very deep.

Thanks for any suggestion!

The easiest way would probably to take an electricity demand (or production) time series, fit an appropriate model, randomly permute the residuals and add these back to the fitted values. You can inflate the permuted residuals to make the simulated series less similar to the original series.

Alternatively, don't resample the residuals, but instead draw from an appropriate parametric distribution. However, given the amount of data you will likely be working with, I don't this this will yield very different results from the permutation approach.

Here is an example. A good model to fit electricity data is , which can model . The top left panel is the original series; the rest are resampled simulations. Note how the intra-daily and intra-weekly patterns look similar, but the simulated series are more noisy. You can tweak the scaling-factor to govern this.

library(forecast)
taylor.fit <- tbats(taylor)

scaling.factor <- 100000
opar <- par(mfrow=c(3,3),mai=c(.4,.4,0,0))
plot(taylor,xlab="",ylab="",ylim=c(15000,44000))
for ( ii in 1:8 ) {
set.seed(ii)
plot(fitted(taylor.fit)+scaling.factor*sample(residuals(taylor.fit),length(taylor)),
xlab="",ylab="",ylim=c(15000,44000))
}
par(opar)

• Thanks for this helpful answer! I needed some time to get the essentials in R since I'm usually using Matlab. But after having some trouble with the exact format of the time series, I managed to create similar (looking) datasets. Am I correct that the sample() in the code is responsible for the random variations? – TinkerPhil Nov 9 '17 at 0:59
• Yes. sample(x,n) will take a sample of size $n$ out of a vector $x$, by default without replacement. So if n==length(x), then this amounts to a random permutation. Unfortunately, I don't know whether the bats or tbats models are available in Matlab - you may need to roll your own model that can deal with multiple-seasonalities (if, as I suspect, these are important in your data). – Stephan Kolassa Nov 9 '17 at 7:39
• Ok then I got this right. No, I couldn't find something similar in Matlab, but I made it work and might just use R to create the time-series and subsequently import them into Matlab. Thanks again! – TinkerPhil Nov 9 '17 at 21:38