xts

Applying a rolling window regression to an XTS series in R

限于喜欢 提交于 2019-12-18 11:56:12
问题 I have an xts of 1033 daily returns points for 5 currency pairs on which I want to run a rolling window regression, but rollapply is not working for my defined function which uses lm(). Here is my data: > head(fxr) USDZAR USDEUR USDGBP USDCHF USDCAD 2007-10-18 -0.005028709 -0.0064079963 -0.003878743 -0.0099537170 -0.0006153215 2007-10-19 -0.001544470 0.0014275520 -0.001842564 0.0023058211 -0.0111410271 2007-10-22 0.010878027 0.0086642116 0.010599365 0.0051899551 0.0173792230 2007-10-23 -0

Use endpoints function to get start points instead?

自作多情 提交于 2019-12-18 05:02:48
问题 I have an xts object called Daily_Quotes that contains stock quotes. I'm using endpoints to get monthly stock quotes that I retrieved using getSymbols (from the quantmod package). I noticed that the endpoints function creates an index of the row that contains the last trading day for the particular month and assigns it to the new object for the specified date range. Is there anyway to get first trading day of the month instead? # My code Monthly_Quotes <- Daily_Quotes[endpoints(Daily_Quotes,

Use endpoints function to get start points instead?

我怕爱的太早我们不能终老 提交于 2019-12-18 05:02:32
问题 I have an xts object called Daily_Quotes that contains stock quotes. I'm using endpoints to get monthly stock quotes that I retrieved using getSymbols (from the quantmod package). I noticed that the endpoints function creates an index of the row that contains the last trading day for the particular month and assigns it to the new object for the specified date range. Is there anyway to get first trading day of the month instead? # My code Monthly_Quotes <- Daily_Quotes[endpoints(Daily_Quotes,

can I write an xts object using write.csv in R

元气小坏坏 提交于 2019-12-18 04:05:30
问题 I have an xts object, the first column of which is date-time, followed by OHLC. when I type >test it prints the correct output as follows: 2010-09-08 15:13:00 115 115 110 115 2010-09-08 15:14:00 120 125 115 125 however, when I try write.csv(test,"test.csv") it only writes the OHLC - why. what command do I use to also write the date-time this is what str(test) looks like: An ‘xts’ object from 2010-06-30 15:47:00 to 2010-09-08 15:14:00 containing: Data: num [1:21757, 1:4] 215 220 205 195 185 ..

rowSums but keeping NA values

末鹿安然 提交于 2019-12-17 20:50:18
问题 I am pretty sure this is quite simple, but seem to have got stuck...I have two xts vectors that have been merged together, which contain numeric values and NAs. I would like to get the rowSums for each index period, but keeping the NA values. Below is a reproducible example set.seed(120) dd <- xts(rnorm(100),Sys.Date()-c(100:1)) dd1 <- ifelse(dd<(-0.5),dd*-1,NA) dd2 <- ifelse((dd^2)>0.5,dd,NA) mm <- merge(dd1,dd2) mm$m <- rowSums(mm,na.rm=TRUE) tail(mm,10) dd1 dd2 m 2013-08-02 NA NA 0.000000

R xts: .001 millisecond in index

旧街凉风 提交于 2019-12-17 20:39:38
问题 It looks like POSIXlt allows millisecond precision specification, but I have a problem when setting a .001 millisecond index value in an xts object: > options(digits.secs = 3) > data(sample_matrix) > sample.xts = xts(sample_matrix, rep(as.POSIXlt("2012-03-20 09:02:50.001"), 180)) > head(sample.xts, 10) Open High Low Close 2012-03-20 09:02:50.000 50.03978 50.11778 49.95041 50.11778 2012-03-20 09:02:50.000 50.23050 50.42188 50.23050 50.39767 2012-03-20 09:02:50.000 50.42096 50.42096 50.26414 50

xts tick data rolling subset

放肆的年华 提交于 2019-12-17 19:54:38
问题 I have created an xts object from historical tick data, sourced from a SQL database. I would like to create subsets of the tick data, for example: Show daily ticks between 10am and 2:30pm. This would allow me to create specific data sets for specific trade ideas, based on the time of day. The format of my index is as follows: > index(merged[3567,]) [1] "2011-08-01 13:17:59 SAST" Could an expert in xts please advise me how I would go about creating these subsets? Any advice would be greatly

Speedup conversion of 2 million rows of date strings to POSIX.ct

佐手、 提交于 2019-12-17 18:53:22
问题 I have a csv which includes about 2 million rows of date strings in the format: 2012/11/13 21:10:00 Lets call that csv$Date.and.Time I want to convert these dates (and their accompanying data) to xts as fast as possible I have written a script which performs the conversion just fine (see below), but it's terribly slow and I'd like to speed this up as much as possible. Here is my current methodology. Does anyone have any suggestions on how to make this faster? dt <- as.POSIXct(csv$Date.and

dplyr, lubridate : how to aggregate a dataframe by week?

你说的曾经没有我的故事 提交于 2019-12-17 10:43:09
问题 Consider the following example library(tidyverse) library(lubridate) time <- seq(from =ymd("2014-02-24"),to= ymd("2014-03-20"), by="days") set.seed(123) values <- sample(seq(from = 20, to = 50, by = 5), size = length(time), replace = TRUE) df2 <- data_frame(time, values) df2 <- df2 %>% mutate(day_of_week = wday(time, label = TRUE)) Source: local data frame [25 x 3] time values day_of_week <date> <dbl> <fctr> 1 2014-02-24 30 Mon 2 2014-02-25 45 Tues 3 2014-02-26 30 Wed 4 2014-02-27 50 Thurs 5

merging a large list of xts objects

坚强是说给别人听的谎言 提交于 2019-12-17 09:50:17
问题 I have a list of xts objects that are mutually exclusive days. I would like to merge the list into one large xts object. My attempt at doing this was to" merged_reg_1_min_prices <- do.call(cbind, reg_1_min_prices) However this seems to run out of memory. reg_1_min_prices is 6,000 days of 1 minute returns on mutually exclusive days so it's not very large. Does anyone know how to get around this? To be clear: reg_1_min_prices contains mutually exclusive days with 1 minute prices on each day and