xts

Extend a weekly times series into daily

霸气de小男生 提交于 2019-12-07 04:20:54
问题 I have an xts time series of weekly values Jan 4 2004, 0.99 Jan 11 2004, 1.11 Jan 18 2004, 1.06 .... and I want to covert it to daily values Jan 4 2004, 0.99 Jan 5 2004, 0.99 Jan 6 2004, 0.99 .... Jan 10 2004, 0.99 Jan 11 2004, 1.11 Jan 12 2004, 1.11 Jan 13 2004, 1.11 .... where each value is replicated for the following 6 days. How can I do this in R? 回答1: The data you show are not an xts series. I assume that is how the data are represented in a CSV file. To answer your question, I'm going

using data.table to speed up rollapply

时光总嘲笑我的痴心妄想 提交于 2019-12-07 03:46:04
问题 I am new to data.tables so apologies if this is a very basic question. I have heard that data.tables significantly improves computational times when working with large amounts data, and so would like to see if data.table is able to help in speeding up the rollapply function. if we have some univariate data xts.obj <- xts(rnorm(1e6), order.by=as.POSIXct(Sys.time()-1e6:1), tz="GMT") colnames(xts.obj) <- "rtns" a simple rolling quantile with width of 100 and a p of 0.75 takes a surprisingly long

R - converting dataframe to xts adds quotations (in xts)

人盡茶涼 提交于 2019-12-06 12:26:56
问题 I am using a dataframe to create an xts. The xts gets created but all values (except the index in the xts) are within quotation. This leads that I cannot use the data, since many functions such as sum, does not work. Any ideas how I can get an xts produced without the quotations? Here is my code [updated due to comment of inconsisty names of dataframes/xts]: # creates a dataframe with dates and currency mydf3 <- data.frame(date = c("2013-12-10", "2015-04-01", "2016-01-03"), plus = c(4, 3, 2),

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

假如想象 提交于 2019-12-06 12:02:17
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. 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, one way to accomplish what you want is to use the which.i argument to [.xts to find the integer indices.

xts's hourly endpoints and daylight savings

倖福魔咒の 提交于 2019-12-06 11:10:42
问题 I have an irregular time series and am using xts's endpoints to get hourly indices of my time series. endpoints(data, on="hours") I am using this in order to calculate hourly in such fashion period.apply(data, INDEX=endpoints(data, on="hours"), FUN=mean) The problem, however, is that function endpoints returns two consecutive indices (thus for the same hour). > endpoints(data, on="hours")[7201:7220] [1] 87077 87078 87089 87101 87113 87125 87137 87149 87162 87175 87187 87199 87211 87223 87235

Merge new row into an existing xts ( purpose: to add current stock quote to historical object from quantmod)

泪湿孤枕 提交于 2019-12-06 10:40:22
问题 What I like to do is to get and attach current stock price to an historical xts object. example, require(quantmod) x=getSymbols("AAPL", from = "2014-10-27" ,auto.assign=FALSE) q = getQuote('AAPL') # this produces, > tail(x) AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted 2015-05-06 126.56 126.75 123.36 125.01 72141000 124.49 2015-05-07 124.77 126.08 124.02 125.26 43940900 125.26 2015-05-08 126.68 127.62 126.11 127.62 55550400 127.62 2015-05-11 127.39 127.56 125.63 126.32

XTS: split FX intraday bar data by trading days

橙三吉。 提交于 2019-12-06 09:07:44
问题 I want to apply a function to 20 trading days worth of hourly FX data (as one example amongst many). I started off with rollapply(data,width=20*24,FUN=FUN,by=24) . That seemed to be working well, I could even assert I always got 480 bars passed in... until I realized that wasn't what I wanted. The start and end time of those 480 bars was drifting over the years, due to changes in daylight savings, and market holidays. So, what I want is a function that treats a day as from 22:00 to 22:00 of

How can i convert a dataframe with a factor column to a xts object?

怎甘沉沦 提交于 2019-12-06 08:58:36
I have a csv file and when i use this command SOLK<-read.table('Book1.csv',header=TRUE,sep=';') I get this output > SOLK Time Close Volume 1 10:27:03,6 0,99 1000 2 10:32:58,4 0,98 100 3 10:34:16,9 0,98 600 4 10:35:46,0 0,97 500 5 10:35:50,6 0,96 50 6 10:35:50,6 0,96 1000 7 10:36:10,3 0,95 40 8 10:36:10,3 0,95 100 9 10:36:10,4 0,95 500 10 10:36:10,4 0,95 100 . . . . . . . . . . . . 285 17:09:44,0 0,96 404 Here is the result of dput(SOLK[1:10,]) : > dput(SOLK[1:10,]) structure(list(Time = structure(c(1L, 2L, 3L, 4L, 5L, 5L, 6L, 6L, 7L, 7L), .Label = c("10:27:03,6", "10:32:58,4", "10:34:16,9",

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

放肆的年华 提交于 2019-12-06 08:32:58
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 0 0 01.03.93 0 0 1 0 0 04.03.93 0 1 0 0 -1 05.03.93 0 0 0 0 0 11.03.93 0 0 0 1 0 12.03.93 0 0 1 0 0 I

R xts object subseting xts object with multiple days of intraday data for certain hours

♀尐吖头ヾ 提交于 2019-12-06 06:59:45
问题 Is there a way in xts object to do the same as below but for xts object with multiple days of intraday data? The below works like a clock but for one day of data. If I pass xts from 22nd to 26th it does not. It seems like subseting intraday data in xts across multiple days is not possible to be done in one go but rather need to first split data per each day and then use this xts functionality. Is this correct? indexTZ(tdata) = "GMT" plotdata= tdata['20110822 10:00:00/20110822 12:00:00'] >