[R-SIG-Finance] date to index
Gordon Erlebacher
gordon.erlebach at gmail.com
Mon Apr 30 22:34:47 CEST 2012
ok, thanks. Now I'll tell you what I am working on. I wish to enhance
Chart_Series and add_Series to add annotations to charts. For example, I,
say I have identified 20 days which have candlestick gaps, and I wish to
annotate the underlying candlestick chart. I would like to pass this array
of dates to chart_Series and place a symbol next to each of the 20
associated candles. The difficulty is that the text() function takes as its
first argument the integer index (the row number of the xts structure).
In any case, regardless of whether I am expressing myself correctly or not,
I do understand the differences between xts and data.frame, and I still
believe that there must be a way to go from date to row number when dealing
with xts objects. In the meantime, I'll implement the inefficient solution.
I am quite surprised that chart_Series (which is quite powerful, thanks)
does not have a built in annotation functionality.
I attach two images. One that I have created, and one, close to what I
would like to create. The image with the "G" is what I have done by
changing chart_Series.
Thanks for all your help and comments.
Gordon
On Mon, Apr 30, 2012 at 4:26 PM, Brian G. Peterson <brian at braverock.com>wrote:
> On Mon, 2012-04-30 at 16:15 -0400, Gordon Erlebacher wrote:
> > I would have assumed the existence of a function in R to accomplish
> > this.After all, a data frame is a list of columns, each column is a
> > vector,which is indexed. We are not dealing with hash tables.
>
> As Josh already told you, and xts object and a data.frame have *nothing*
> to do with each other.
>
> Your example first creates a data.frame of row numbers, which could be
> easily found via which()
>
> Part of the difficult here is that *usually* if you are referring to row
> numbers in an xts object, you're doing it wrong. For time series data,
> refer to the timestamp (the actual index), not to a row number. You can
> reference row numbers in xts, you just usually shouldn't.
>
>
> --
> Brian
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120430/08e99a0c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: candle_annotation.pdf
Type: application/pdf
Size: 15412 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120430/08e99a0c/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gaps_prota.pdf
Type: application/pdf
Size: 17956 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120430/08e99a0c/attachment-0001.pdf>
More information about the R-SIG-Finance
mailing list