xts

Changes in plotting an XTS object

孤街浪徒 提交于 2019-11-28 06:01:27
问题 I had produced the following chart, which is created using an xts object. The code I used was simply plot(graphTS1$CCLL, type = "l", las = 2, ylab = "(c)\nCC for Investors", xlab = "", main = "Clustering Coefficient at the Investor Level") I updated my R Studio Package and R version and then by running the same code I got the following chart. Obviously the two are not the same. Can people help me remove the second Y axis - I do not need that, and remove the automatic heading of 2007-03-01 /

Rolling window over irregular time series

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 05:33:19
I have an irregular time series of events (posts) using xts , and I want to calculate the number of events that occur over a rolling weekly window (or biweekly, or 3 day, etc). The data looks like this: postid 2010-08-04 22:28:07 867 2010-08-04 23:31:12 891 2010-08-04 23:58:05 901 2010-08-05 08:35:50 991 2010-08-05 13:28:02 1085 2010-08-05 14:14:47 1114 2010-08-05 14:21:46 1117 2010-08-05 15:46:24 1151 2010-08-05 16:25:29 1174 2010-08-05 23:19:29 1268 2010-08-06 12:15:42 1384 2010-08-06 15:22:06 1403 2010-08-07 10:25:49 1550 2010-08-07 18:58:16 1596 2010-08-07 21:15:44 1608 which should

create an OHLC series from ticker data using R

北城余情 提交于 2019-11-28 03:51:23
问题 This seems like it should be a common thing, but all my searching comes up with half or unfinished answers. I have a set of data in a csv. But the data is set up so it is time, price, volume. To properly analyze my data I need it in OHLCV format: open, high, low, close, volume. Does anyone have an idea how to reformat into OHLCV? Here is a sample of a data set: time,price,volume, 7/18/10 0:09,0.04951,20, 7/18/10 4:43,0.05941,50.01, 7/18/10 18:48,0.0808,5, 7/18/10 22:44,0.08585,10, 7/18/10 23

Obtain date column from xts object [duplicate]

百般思念 提交于 2019-11-28 03:49:18
问题 This question already has an answer here: Access zoo or xts index 2 answers I used getSymbols to obtain stock data, and it returned something like this: > require(quantmod) > getSymbols(AAPL) > head(AAPL) AAPL.Open AAPL.High AAPL.Low AAPL.Close 2007-01-03 86.29 86.58 81.90 83.80 2007-01-04 84.05 85.95 83.82 85.66 2007-01-05 85.77 86.20 84.40 85.05 2007-01-08 85.96 86.53 85.28 85.47 2007-01-09 86.45 92.98 85.15 92.57 2007-01-10 94.75 97.80 93.45 97.00 > str(AAPL) An ‘xts’ object on 2007-01-03

Converting an XTS object to a data.frame [duplicate]

不羁岁月 提交于 2019-11-28 01:28:29
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to create a variable of rownames? Please run it in R: require(quantmod) setSymbolLookup(SDB=list(name="000001.sz",src="yahoo")) getSymbols("SDB",from="2010-01-01",to="2010-02-01") sdb=as.data.frame(weeklyReturn(SDB)) sdb What I get is: weekly.returns 2010-01-08 -0.07830343 2010-01-15 -0.05176991 2010-01-22 0.07699487 2010-01-29 -0.05979203 2010-02-01 -0.02119816 What I want to get is: date weekly.returns 1

subsetting in xts using a parameter holding dates

空扰寡人 提交于 2019-11-28 01:10:05
问题 I am familiar with the xts subsetting abilities. However, I can't find an elegant way to subset a parameterized range of dates. something like this: times = c(as.POSIXct("2012-11-03 09:45:00 IST"), as.POSIXct("2012-11-05 09:45:00 IST")) #create an xts object: xts.obj = xts(c(1,2),order.by = times) #filter with these dates: start.date = as.POSIXct("2012-11-03") end.date = as.POSIXct("2012-11-04") #instead of xts["2012-11-03"/"2012-11-04"], do something like this: xts[start.date:end.date] Does

Regular analysis over irregular time series

大憨熊 提交于 2019-11-27 21:33:12
I have an irregular time series ( xts in R ) that I want to apply some time-windowing to. For example, given a time series like the following, I want to compute things like how many observations there are in each discrete 3-hour window, starting from 2009-09-22 00:00:00 : library(lubridate) s <- xts(c("OK", "Fail", "Service", "OK", "Service", "OK"), ymd_hms(c("2009-09-22 07:43:30", "2009-10-01 03:50:30", "2009-10-01 08:45:00", "2009-10-01 09:48:15", "2009-11-11 10:30:30", "2009-11-11 11:12:45"))) I apparently can't use period.apply() or split() to do it, because those will omit periods with no

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

☆樱花仙子☆ 提交于 2019-11-27 19:53:28
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 2014-02-28 50 Fri 6 2014-03-01 20 Sat 7 2014-03-02 35 Sun 8 2014-03-03 50 Mon 9 2014-03-04 35 Tues 10

R obtaining rownames date using quantmod

為{幸葍}努か 提交于 2019-11-27 19:24:54
问题 Using quantmod and collecting data from Yahoo. I am trying to get the dates that are in rownames. However I am just getting NULL. library("quantmod") sp500 <- new.env() getSymbols("^GSPC", env = sp500, src = "yahoo", from = as.Date("2008-01-04"), to = Sys.Date()) GSPC <- get("GSPC", envir = sp500) date1 <- rownames(GSPC) date1 > NULL I would be grateful for your help into getting the rowname dates into a vector. 回答1: You need to use the index function. The xts object isn't the same as a

R: adding 1 month to a date

血红的双手。 提交于 2019-11-27 17:52:40
问题 I want to get the date sequence between a startDate and endDate by adding 1 month to the startDate . ie, if startDate is 2013-01-31 and endDate is 2013-07-31, I would prefer to see dates like this: "2013-01-31" "2013-02-28" "2013-03-31" "2013-04-30" "2013-05-31" "2013-06-30" "2013-07-31" I have tried seq.Date(as.Date("2013-01-31"),by="month",length.out=7) . But the output of this code is like this > seq.Date(as.Date("2013-01-31"),by="month",length.out=7) [1] "2013-01-31" "2013-03-03" "2013-03