1 Introduction

For this report, I will be analayzing Monthly Natural Gas Prices. Specifically I will be analyzing gas prices from January 2008 to August of 2020 To do this, I will build a time series with the data and then decompose and forecast with the time series.

Gas <- read.csv("MonthlyGasPrices.csv")
n.row = dim(Gas)[1]
data.Gas = Gas[(n.row-150):n.row, ]

2 Time Series Analysis

2.1 Building the Time Series

First, i will build the time series, using a monthly period.

Gas.ts = ts(data.Gas[, 2], frequency = 12, start = c(2008, 1))
par(mar = c(2, 2, 2 ,2))
plot(Gas.ts, main = "Natural Gas Prices From January 2008 to August 2020", ylab=" Monthly Gas Price (Dollars)", xlab="")

Next, I will decompose this series into a multiplicative series. I will also decompose via Seasonal and Trend using LOESS (STL).

cls.decomp = decompose(Gas.ts, "multiplicative")
par(mar=c(2, 2, 2, 2))
plot(cls.decomp, xlab="")

stl.decomp = stl(Gas.ts, s.window = 12)
par(mar=c(2, 2, 2, 2))
plot(stl.decomp)

3 Forecasting and Error

To forecast, I will split the data into four training sets of different sizes (144, 109, 73, and 48).

ini.data = data.Gas[,2]
n0 = length(ini.data)
##
train.data01 = data.Gas[1:(n0-7), 2]
train.data02 = data.Gas[37:(n0-7), 2]
train.data03 = data.Gas[73:(n0-7), 2]
train.data04 = data.Gas[97:(n0-7), 2]
## last 7 observations
test.data = data.Gas[(n0-6):n0,2]
##
train01.ts = ts(train.data01, frequency = 12, start = c(2008, 1))
train02.ts = ts(train.data02, frequency = 12, start = c(2011, 1))
train03.ts = ts(train.data03, frequency = 12, start = c(2014, 1))
train04.ts = ts(train.data04, frequency = 12, start = c(2017, 1))

Next, some forecasting:

stl01 = stl(train01.ts, s.window = 12)
stl02 = stl(train02.ts, s.window = 12)
stl03 = stl(train03.ts, s.window = 12)
stl04 = stl(train04.ts, s.window = 12)
## Forecast with decomposing
fcst01 = forecast(stl01,h=7, method="naive")
fcst02 = forecast(stl02,h=7, method="naive")
fcst03 = forecast(stl03,h=7, method="naive")
fcst04 = forecast(stl04,h=7, method="naive")

Now, to calculate errors:

PE01=(test.data-fcst01$mean)/fcst01$mean
PE02=(test.data-fcst02$mean)/fcst02$mean
PE03=(test.data-fcst03$mean)/fcst03$mean
PE04=(test.data-fcst04$mean)/fcst04$mean
###
MAPE1 = mean(abs(PE01))
MAPE2 = mean(abs(PE02))
MAPE3 = mean(abs(PE03))
MAPE4 = mean(abs(PE04))
###
E1=test.data-fcst01$mean
E2=test.data-fcst02$mean
E3=test.data-fcst03$mean
E4=test.data-fcst04$mean
##
MSE1=mean(E1^2)
MSE2=mean(E2^2)
MSE3=mean(E3^2)
MSE4=mean(E4^2)
###
MSE=c(MSE1, MSE2, MSE3, MSE4)
MAPE=c(MAPE1, MAPE2, MAPE3, MAPE4)
accuracy=cbind(MSE=MSE, MAPE=MAPE)
row.names(accuracy)=c("n.144", "n.109", "n. 73", "n. 48")
kable(accuracy, caption="Error comparison between forecast results with different sample sizes")
Error comparison between forecast results with different sample sizes
MSE MAPE
n.144 0.0502943 0.0839476
n.109 0.0522701 0.0860305
n. 73 0.0686739 0.1212956
n. 48 0.1420157 0.2078806

The errors are low, which seems to suggest forecasting with STL did good.

plot(1:4, MSE, type="b", col="darkred", ylab="Error", xlab="",
     ylim=c(0.05, 1),xlim = c(0.5,4.5), main="Error Curves", axes=FALSE)
labs=c("n=144", "n=109", "n=73", "n=48")
axis(1, at=1:4, label=labs, pos=0.4)
axis(2)
lines(1:4, MAPE, type="b", col="blue")
text(1:4, MAPE+0.03, as.character(round(MAPE,4)), col="blue", cex=0.7)
text(1:4, MSE-0.03, as.character(round(MSE,4)), col="darkred", cex=0.7)
legend(1.5, 0.63, c("MSE", "MAPE"), col=c("darkred","blue"), lty=1, bty="n", cex=0.7)

4 Summary and Conclusion

This study focused on analyzing Monthly Natural Gas Prices from January 2008 to August 2020. A time series was built and decomposed using the classical multiplicative method and STL. Forecasting was done with training and testing data, and errors were calculated and graphed. STL did good as the errors were low.