An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110613/e6eefbf2/attachment.pl>
Converting data for use in TTR and PerformanceAnalytics
4 messages · Kenneth Rose, Brian G. Peterson, Joshua Ulrich
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110613/0cd3b7be/attachment.pl>
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
Hi Joshua and Brian Thank you for your replies. It was the "@" that messed things up. I really don't know why I used the "@" instead of the "$". I think I'm gonna work through some more examples before I start writing my own "random code" :) Thanks, Kenneth
On Mon, Jun 13, 2011 at 4:20 PM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
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