Skip to content
Prev 5242 / 15274 Next

AW: quantmod addTA() How to scale the y axis

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:
all
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