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

Joshua Ulrich josh.m.ulrich at gmail.com
Sat Nov 28 15:27:49 CET 2009


Konrad,

There are no intersections because chartSeries() plots the unadjusted
data and you're overlaying an average of the split and dividend
adjusted series.  You need to adjust the raw data before charting.

BOS3.DE <- adjustOHLC(BOS3.DE)
chartSeries(BOS3.DE,theme="white",TA="addSMA(200)", yrange=c(5,50))

Note that "addSMA" replicates your "addTA(average(...))" call by using
the SMA function from TTR.

HTH,
Josh
--
http://www.fosstrading.com



On Sat, Nov 28, 2009 at 7:33 AM, Konrad Hoppe <konradhoppe at hotmail.de> wrote:
> 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.
>
> Regards,
>
>     - Brian
>
> --
> Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list