[R-SIG-Finance] Converting data for use in TTR and PerformanceAnalytics

Joshua Ulrich josh.m.ulrich at gmail.com
Mon Jun 13 16:20:29 CEST 2011


On Mon, Jun 13, 2011 at 8:55 AM, Kenneth Rose <kennethrose82 at gmail.com> wrote:
> Hi guys,
>
> I'm a complete newbie so I'm not sure if my question is stupid. But anyway,
> I can't figure it out!
>
> I'm trying to do calculate returns in "TTR" and "PerformanceAnalytics"
> (inspired by this<http://www.milktrader.net/2011/04/chop-slice-and-dice-your-returns-in-r.html>article
> from milktrader) but I get the error below whenever I run the code:
> *
>
> "Error in inherits(x, "xts") :
>  trying to get slot "Luk" from an object (class "data.frame") that is
> not an S4 object"
>
> *

It's not possible that you get this error from running the code in the
blog post you cite because it does not use the "@" operator.

> I have downloaded data from another source then to ones possible in
> PerformanceAnalytics because Yahoos dataset is incomplete. The dataset I
> have downloaded is not complete either but at least there are closing prices
> for the whole period.
>
> The dataset variables are in danish but can be translated as:
>
> Dato = Date
> Åbning = Open (or opening price)
> Høj = High
> Lav = Low
> Luk = Close (or closing price)
> Omsætning = Volume
>
>
>
> This is the code:
>
> require("quantmod")
> require("TTR")
> require("PerformanceAnalytics")
>
> danske <- read.table("
> http://www.euroinvestor.dk/HistoricalQuotes/HistoricalQuotes.aspx?lang=DA&fn=DANSKE&outputmode=5&format=csv&separator=,&lcid=2057&stockid=235240",
> sep = ",", header = TRUE)
>
> danske at logreturns <- PerformanceAnalytics::Return.calculate(danske at Luk)
> danske at ROC <- TTR::ROC(danske at Luk)
>
>

The blog post you cite doesn't use "@" to access columns, so why are
you using it?  I strongly suggest you read the manuals rather than try
random code.  It's also useful to cross-reference the "See Also"
section of the manual pages.  For example, you could have looked at:

R> help("@")  # The @ operator
R> help("data.frame")  # data.frames (See Also: [.data.frame’ for
subsetting methods)
R> help("S4")  # S4 objects

It would also be helpful to read "An Introduction to R".
Specifically, the section on lists and data.frames:
http://cran.r-project.org/doc/manuals/R-intro.html#Lists-and-data-frames

>
> I appreciate your help!
>
> Yours sincerely,
>
> Kenneth
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> 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.
>

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



More information about the R-SIG-Finance mailing list