简体   繁体   中英

Holt Winters For Weekly Volume And Errors In R

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?

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.

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM