ACF does not run in Quantmod library

Hello folks,
I am new to R and am working on a school project and have using trying to test ACF test, the following code works unit the point ACF testing. I get the error as " Error in na.fail.default(as.ts(x)) : missing values in object" . this is using quantmod only. Please advise me as to how to fix this. thank you in advance .

My understand is the log return for the first date is missing. Please make corrections

AAPL.Adjusted
2007-01-03 NA
2007-01-04 0.021952724
2007-01-05 -0.007146586
2007-01-08 0.004926015
2007-01-09 0.079799289
2007-01-10 0.046746206

library(quantmod)
getSymbols("AAPL")
AAPL.rtn=diff(log(AAPL$AAPL.Adjusted))
t.test(AAPL.rtn)

acf(AAPL.rtn)
Error in na.fail.default(as.ts(x)) : missing values in object

thank you,

It won't run with the NA value there. This will work.

AAPL <- na.omit(AAPL.rtn) # removes the NAs
acf(AAPL)
1 Like

thank you so much Williaml. it worked, I appreciate it

I am trying to fo Augment dickey -fuller test after this and have following code; and get the error. Am I missing any library since I only have quantmod , please help , thanks in advance

m1=ar(AAPL, method='mle')
m1$order

Error in ar.mle(x, aic = aic, order.max = order.max, na.action = na.action, :
MLE only implemented for univariate series

The function (when using the 'mle' method) expects a time series. Try this:

ar(as.ts(AAPL), method = "mle")

# results
Call:
ar(x = as.ts(AAPL), method = "mle")

Coefficients:
      1        2        3        4        5        6        7        8        9       10       11       12  
-0.0298  -0.0220  -0.0041   0.0457   0.0131  -0.0394   0.0431  -0.0400   0.0303  -0.0032  -0.0016   0.0403  

Order selected 12  sigma^2 estimated as  0.0004094

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.