xts

subset list of xts objects

南楼画角 提交于 2019-12-08 08:28:14
问题 There's a great post on here that has clear examples of subsetting an xts object: Return data subset time frames within another timeframes? However, I have list of xts objects and I am looking to subset each component of this list by gathering all the observations from a specified date onward. So, something like this, but for each xts object in the list: my_xts["2011/"] Thank you for all your help! 回答1: You can use lapply to loop over all the elements in your list, and use an anonymous

How to use apply.daily/period.apply for calculating maximum per column in XTS time series?

北城以北 提交于 2019-12-08 05:57:51
问题 I have a problem using the period.apply function for my case of a high resolution time series analysis. I want to calculate statistics(Mean for different Periods, Stddev etc.) for my data which is in 10 min intervals. To calculate hourly means worked fine like described in this answer. It creates a new xts object with means calculated for each column. How do I calculate maximum values for each column? This reproducible example describes the structure of my data: library(xts) start <- as

Rolling list over unequal times in XTS

Deadly 提交于 2019-12-08 02:51:58
问题 I have stock data at the tick level and would like to create a rolling list of all ticks for the previous 10 seconds. The code below works, but takes a very long time for large amounts of data. I'd like to vectorize this process or otherwise make it faster, but I'm not coming up with anything. Any suggestions or nudges in the right direction would be appreciated. library(quantmod) set.seed(150) # Create five minutes of xts example data at .1 second intervals mins <- 5 ticks <- mins * 60 * 10

How to subset xts object based upon [is not] condition

佐手、 提交于 2019-12-08 00:23:47
问题 I have a xts object, now I would like to select all index rows except for a certain period. I understand that specifying my.object["2015/2015-03-01"] would select the index rows from 2015 to March 2015. But how can I make an is not operation based upon the same xts syntax? I've tried my.object[!"2015/2015-03-01"] but it does not work. 回答1: I'm not sure why you would expect my.object[!"2015/2015-03-01"] to work. Applying a logical function to a character string doesn't make sense. Regardless,

Odd behavor with POSIXct/POSIXlt and subsecond accuracy

可紊 提交于 2019-12-07 23:31:49
问题 I am having difficulty having a sequence occur in order when using sub seconds with POSIXct. options(digits.secs=6) x <- xts(1:10, as.POSIXct("2011-01-21") + c(1:10)/1e3) Produces the following output, why aren't the times in order? [,1] 2011-01-21 00:00:00.000 1 2011-01-21 00:00:00.002 2 2011-01-21 00:00:00.003 3 2011-01-21 00:00:00.003 4 2011-01-21 00:00:00.005 5 2011-01-21 00:00:00.006 6 2011-01-21 00:00:00.006 7 2011-01-21 00:00:00.007 8 2011-01-21 00:00:00.009 9 2011-01-21 00:00:00.009

Change value of some column in xts based on other columns values with lookback

∥☆過路亽.° 提交于 2019-12-07 20:21:38
问题 I have the following xts object (representing long/short entries (column 1 and 2) and exit (columns 3 and 4) triggers with "aggregate" signal column which should be 1 (system is long), -1 (system is short) or 0 (system is flat). I can not make this work for "aggregate" signal column5... The data: LongEntrySignal ShortEntrySignal LongExitSignal ShortExitSignal Signal 18.02.93 0 0 1 0 0 19.02.93 0 0 0 1 0 22.02.93 1 0 0 0 1 23.02.93 0 0 0 0 0 24.02.93 0 0 0 0 0 25.02.93 0 0 0 0 0 26.02.93 0 0 1

Rcpp debug - fatal error: Datetime.h: No such file or directory; xtsAPI.h: No such file or directory

拜拜、爱过 提交于 2019-12-07 18:26:17
问题 I am using Rcpp to handle Datetime and xts data. However, I'm getting the error No such file or directory error at both lines 2 & 3 of the following code: #include <Rcpp.h> #include <Datetime.h> #include <xtsAPI.h> // [[Rcpp::depends(xts)] using namespace Rcpp; using namespace std; Here's the errors I'm getting: fatal error: Datetime.h: No such file or directory; fatal error: xtsAPI.h: No such file or directory; 回答1: Use #include <Rcpp/Datetime.h> instead of #include <Datetime.h> and make

xts merge odd behaviour

99封情书 提交于 2019-12-07 16:48:49
问题 I have 3 xts objects all of whose indicies are 'Date' objects: > a a 1995-01-03 1.76 1995-01-04 1.69 > b b 1995-01-03 1.67 1995-01-04 1.63 > c c 1995-01-03 1.795 1995-01-04 1.690 To verify the indices are the same: > index(a) == index(b) [1] TRUE TRUE > index(a) == index(c) [1] TRUE TRUE Now I'm seeing this odd behaviour: > merge.xts(a,b) a b 1995-01-03 NA 1.67 1995-01-03 1.76 NA 1995-01-04 NA 1.63 1995-01-04 1.69 NA While the following merge works fine: > merge.xts(a,c) a c 1995-01-03 1.76 1

matching time vectors of different length: a tricky one

心已入冬 提交于 2019-12-07 15:37:45
问题 I have two sets of measurements from different machines. They are measured over time, at slightly different intervals - e.g. one makes a measurement every 5 mins, but the other, every 3 mins. The advantage is that the one every 5 mins is computed as an average over the whole interval so the values should correspond roughly to one another. I would like to expand the vector with measurements every 5 minutes (Light) so that its values are roughly synchronous with the values in vector of

endpoints in xts using R

删除回忆录丶 提交于 2019-12-07 12:46:13
问题 I am trying to figure out how endpoints selects the times when my data is only weakly regular: that is, some observations are missing. I have 1 minute returns with some minutes missing and I am trying to convert to 5 minute intervals. How will endpoints decide which times to keep? The call I use is: endpoints(ret_1_min_xts, k=5, "minutes") My series looks like this, for example: 1986-02-04 09:32:00 1 1986-02-04 09:33:00 2 1986-02-04 09:34:00 3 1986-02-04 09:35:00 4 1986-02-04 09:36:00 5 1986