HI Joshua Ulric,

I used coredata to covert to data frame
but getting error

Error in ht$p - value : non-numeric argument to binary operatorIn
addition: Warning message:sd(<matrix>) is deprecated.
 Use apply(*, 2, sd) instead.

t1=data.frame(date=index(spreadT), coredata(spreadT))
    #find cointegration coefficient

    x=as.vector(t1[,2])
    ht <- adf.test(as.numeric(x), alternative="stationary", k=0)
    cat("ADF p-value is", ht$p-value, "\n")

Kindly help me
thanks
veepsirtt


On Fri, Aug 2, 2013 at 2:05 PM, veepsirtt [via R] <
ml-node+s789695n4672880h60@n4.nabble.com> wrote:

> Hi,
>                    I couldnot find cointegration coefficient  while using
> adf.test.
>
> Error in ht$p - value : non-numeric argument to binary operator
> In addition: Warning message:
> sd(<matrix>) is deprecated.
>  Use apply(*, 2, sd) instead.
>
> --------------------------------------------- The
> code----------------------------------------------
> if (!require(quantmod)) {
>   stop("This app requires the quantmod package. To install it, run
> 'install.packages(\"quantmod\")'.\n")
> }
>
> # Download data for a stock if needed, and return the data
> require_symbol <- function(symbol, envir = parent.frame()) {
>   if (is.null(envir[[symbol]])) {
>     envir[[symbol]] <- getSymbols(symbol, auto.assign = FALSE)
>   }
>
>   envir[[symbol]]
> }
>
>   # Create an environment for storing data
>   symbol_env <- new.env()
>
>     #Utilize quantmod to load the security symbols
>     require(quantmod)
>     library(zoo)
>     library(tseries)
>
>     s1="SPY"
>     s2="GOOG"
>
>     a <- require_symbol(s1, symbol_env)
>     b <- require_symbol(s2, symbol_env)
>
>     #remove NAs
>     c=cbind(a,b)
>     final=na.omit(c)
>     row.has.na <- apply(final, 1, function(x){any(is.na(x))})
>     sum(row.has.na)
>
>     A<- c[, c(1,2,3,4,5,6)]
>     B<- c[, c(7,8,9,10,11,12)]
>
>     #define training set
>     startT  <- "2007-01-02"
>     endT    <- "2009-01-01"
>     rangeT  <- paste(startT,"::",endT,sep ="")
>     tA   <- A[,6][rangeT]
>     tB   <- B[,6][rangeT]
>
>     #define out of sample set
>     startO  <- "2013-02-01"
>     endO <-Sys.Date()
>     rangeO  <- paste(startO,"::",endO,sep ="")
>     oA   <- A[,6][rangeO]
>     oB   <- B[,6][rangeO]
>
>     #compute price differences on in-sample data
>     pdtA <- diff(tA)[-1]
>     pdtB <- diff(tB)[-1]
>
>     #build the model
>     model  <- lm(pdtA ~ pdtB - 1)
>
>     #extract the hedge ratio
>     hr     <- as.numeric(model$coefficients[1])
>     #spread price (in-sample)
>     spreadT <- oA - hr * oB
>
>     days=length(spreadT)
>
>     #compute statistics of the spread
>     meanT    <- as.numeric(mean(spreadT,na.rm=TRUE))
>     sdT      <- as.numeric(sd(spreadT,na.rm=TRUE))
>
>     #find correlation coefficient
>     cr=   cor(oA, oB, method="spearman")
>
>     #find cointegration coefficient
>     ht <- adf.test(spreadT, alternative="stationary", k=0)
>     cat("ADF p-value is", ht$p-value, "\n")
>     -----------------------------------------------the
> code--------------------------------------------------------
>
>
> Thanks
> veepsirtt
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://r.789695.n4.nabble.com/Finding-price-difference-of-a-time-series-tp4672099p4672880.html
>  To unsubscribe from Finding price difference of a time series, click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4672099&code=dmVlcHNpcnR0QGdtYWlsLmNvbXw0NjcyMDk5fDY5NzkzMTE3Nw==>
> .
> NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://r.789695.n4.nabble.com/Finding-price-difference-of-a-time-series-tp4672099p4672889.html
Sent from the Rmetrics mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]

