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
11
votes
3 answers

Rolling window over irregular time series

I have an irregular time series of events (posts) using xts, and I want to calculate the number of events that occur over a rolling weekly window (or biweekly, or 3 day, etc). The data looks like this: postid 2010-08-04 22:28:07 …
Eric W.
  • 814
  • 1
  • 8
  • 18
10
votes
2 answers

Applying a rolling window regression to an XTS series in R

I have an xts of 1033 daily returns points for 5 currency pairs on which I want to run a rolling window regression, but rollapply is not working for my defined function which uses lm(). Here is my data: > head(fxr) USDZAR …
Thomas Browne
  • 23,824
  • 32
  • 78
  • 121
10
votes
1 answer

Regular analysis over irregular time series

I have an irregular time series (xts in R) that I want to apply some time-windowing to. For example, given a time series like the following, I want to compute things like how many observations there are in each discrete 3-hour window, starting from…
Ken Williams
  • 22,756
  • 10
  • 85
  • 147
10
votes
2 answers

How do I merge a large list of xts objects via loop / function in R?

I have a loop that extracts ~200 individual timeseries by making calls to an API. The loop outputs the timeseries as xts objects (library(xts)) into the Global Environment with the suffix ".oc". So I have 200 xts objects of the form "ABC.oc",…
n.e.w
  • 1,128
  • 10
  • 23
10
votes
1 answer

Obtain date column from xts object

I used getSymbols to obtain stock data, and it returned something like this: > require(quantmod) > getSymbols(AAPL) > head(AAPL) AAPL.Open AAPL.High AAPL.Low AAPL.Close 2007-01-03 86.29 86.58 81.90 83.80 2007-01-04 …
NewbieDave
  • 1,199
  • 3
  • 12
  • 23
10
votes
2 answers

Linear Interpolation using dplyr

I'm trying to use the na.approx() function from the zoo library (in conjunction with xts) to interpolate missing values from repeated measures data for multiple individuals with multiple measurements. Sample data... event.date <- c("2010-05-25",…
slackline
  • 2,295
  • 4
  • 28
  • 43
10
votes
5 answers

Rolling Sum by Another Variable in R

I want to get the rolling 7-day sum by ID. Suppose my data looks like…
jgreenb1
  • 153
  • 1
  • 6
10
votes
4 answers

Write xts/zoo object to csv with index

> library(PerformanceAnalytics) > data(managers) > class(managers) [1] "xts" "zoo" > head(managers) HAM1 HAM2 HAM3 HAM4 HAM5 HAM6 EDHEC LS EQ SP500 TR US 10Y TR US 3m TR 1996-01-31 0.0074 NA 0.0349 0.0222 NA NA …
zsljulius
  • 3,813
  • 8
  • 36
  • 61
9
votes
2 answers

Cumulative look-back rolling join

I have two data tables. I want to do a rolling join but of a "cummulative kind". For example, here are two tables d1 <- data.table(starttime = c("2011-01-01 15:29:50", "2011-01-01 15:30:03", "2011-01-01 15:40:20", "2011-01-01 15:50:20"…
user2961712
  • 469
  • 1
  • 7
  • 17
9
votes
1 answer

How can I alter a time series (XTS or ZOO) in R?

I am new to stackoverflow and fairly new to R but have searched long and hard and cannot find an answer to the following question. I have a number of data files that are temperature against a time series. I am importing the CSV as a ZOO object then…
phrozenpenguin
  • 677
  • 2
  • 7
  • 7
9
votes
4 answers

Obtaining last Friday's date

I can get today's date: Sys.Date( ) But how do I get last Friday's date? I tried: library(xts) date1 <- Sys.Date( ) to.weekly(date1 ) But this gives an error.
adam.888
  • 7,686
  • 17
  • 70
  • 105
9
votes
3 answers

Using rollmean when there are missing values (NA)

I have a data set which has a couple of NA in it. I take a rolling mean and expect that when there is no NA in the window, the rolling mean should produce a number as opposed to NA, however, rollmeanr in zoo does not seem to do this.…
Alex
  • 19,533
  • 37
  • 126
  • 195
9
votes
1 answer

Is there a work around for slow performance of do.call(cbind.xts,...) in R 2.15.2?

I would expect cbind.xts and do.call(cbind.xts) to perform with similar elapsed time. That was true for R2.11, R2.14. For R2.15.2 and xts 0.8-8, the do.call(cbind.xts,...) variant performs drastically slower, which effectively breaks my previous…
Petr Matousu
  • 3,120
  • 1
  • 20
  • 32
9
votes
1 answer

Pull Return from first business day of the month from XTS object using R

I am very new to R so apologies if I get any of the terminology wrong when I explain this problem. I have a set of daily returns data in a csv file that I have managed to convert to an xts object. The data is in the format: …
GreenyMcDuff
  • 3,292
  • 7
  • 34
  • 66
8
votes
1 answer

na.locf but don't do trailing NAs

I have the following time series > y<- xts(1:10, Sys.Date()+1:10) > y[c(1,2,5,9,10)] <- NA > y [,1] 2011-09-04 NA 2011-09-05 NA 2011-09-06 3 2011-09-07 4 2011-09-08 NA 2011-09-09 6 2011-09-10 7 2011-09-11 8 2011-09-12…
R novice
  • 83
  • 3