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
1
vote
2 answers

How to sum each row in a .xts object, where values are NOT missing

I currently have a line of code set up to sum each row/date of a xts object, where value for each data point = 1: universe.rt=sapply(X=2:nrow(rt),FUN=function(x){sum(rt[x,which(live[x,]==1)])/count[x]}) I want to change the code such that…
Malik
  • 71
  • 1
  • 9
1
vote
1 answer

Extrapolating time series based on non-constant percent changes

I'm trying to do a variant of the following: Calculate the percent change per time period of a time series and then apply those percent changes to a separate time series. It's like applying AAPL's daily price changes to the current price of some…
Trent Baur
  • 95
  • 1
  • 9
1
vote
1 answer

I cannot get xts to recognize Time Series in rownames

I am having a problem with the xts package. I am trying to create an xts from a dataframe. For simplicity sake, I tried to replicate what I am trying to do on a small df below: > df <- japanTOPIX[,1, drop = FALSE] > typeof(df[,1]) [1] "double" >…
lukehawk
  • 1,423
  • 3
  • 22
  • 48
1
vote
1 answer

How to speedup the xts data conversion to DatatimeVector in Rcpp?

I am using Rcpp for analysis of XTS data and get its time index by using the following rcpp code: #include using namespace Rcpp; using namespace std; // [[Rcpp::export]] DatetimeVector xtsIndex(NumericMatrix X) { DatetimeVector…
Alvin
  • 351
  • 3
  • 13
1
vote
1 answer

R xts object - subset data points for 5 consecutive seconds

I have a large xts object and want to subset the seconds in the time column, but only if there is a sequence of minimum 5 consecutive seconds. I have up to 8 data points per second (which shouldn't be counted as 5 consecutive points as they are…
Pat
  • 217
  • 1
  • 6
1
vote
1 answer

Efficient replace of nan/na values in xts object

I have an object that has 20k columns. I want to replace all occurence of NaN, NA, and say a specific value with 0. How do i do that: Subset of data: AAC-200004 AACB-200708 AACE-200610 BVX BWL.A BZC BZM CAK CANF CAW CCA CCF CEF…
user1234440
  • 22,521
  • 18
  • 61
  • 103
1
vote
1 answer

Exponentiation with a negative base in R not consistent

I am trying to annualize negative returns, and running into an issue. I have an xts series, and I am using the following code: x = rebalReturns[,"LBND/SBND (PS DB 25+ Year T-Bond)"] round((tail(cumprod(na.omit(x) + 1) - 1,1)),…
lukehawk
  • 1,423
  • 3
  • 22
  • 48
1
vote
1 answer

Repeated date in R timeBasedSeq

Why does this timeBasedSeq result in repeated 31st of October? > d <- timeBasedSeq("2010-05-24/2010-11-04/d") > d[158:164] [1] "2010-10-28" "2010-10-29" "2010-10-30" "2010-10-31" [5] "2010-10-31" "2010-11-01" "2010-11-02" Using Package xts…
mark
  • 537
  • 6
  • 25
1
vote
1 answer

How do I aggregate and sum irregular time-series data based on a desired regular time interval in R?

I have rainfall data at very irregular intervals. Every time it records 0.01 inches of rain, the data logger records the time down to seconds. A few data points look like this: datetime <- as.POSIXct(as.character(c("2/5/15 16:28:38", "2/5/15…
AndMan21
  • 533
  • 1
  • 4
  • 15
1
vote
1 answer

R: using stl() on an xts object

I'm relatively new to R so please bear with me. I'm trying to get to grips with basic irregular time-series analysis. That's what my data file looks like, some 40k lines. The spacing is not always exactly 20sec. Time, Avg 04/03/2015…
moodywoody
  • 2,149
  • 1
  • 17
  • 21
1
vote
1 answer

frequency() and cycle() of a monthly xts object returns value "1"

I have a monthly xts object, and the function frequency() returns a value of 1, however I would expect 12. The function cycle() also does not return month numbers, but instead a value of 1 for each observation. library('quantmod') getSymbols("GS10",…
HRC
  • 107
  • 7
1
vote
1 answer

Adjusting for Stock Splits in R Error?

I have an intraday dataset with closing prices that I want to adjust stock prices for stock splits. I have found the adjustOHLC() from the quantmod package to work almost effectively. Here is one of the many UNADJUSTED tickers in my dataset called:…
Rime
  • 912
  • 2
  • 11
  • 39
1
vote
1 answer

Excluding hours and days in xts

I have an xts object with NA data from 1.1.2007 to 5.6.2014 with minute intervals. I need to exclude between friday 17:00 and sunday 17:00. I am aware of the tricks like ['T17:00:00/T17:00:00'] to subset but how do you work the day of week condition…
1
vote
1 answer

R // QuantStrat package - hasTsp(x): invalid time series parameters specified Error

I'm trying to use historical chart data in .csv format for simple backtesting with the quantstrat package in R. I've tried to use different sources - daily OHLC charts, tick data etc. , but I always get this error: hasTsp(x): invalid time series…
Monocloud
  • 41
  • 7
1
vote
1 answer

How to select columns name and its value when greater than 0 in R?

I have an xts object that contain several columns with one numeric values per row and I need to select the name and the value of columns where value is greater than 0 for the day n-1. Object1 <- colnames(xxx)[apply(xxx[Sys.Date()-1],1,which.max)] I…
Florent
  • 1,791
  • 22
  • 40