Displaying 20 results from an estimated 1000 matches similar to: "Store vectors as values in xts time-series object"
2012 Aug 05
1
R: Help xts object Subset Date by Day of the Week
I have a xts object made of daily closing prices I have acquired using
quantmod.
Here is my code:
library(xts)
library(quantmod)
library(lubridate)
# Gets SPY data
getSymbols("SPY")
# Subset Prices to just closing price
SP500 <- Cl(SPY)
# Show day of the week for each date using 2-6 for monday-friday
SP500wd <- wday(SP500)
# Add Price and days of week together
2018 Jan 18
0
Split charts with ggplot2, tidyquant
Hi Charlie,
I am comfortable to put the data in any way that works best. Here are two
possibilities: an xts and a data frame.
library(quantmod)
quantmod::getSymbols("SPY") # creates xts variable SPY
SPYxts <- SPY[,c("SPY.Close","SPY.Volume")]
SPYdf <- data.frame(Date=index(SPYxts),close=as.numeric(SPYxts$SPY.Close),
2018 Jan 19
2
Split charts with ggplot2, tidyquant
So the general strategy for getting these into separate panels in ggplot
is to have a single variable that will be your response and a factor
variable that indexes which original variable it came from. This can be
accomplished in many ways, but the way I use is with the melt() function
in the reshape2 package.
For example,
library(reshape2)
plotDF <- melt(SPYdf,
??? ??? ??? ??? ??? ???
2018 Jan 19
0
Split charts with ggplot2, tidyquant
Hi Charlie,
Thanks. This is helpful. As mentioned in my original question, I want to be
able to plot a few such charts on the same page,
say a 2 x 2 grid with such a chart for each of 4 different stocks. Using
your solution I accomplished this by making
a list pLst of your ggplots and then calling cowplot::plot_grid(
plotlist=pLst, nrow=2, ncol=2 ) That worked fine.
The one issue I have is that
2012 Aug 01
1
Time Series Have Date Show Days of the Week
I used quantmod to pull in price data from the ticker SPY. The data has
date and closing price. I would like to show the day of the week for each
closing price. Is that possible? Also, I would like to add the back into
the data frame in a new column without changing the structure of the data
set if possible.
SPY
2009-01-02 92.96
2009-01-05 92.85
2009-01-06 93.47
2012 Nov 10
2
For loop question
I have this code:
IEF <- to.monthly(IEF, indexAt="endof")
SPY <- to.monthly(SPY, indexAt="endof")
I would like to use a for loop instead of separate entries,
so the only code that needs to be modified is the list
of symbols.
symbols <- c("IEF", "SPY")
for(symbol in symbols) {
symbol <- to.monthly(symbol, indexAt="endof")
}
This
2018 Jan 20
2
Split charts with ggplot2, tidyquant
For this kind of control you will probably need to move to base graphics
and utilize the `fig` argument in par(), in which case you would want to
run the plot() command twice: once with your first outcome and once with
your second, changing the par() settings before each one to control the
size.
On 01/19/2018 01:39 PM, Eric Berger wrote:
> Hi Charlie,
> Thanks. This is helpful. As
2018 Jan 20
0
Split charts with ggplot2, tidyquant
That (the need for base graphics) is false. It certainly **can** be done in
base graphics -- see ?layout for a perhaps more straightforward way to do
it along the lines you suggest.
However both lattice and ggplot are based on grid graphics, which has a
similar but slightly more flexible ?grid.layout function which would allow
one to size and place subsequent ggplot or lattice graphs in an
2011 Jan 04
1
XTS : merge.xts seems to have problem with character vectors
Hi,
Please can you tell me what I am doing wrong. When trying to merge two xts
objects, one of which has multiple character vectors for columns...I am just
getting NAs.
> str(t)
POSIXct[1:1], format: "2011-01-04 11:45:37"
> y2 = xts(matrix(c(letters[1:10]),5), order.by=as.POSIXct(c(t + 1:5)))
> names(y2) = c(1,2)
> y2
1 2
2011-01-04 11:45:38
2018 Jan 21
1
Split charts with ggplot2, tidyquant
Thanks for the reminder about lattice! I did some searching and there's
a good example of manipulating the size of subplots using the `position`
argument (see pp. 202-203 in the Trellis Users Guide:
http://ml.stat.purdue.edu/stat695t/writings/Trellis.User.pdf). This is
not within the paneling environment with the headers like in other
trellis plots though, so you'll have to do a bit
2009 Nov 16
0
OCaml-R and xts works!
Hi.
I've managed to make a *very* simple wrapper around the xts library for
R into OCaml. (Need to be downloaded from CRAN for OCaml users, but I
expect other wrapping to be fairly similar...). The good, good, good
thing (from my humble point of view) is that all loading is done
statically: Loading the R interpreter is done statically. Loading the
xts library is done statically... etc...
2010 Aug 17
0
Merge xts
Hi all ,
I have 12 xts objects of differing timeseries stamp. For example :
> str(s1_predict.xts)
An ?xts? object from 1990-03-25 20:00:00 to 1990-12-15 09:00:00 containing:
Data: num [1:725, 1] 11.23 10.18 9.3 9.74 10.18 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : NULL
Indexed by objects of class: [POSIXt,POSIXct] TZ:
Original class: 'double'
xts
2011 Nov 09
1
Are there equivalents to xblocks or rect that can be used with plot.xts?
I would like to add vertical shaded blocks in plot.xts graphs (like recession
periods in FRED graphs)
The reason I use plot.xts instead of plot.zoo is that I like the fact that
the grid is automatically aligned with major ticks in plot.xts.
xblocks() and rect() do not seem to work with plot.xts (only with plot.zoo).
Are there any alternative methods that work with plot.xts?
Thanks.
--
View
2010 Dec 06
1
as.xts error
Dear all,
I am using the as.xts function to transfer a data frame to the xts
The following is the code and result:
a<-read.csv("price.csv")
a$Date<-as.POSIXct(a$Date)
str(a)
'data.frame': 15637 obs. of 2 variables:
$ Date : POSIXct, format: "2010-01-04 09:45:01" "2010-01-04 09:45:02"
"2010-01-04 09:45:03" ...
$ bid_hsi: int 21850
2011 Dec 24
1
Optimising timeboxing in xts
I don't know if timeboxing is the correct term to use to accomplish
what I'm attempting, so allow me to explain. I have a set n of tagged
observations in time series t. What I'm interested in is taking i
seconds before and after every n. My code is below:
# observations.xts is an xts time series and arg is the number of
seconds to for the timebox
timeboxes <-
2012 Jan 15
1
problem with table.CAPM in PerformanceAnalytics
All,
I'm attempting to run this:
table.CAPM(series[,"Strat.Return",drop=FALSE],series[,"spy.Return",drop=FALSE])
and getting this error
Error in as.vector(data[, i]) : subscript out of bounds
I've searched around and cannot find a solution to the problem. I've used this in the past without problem and I'm not sure what I did different this time.
Other
2011 Oct 08
1
Filling missing days in xts time series
Hi,
I have a bunch of irregularly spaced xts time series (with a POSIX index),
and I'm trying to write a function that fillls the missing days. Using a
solution suggested by Gabor Grothendieck for zoo, I wrote the following:
# FD: Fill missing days
FD<-function(ser) {rng<-range(time(ser))
> temp<-merge(ser,xts(,seq(rng[1],rng[2],"day")))
>
2013 May 13
1
Math problem with xts objects
Hello,
I coming across a strange problem doing math on an xts object.
If I have an xts object of stock prices (perhaps 5 minute bars of open, high, low,close) and want to do some math, the results fail.
For example:
d$close[10] - d$open[10] works perfectly
d$close[10] - d$open[9] fails. I just get an answer of "numeric(0) Index: numeric(0)".
My guess is that xts is breaking
2011 Mar 07
1
Associating the day of week to a daily xts object
I have the following xts objetct "temp"
> str(temp)
An ?xts? object from 2010-12-26 to 2011-03-05 containing:
Data: num [1:70, 1] 2.95 0.852 -0.139 1.347 2.485 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr "t_n"
Indexed by objects of class: [POSIXct,POSIXt] TZ: GMT
xts Attributes:
NULL
> temp
t_n
2010-12-26
2017 Oct 06
2
Time series: xts/zoo object at annual (yearly) frequency
Hi,
I'd like to make a time series at an annual frequency.
> a<-xts(x=c(2,4,5), order.by=c("1991","1992","1993"))
Error in xts(x = c(2, 4, 5), order.by = c("1991", "1992", "1993")) :
order.by requires an appropriate time-based object
> a<-xts(x=c(2,4,5), order.by=1991:1993)
Error in xts(x = c(2, 4, 5), order.by =