[R-SIG-Finance] xts to timeSeries conversion

G See gsee000 at gmail.com
Sat Mar 24 14:34:01 CET 2012


You may also be interested in
library(qmao)
?makeReturnFrame

which takes the name of one or more xts objects, extracts a column
(that you can specify with the "prefer" argument; if not specified, it
will default to "Adjusted" on yahoo data) from each of them and cbinds
those columns together.  Then it calculates returns so that you're
left with an object that charts.PerformanceSummary can use.

It's much more useful when you want to chart several Symbols at once.
It makes it easy to get data, merge, calculate returns, and chart all
in one line.  (RF is an alias for makeReturnFrame, and I'll use RF in
the examples because it is more compact)

library(qmao)
library(PerformanceAnalytics)
charts.PerformanceSummary(RF(getSymbols("IBM")))

The above will give a warning unless you have defined an instrument named "IBM"
You can either silence the warning
RF(getSymbols("IBM")), silent=TRUE)

or define the stock, which you could either do separately, or in the same line:
charts.PerformanceSummary(RF(getSymbols(stock("IBM", currency("USD")))))

or, to really see the convenience of RF, get more than one stock:
charts.PerformanceSummary(RF(getSymbols(stock(c("SPY", "DIA", "QQQ"),
currency("USD")))))

HTH,
Garrett

On Sat, Mar 24, 2012 at 8:13 AM, Brian G. Peterson <brian at braverock.com> wrote:
> On Sat, 2012-03-24 at 13:01 +0000, Golam Sakline wrote:
>> How is it possible to get getSymbol object like IBM stock converted to timeSeries object so that it can be plotted in charts.PerformanceSummary() of PerformanceAnalytics in few lines of code. The problem I am having is with the Date column. Please help.
>
> PerformanceAnalytics uses xts internally for everything.  It also
> accepts timeSeries-classed objects, but they will be converted to xts
> internally.
>
> You didn't follow the posting guide and provide a reproducible example,
> so I can't tell what your problem really is, but the following works for
> me:
>
> require(quantmod)
> require(PerformanceAnalytics)
> getSymbols('IBM')
> IBM$Returns<-Return.calculate(Cl(IBM))
> charts.PerformanceSummary(IBM$Returns)
>
>
>
> --
> Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.



More information about the R-SIG-Finance mailing list