[R-SIG-Finance] trying to plot coincident time series in quantmod...

Eugene Tyurin etyurin at skipstonellc.com
Thu May 14 18:35:51 CEST 2009


Jeff,

Thank you very much - addTA really does what I need. However, there's
a wrinkle - addTA somehow does not work inside a function!  Code
sample attached:

ix<-as.Date('2009-05-01')+seq(0:19)
x<-sin(1:20)
y<-cos(1:20)
dat_<-xts(cbind(x,y),order.by=ix)

# You see both lines:
lineChart(dat_$x)
addTA(dat_$y,on=1,col='red')

z <- function(a) {
	lineChart(a[,1],theme='white')
	addTA(a[,2],on=1,col='blue') # <--- this one will not be displayed
}

# You see only one line:
z(dat_)


On Thu, May 14, 2009 at 10:24 AM, Jeff Ryan <jeff.a.ryan at gmail.com> wrote:
>
> Hi Eugene,
>
> addPoints isn't very useful.  I intend on adding wrapper functions to
> the underlying base graphics functions in R, that will work with
> quantmod.  Until then 'addTA' will do almost everything you would want
> for simple additions.
>
> Both of these work:
>
> addTA(dat_[,'5x16'],type='p',col='red',pch=25,on=1)
> addTA(dat_[,'7x24'],type='p',col='red',pch=25,on=1)
>
>
> Key points:
>
> ** Don't convert dat_ from xts.  The timestamps are important.
> ** the "on" argument is where to draw.  In this case "1" is the main
> window you want.
>
> HTH
> Jeff
>
> On Thu, May 14, 2009 at 8:35 AM, Eugene Tyurin <etyurin at skipstonellc.com> wrote:
> > Hello!
> >
> > I am trying to plot more than one time series on one chart using quantmod's
> > functions. However, my ability to parse the source code is lacking...
> >
> > For the life of me I can't figure out a way to use addPoints(). Simple
> > points() function breaks down due to na.omit() in chartSeries().
> >
> > What is the "proper way" to do something like this?  I attached a simple
> > example below:
> >
> > ix<-as.Date('2009-05-01')+seq(0,6)
> > dat_<-xts(cbind(sin(1:7),sin(1:7)),order.by=ix)
> > colnames(dat_)<-c('7x24','5x16')
> > dat_[2:3,'5x16']<-NA
> >
> > # This works fine:
> > lineChart(dat_[,'7x24'])
> > points(as.vector(dat_[,'5x16']),col='red',type='p',pch=25)
> >
> > # This does not:
> > lineChart(dat_[,'5x16'])
> > points(as.vector(dat_[,'7x24']),col='red',type='p',pch=25)
> >
> > Thanks!
> > -- Eugene Tyurin.
> >
> >        [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > 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.
> >
>
>
>
> --
> Jeffrey Ryan
> jeffrey.ryan at insightalgo.com
>
> ia: insight algorithmics
> www.insightalgo.com



More information about the R-SIG-Finance mailing list