xts

Plot value over hour of day with xts/zoo R

余生颓废 提交于 2020-01-01 15:35:10
问题 I do have a time-series looking like this (minute values): "timestamp", value "2012-04-09 05:03:00",2 "2012-04-09 05:04:00",4 "2012-04-09 05:05:00",5 "2012-04-09 05:06:00",0 "2012-04-09 05:07:00",0 "2012-04-09 05:08:00",3 "2012-04-09 05:09:00",0 "2012-04-09 05:10:00",1 Is there an easy way to plot these values over the hour of the day: X-Axis from 1 to 24 hours (or 0 and 23). So - all values between 5:00 and 5:59 over the 5th hour etc. It doesn't depend wich date, I am just interested in the

R Generating a 1 min spaced time sequence

匆匆过客 提交于 2020-01-01 14:33:54
问题 I would like to generate a 1 min spaced time sequence to paste then to a xts object. Basically, I've got a tick-by-tick dateTime object like that : [1] "2010-02-02 08:00:03 CET" "2010-02-02 08:00:04 CET" "2010-02-02 08:00:04 CET" "2010-02-02 08:00:04 CET" "2010-02-02 08:00:04 CET" [6] "2010-02-02 08:00:04 CET" "2010-02-02 08:00:04 CET" "2010-02-02 08:00:05 CET" "2010-02-02 08:00:05 CET" "2010-02-02 08:00:05 CET" I'm aggregating my xts series (by previous tick) to get a 1 min (equally)-spaced

Calculate cumulatve growth/drawdown from local min/max

痞子三分冷 提交于 2020-01-01 05:51:17
问题 I'm learning R (and its application to trading tasks via quantmod lib) and looking through the community pretty regularly to get a lot of new knowledge and tricks from here. My impression about R in general and quantmod lib in particular - it's awesome. At this point I need help of seasoned R users. I'm using timeseries downloaded via getSymbols and I need to calculate cumulative growth/drawdown from local minimum/maximum respectively. I can solve my task using FOR cycles as well as I can do

Longer object length is not a multiple of shorter object length? [duplicate]

99封情书 提交于 2020-01-01 04:28:21
问题 This question already has answers here : Why do I get “warning longer object length is not a multiple of shorter object length”? (4 answers) Closed 3 years ago . I don't understand why R gives me a warning about "Longer object length is not a multiple of shorter object length" I have this object which is generated by doing an aggregate over an xts series giving the weekday median: u <- aggregate(d, list(Ukedag = format(index(d),"%w")), median) 1 314.0 2 282.5 3 270.0 4 267.0 5 240.5 Then I

How do I match data frames by time intervals?

こ雲淡風輕ζ 提交于 2020-01-01 03:33:06
问题 This is a problem that comes up often when I am importing raw data from data loggers. A temperature logger is set to record temperature every ten minutes, and a separate gas logger is set to record gas used in the last ten minute interval. I want to combine the data from these two loggers into a single data frame for plotting and analysis, but the times are not exactly aligned. I want to have one row in the data frame for each ten minute period, with the datetime showing the beginning of the

XTS time subselect across DST date Linux vs Windows

不问归期 提交于 2019-12-31 04:52:30
问题 On Windows the following subselect code produces an incorrect XTS object, but works correctly on my Ubuntu machine library(xts) theTimes <- seq(from=as.POSIXct('2016-03-10 12:00:00 CDT'), to=as.POSIXct('2016-03-20 12:10:00 CDT'),by=60) ExampleData <- xts(rep(1,length(theTimes)),theTimes) CutExampleData <- ExampleData['T02:00/T16:00'] any(duplicated(index(CutExampleData))) ## Evaluates to TRUE on windows (incorrect) and FALSE on Ubuntu (correctly) SessionInfo on Linux PC: R version 3.3.1 (2016

Using rollapply function for VaR calculation using R

僤鯓⒐⒋嵵緔 提交于 2019-12-31 02:34:09
问题 I did the following for calculating Value at Risk (VaR) over 20 period rolling window: require(PerformanceAnalytics); require(zoo) data(edhec) class(edhec) # [1] "xts" "zoo" class(edhec$CTAGlobal) # "NULL" var1<-rollapply(edhec,width=20,FUN=function(edhec) VaR(R=edhec,p=.95,method="modified"),by.column=TRUE) It produces the desired output, and then I tried the same on another data: data(managers) class(managers) # [1] "xts" "zoo" class(managers$HAM4) # [1] "xts" "zoo" var2<-rollapply(managers

How to overcome error:“attempt to set 'colnames' on an object with less than two dimension” in xts object

江枫思渺然 提交于 2019-12-30 11:55:08
问题 I would like to add an open price as a new row at the end of a "SPY" data frame that was produce using the quantmod package, I used the following code in order to rbind the new row but I got an error # rm(list = ls()) # generally considered as bad manner in an MWE require(quantmod) options(scipen=999) spy <- getSymbols(("SPY") , src = 'yahoo', from = '2016-01-01', auto.assign = T) spy<-cbind(SPY) tail(SPY) SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted 2016-01-14 189.55 193.26

Change NAs to interpolated flat bars

强颜欢笑 提交于 2019-12-30 11:00:10
问题 If I have some OHLC data, with some NA rows, is there already a function in one of the R packages that will interpolate data? na.locf has two cons: It is flat, then a sudden jump Used naively, it will repeat the whole of the last bar, with its high/lows UPDATE: na.approx is superior to na.locf in the first respect, thanks Dirk, but I'm still searching for an existing function that is bar-aware . I.e. that will interpolate from the close of previous bar to the open of the next non-NA bar, and

rolling computations in xts by month

我与影子孤独终老i 提交于 2019-12-30 10:50:54
问题 I am familiar with the zoo function rollapply which allows you to do rolling computations on zoo or xts objects and you can specify the rolling increment via the by parameter. I am specifically interested in applying a function every month but using all of the past daily data in the computation. For example say my data set looks like this: dte, val 1/01/2001, 10 1/02/2001, 11 ... 1/31/2001, 2 2/01/2001, 54 2/02/2001, 34 ... 2/30/2001, 29 I would like to select the end of each month and apply