0

I'm trying to use Holt Winters and prediction function for stock index weekly volume from last 10 years, however i am still getting error. Can you help me please?

This is what i'm trying to do now:

volumen<-read.csv(file.choose(), header = TRUE, sep = ";")
lines(volumen[,6])
HoltWinters(volumen)

This is error I'm getting on third row:

Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) :
  the time series has no periods or has less than 2

For prediction i have below code, however it does not seems to work with previous error:

lines(predict(volumen.hw,n.ahead=12),col=2)

Data in R Studio looks correct. I have decided to use file.choose() to make this code more universal. I am using *.csv file. Could someone guide me or advise what the code should look like to apply the Holt and Winters method and prediction?

Carol
  • 1
  • 2
  • It seems like if you are getting an error in line 3 you might want to share what is in that line. Also are you sure that you have read this in as ts? You may want to do `class("volumen")` to make sure. – Elin Apr 08 '18 at 18:51
  • As shown in my post line 3 is: `HoltWinters(volumen)` I was also experimenting with ts but still got the same error. – Carol Apr 08 '18 at 20:38
  • Oh i thought you meant line three of the file. SO you need to make that a ts file with a period and start, finish. It would help if you would provide a minimal example with actual data. Just a few rows. – Elin Apr 08 '18 at 21:27
  • Thanks for reply @Elin. I have changed to ts aslike this `volumen<-read.csv(file.choose(), header = TRUE, sep = ";") dane2 <-ts(volumen[,6]) plot(volumen[,6]) HoltWinters(dane2)` but still getting the same error. Couple lines of data here: **Wolumen 285945946 231919384 296523526 345960630 118742864 187254056** – Carol Apr 09 '18 at 07:55
  • Look at ?ts `ts(data = NA, start = 1, end = numeric(), frequency = 1, deltat = 1, ts.eps = getOption("ts.eps"), class = , names = )` you need to set the start and frequency etc. Try tsp(lynx) and tsp(volumen) and see if you get similar attributes. – Elin Apr 09 '18 at 23:17

3 Answers3

0

It's hard to be 100% sure but

HoltWinters(lynx) generates the same message as you are gettin,g but HoltWinters(lynx, gamma = FALSE)

generates

Holt-Winters exponential smoothing with trend and without seasonal component.

Call: HoltWinters(x = lynx, gamma = FALSE)

Smoothing parameters:
alpha: 1
beta : 0
gamma: FALSE

Coefficients: [,1] a 3396 b 52

Which I learned from reading the examples in the HoltWinters documentation.

Elin
  • 6,507
  • 3
  • 25
  • 47
0

first of all it would be nice if you put your data here (if it is not private).

Secondly as far as I know you only can user HoltWinters() or any other method in the forecasting package to a vector or a time series so loading the entire dataset (volume) without specifying the rows could lead you to a problem.

Finally I recommend you to try the HW to an auxiliary vector containing the data that you want to study and also specify the frequency of the time series:

aux_train<-as.ts(volumen$variable, start=1, end=0.9*nrow(volume),  freq="yourfrecuency")
prediction<-forecast(aux_train, h="number of forecast", method="hw")
accuracy(prediction, volumen$value)
tfkLSTM
  • 161
  • 13
0

I have finally won this battle - I have deleted my code and started from scratch. Here is what I came with:

dane2<-read.csv2(file.choose(), header = TRUE, sep = ";", dec=",")
dane2 <-ts(dane2[,5], start=c(2008,1),frequency=52)
past <- window(dane2, end = 2017)
future <- window(dane2, start = 2017)
model <- HoltWinters(past, seasonal = "additive") 
model2 <- HoltWinters(past, seasonal = "multiplicative") 
pred <- predict(model, n.ahead = 52)
pred2 <- predict(model2, n.ahead = 52)
dane2.hw<-HoltWinters(dane2)
predict(dane2.hw,n.ahead=52)
par(mfrow = c(2,1)) 
plot(model, predicted.values = pred)
lines(future, col="blue")
plot(model2, predicted.values = pred2)
lines(future, col="blue")

Now it works, so thank you for your answers.

Carol
  • 1
  • 2
  • 1
    You should explain what it is that you actually changed and why that change fixed it. Then it would be a good answer and you could accept it. It would be helpful if you upvoted and referenced any other answers that helped you along the way. – Elin May 05 '18 at 17:46