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

Select values from vector using Date as index

Suppose I have a named vector, bar: bar=c() bar["1997-10-14"]=1 bar["2001-10-14"]=2 bar["2007-10-14"]=1 How can I select from bar all values for which the index is within a specific date range? So, if I look for all values between "1995-01-01" and…
Pieter
  • 3,339
  • 5
  • 30
  • 63
1
vote
2 answers

R xts: apply over a rolling window

I wish to execute a function FUN over a rolling window of 1 year. My xts has not the same number of points per year. How can I do that in an efficient way? P.S. usually to execute a FUN over a fixed number of datapoints (for instance 100) I…
RockScience
  • 17,932
  • 26
  • 89
  • 125
1
vote
1 answer

Shiny: xts plot (xtsExtra) disappears when checkbox unchecked

I'm writing a shiny app on rmarkdown. The app supposes to plot two time series on the same chart, but the second plot is conditional on a checkbox. The problem is that when the checkbox is left unchecked, the whole chart disappears, instead of only…
Gustavo
  • 65
  • 1
  • 6
1
vote
2 answers

referencing an xts object with a matrix

I have a 207x7 xts object (called temp). I have a 207x3 matrix (called ac.topn), each row of which contains the columns I'd like from the corresponding row in the xts object. For example, given the following top two rows of temp and…
rmacey
  • 599
  • 3
  • 22
1
vote
1 answer

Split data frame into multiple data frames based on information in a xts object Part 2

Taking my first question as starting point: Split data frame into multiple data frames based on information in a xts object Now I have a new problem. Suppose you have double entries in your data.frames d1 & d2 - i.e. you have in d1 the letter "h"…
Daniel_D
  • 698
  • 1
  • 7
  • 13
1
vote
2 answers

Reduce time precision in a time series to minutes from seconds

I have financial time series data with the following date Format: "%Y-%m-%d %H:%M:%S" I am trying to reduce its time precision to minutes instead of seconds efficiently. Sample Data: dd <- c("2014-02-23","2014-03-12", "2014-05-29") tt <-…
user2004820
  • 321
  • 2
  • 11
1
vote
1 answer

Using lapply on quantmod, get straight to xts object?

I am importing some stock data from yahoo and would like to calculate the daily range as High - Low. I then want to put each stock's range in a single xts object. The below code accomplishes this but seems very convoluted to me. The problem starts…
mks212
  • 901
  • 1
  • 18
  • 40
1
vote
2 answers

Adding a vector back as an extra xts file column

This is my first time with coding - not in finances, either. Just trying to learn R. I tried to calculate differences in closing price for historical data on Google. The problem is that to apply a function (and I bet there are many functions for…
Antoni Parellada
  • 4,253
  • 6
  • 49
  • 114
1
vote
1 answer

How do I increase margins between plots in plot.xts?

I'm getting some label overlap with plot.xts. For example, see the circled area below: How do I increase the margins to avoid this? Below is a minimal reproducible example (see the original post for the entire script). I'm most interested in the…
kgibm
  • 852
  • 10
  • 22
1
vote
1 answer

Divide two xts time series in for loop maintaining xts time

I have multiple xts time series where the index() is the same for all. I would like to divide two series and insert them in an empty matrix and then apply this to other pairs and maintain the time series. I have tried various ways in the loop: such…
philippe
  • 47
  • 7
1
vote
1 answer

Using QuantMod/tseries monthlyReturn with dividend

Is there are way using Monthly Return function to factor in dividends into the monthlyReturn? I have my an xts object with price and dividend columns.
firstever
  • 49
  • 1
  • 6
1
vote
1 answer

to.period returns error attempt to set index 4/4 in SET_STRING_ELT in R

I am a newbie with R and have been following a tutorial from YouTube by Chris Reeves I am using xts with to.period to create OHLC from tick/second data. My code Last = AAPL.Last Bid = AAPL.Bid Ask = AAPL.Ask colnames(Last) =…
1
vote
2 answers

Create XTS with dates with different number of rows

Trying to create an xts file but after formatting upon loading in, I have different number of rows for dates than I do for my data. My data has many columns with varying number of rows, anywhere from 20 to 200. I want to create a separate variable…
user2662565
  • 509
  • 2
  • 9
  • 22
1
vote
1 answer

how to format a column with duplicate dates in r

I have a fairly large dataset saved in a .txt file, that i read into my environment using fread() from data.table. I would like to organize the data so that it looks like this: # Desired output: Column headers = [ Date, Company Names, RET, RETX,PRC,…
Rime
  • 912
  • 2
  • 11
  • 39
1
vote
2 answers

Load csv into R as xts, or comparable to enable time series analysis

I am still learning R, and get very confused when using various data types, classes, etc. I have run into this issue of "Dates" not being in the right format for xts countless times now, and find a solution each time after searching long and hard…
user2662565
  • 509
  • 2
  • 9
  • 22