[R-SIG-Finance] Fwd: AW: quantmod addTA() How to scale the y axis

Brian Peterson brian at braverock.com
Sat Nov 28 14:36:08 CET 2009


To the list.  Konrad, thank you for constructing an example.  
I am not currently at a machine with R installed, but I will take a look if no one beats me to your problem.

  - Brian
-------- Original Message --------
Subject: AW: [R-SIG-Finance] quantmod addTA() How to scale the y axis
From: "Konrad Hoppe" <konradhoppe at hotmail.de>
To: "'Brian G. Peterson'" <brian at braverock.com>
CC: 

Okay, I'm sorry. Now I've constructed an example. I would be very glad if
you can help me:

#--------------------------------------------------------#
install.packages("quantmod")
library(quantmod)

#use for example the 200-days average implemented by:

average <- function(thisVector,grad){
	res <- vector(length=length(thisVector))
	for(i in grad:length(res)){
		res[i] <- mean(thisVector[(i-(grad-1)):i], na.rm=T)
	}
	for(i in 1:(grad-1)){
		res[i] <- NA
	}
	return(as.numeric(res))
}

#construct the chartSeries plot and get the data:

from.dat <- as.Date("01/01/03", format="%m/%d/%y")
to.dat <- as.Date(Sys.Date(), format="%m/%d/%y")
getSymbols("BOS3.DE", src="yahoo", from = from.dat, to = to.dat)

chartSeries(BOS3.DE,theme="white",TA=NULL, yrange=c(5,50))
addTA(average(Ad(BOS3.DE),200), on=1,yrange=c(5,50))

# check the correctness of plot by the difference:
addTA(average(Ad(BOS3.DE),200)-Ad(BOS3.DE))

# but that looks quite different compared to:

boss <- as.vector(Ad(BOS3.DE))
plot(boss, type="l" , ylim=c(0,50))
par(new=T)
plot(average(boss,200) , type="l" , ylim=c(0,50),ylab="")
#-------------------------------------------------------------#

Thanks in advance.

Regards
Konrad


-----Ursprüngliche Nachricht-----
Von: Brian G. Peterson [mailto:brian at braverock.com] 
Gesendet: Samstag, 28. November 2009 00:29
An: Konrad Hoppe
Cc: r-sig-finance at stat.math.ethz.ch
Betreff: Re: [R-SIG-Finance] quantmod addTA() How to scale the y axis

Konrad Hoppe wrote:
> Dear mailinglist members,
>
>  
>
> I'm new to the quantmod package and I got some trouble with the addTA()
> method. 
>
> I want to add some indicators in the plot on position 1, hence behind the
> original data. But the indicators are plotted to low, they don't have any
> intersections with the raw-data. 
>
> When I plot both lines with the standard plot function there are some
> intersections and also when I plot the difference between those two series
> on position 0, there are some intersections with the null-line. Hence I'm
> sure that the plot methods got the right data. 
>
> I've already tried the solution with setting the yrange (setting it for
all
> plots to the same range), but that doesn't work.
>
> Does anybody have an idea?
>   
Yes, I have an idea.

Please construct a reproducible example, and provide your code.  It is 
nearly impossible to "have an idea" when you've described things in 
broad generalities.  If you take the time to construct an example of 
what you're talking about (disguise your data,create fake data, rename 
your indicators, whatever), then I'm almost certain someone here can 
help you.


--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock


More information about the R-SIG-Finance mailing list