Questions tagged [xts]

xts is an R package that contains an eXtensible Time Series class and methods. xts extends and behaves like zoo.

xts is an package for analysis. It provides uniform handling of R's different time-based data classes by extending the package.

Repositories

Vignettes

Other resources

Related tags

1987 questions
14
votes
1 answer

ADD a new column into an XTS object

Hi: I have an xts object as such: AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted 2013-09-09 505.00 507.92 503.48 506.17 12116200 506.17 2013-09-10 506.20 507.45 489.50 494.64 …
Ahdee
  • 4,679
  • 4
  • 34
  • 58
13
votes
2 answers

R Subset XTS weekdays

How do I subset an xts object to only include weekdays (Mon-Fri, with Saturday and Sunday excluded)?
Kyle Brandt
  • 26,938
  • 37
  • 124
  • 165
13
votes
3 answers

can I write an xts object using write.csv in R

I have an xts object, the first column of which is date-time, followed by OHLC. when I type >test it prints the correct output as follows: 2010-09-08 15:13:00 115 115 110 115 2010-09-08 15:14:00 120 125 115 125 however, when I try…
user1155299
  • 877
  • 5
  • 20
  • 29
13
votes
2 answers

Speedup conversion of 2 million rows of date strings to POSIX.ct

I have a csv which includes about 2 million rows of date strings in the format: 2012/11/13 21:10:00 Lets call that csv$Date.and.Time I want to convert these dates (and their accompanying data) to xts as fast as possible I have written a script…
n.e.w
  • 1,128
  • 10
  • 23
12
votes
2 answers

R xts and data.table

I can convert a data.table to an xts object just as I do with a data.frame: > df = data.frame(x = c("a", "b", "c", "d"), v = rnorm(4)) > dt = data.table(x = c("a", "b", "c", "d"), v = rnorm(4)) > xts(df, as.POSIXlt(c("2011-01-01 15:30:00",…
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91
12
votes
5 answers

Fill NA in a time series only to a limited number

Is there a way we can fill NAs in a zoo or xts object with limited number of NAs forward. In other words like fill NAs up to 3 consecutive NAs, and then keep the NAs from the 4th value on until a valid number. Something like this. library(zoo) x <-…
Kate K
  • 175
  • 7
12
votes
1 answer

correlation error: 'x' must be numeric

I have a XTS dataset that contains many stock closing prices called: dataset. I then wanted to find if their returns have any correlation via cor() , however I get an error message: Error in cor(RETS) : 'x' must be numeric. Here is what i have…
Jason
  • 311
  • 1
  • 4
  • 14
11
votes
2 answers

R obtaining rownames date using quantmod

Using quantmod and collecting data from Yahoo. I am trying to get the dates that are in rownames. However I am just getting NULL. library("quantmod") sp500 <- new.env() getSymbols("^GSPC", env = sp500, src = "yahoo", from =…
adam.888
  • 7,686
  • 17
  • 70
  • 105
11
votes
4 answers

Fastest way of finding matching rows

I am wondering what is the fastest way of finding all rows in xts object that are the same as one particular row library(xts) nRows <- 3 coreData <- data.frame(a=rnorm(nRows), b=rnorm(nRows), c=rnorm(nRows)) testXts1 <- xts(coreData,…
Samo
  • 2,065
  • 20
  • 41
11
votes
2 answers

Extracting the numerical values of a xts object

I want to extract the numerical values of a xts object. Let's look at an example data <- new.env() starting.date <- as.Date("2006-01-01") nlookback <- 20 getSymbols("UBS", env = data, src = "yahoo", from = starting.date) Reg.curve <-…
math
  • 1,868
  • 4
  • 26
  • 60
11
votes
1 answer

Check if a variable is xts or data.frame

Well the question says it all..I want to check in one of my functions if a function parameter given is of xts or data frame type. How can I do this?
MichiZH
  • 5,587
  • 12
  • 41
  • 81
11
votes
2 answers

adding 1 month to a date

I want to get the date sequence between a startDate and endDate by adding 1 month to the startDate. ie, if startDate is 2013-01-31 and endDate is 2013-07-31, I would prefer to see dates like this: "2013-01-31" "2013-02-28" "2013-03-31" "2013-04-30"…
Dinoop Nair
  • 2,663
  • 6
  • 31
  • 51
11
votes
1 answer

Why do I get different results using ccf() and cor() in R?

Why do I get different correlation results between cor() and ccf()? library(xts) > set.seed(123) > ts1 = xts(1:100, as.POSIXlt(1366039619, tz="", origin="1970-01-01") + rnorm(100, 0, 3)) > ts2 = xts(1:100, as.POSIXlt(1366039619, tz="",…
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91
11
votes
1 answer

Faster Way of Calculating Rolling Realized Volatility in R

I want to calculate the rolling 20 day realized volatility for a collection of indices. Here is the code I use to download the index prices, calculate the daily returns and the 20 day realized…
mchangun
  • 9,814
  • 18
  • 71
  • 101
11
votes
3 answers

merging a large list of xts objects

I have a list of xts objects that are mutually exclusive days. I would like to merge the list into one large xts object. My attempt at doing this was to" merged_reg_1_min_prices <- do.call(cbind, reg_1_min_prices) However this seems to run out of…
Alex
  • 19,533
  • 37
  • 126
  • 195