[R-SIG-Finance] addLines in Quantmod

Marc Delvaux mdelvaux at gmail.com
Thu Jul 8 00:49:27 CEST 2010


I happened to have a similar problem, so let me try to be more specific.

The following code, when run on the command line works, i.e. the
correct graph is produced including an horizontal line at the correct
position

require(quantmod)
getSymbols("AAPL")
chartSeries(AAPL, ylim=yLimits)
addLines(h=mean(AAPL[,1]))

Writing the same lines inside a .R file, say test_quantmod.R and
sourcing that file does not work, you get the graph produced by
chartSeries() without the horizontal line.  Wrapping the call to
addLines into plot() as indicated by Joshua does work, i.e. the
following code inside test_quantmod.R works correctly.  Thank Joshua
for the tip.

require(quantmod)
getSymbols("AAPL")
chartSeries(AAPL, ylim=yLimits)
plot(addLines(h=mean(AAPL[,1])))

or even more directly
require(quantmod)
getSymbols("AAPL")
chartSeries(AAPL, TA='addLines(h=mean(AAPL[,1]))')


On a side topic, I was trying to use ylim to control the scale of the
y axis, it took me a while to realize that the correct parameter is
yrange (and yes this is correctly mentioned in the documentation, I
was just not paying attention).


On Tue, Jul 6, 2010 at 5:53 PM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
> I'm assuming the lines aren't being added to the plot.  If that's the
> case, you need to wrap each call to addLines() with plot().  For
> example plot(addLines(h=130,on=1)).
>
> That said, I don't know if that's the issue you're referring to since
> you didn't actually ask a question.
> --
> Joshua Ulrich
> FOSS Trading: www.fosstrading.com
>
>
>
> On Tue, Jul 6, 2010 at 7:45 PM, Andres Petrocelli <cordura21 at gmail.com> wrote:
>> Hi, guys. I am running the following code:
>>
>> plotFunction <-function() {
>> library("quantmod")
>> getSymbols("SPY")
>> #pdf("quantModChart.pdf")
>> barChart(SPY,theme="white")
>> addLines(h=130,on=1)
>> addLines(h=100,on=1)
>> #dev.off()
>>  }
>>
>>  plotFunction()
>>
>>
>> pS: sorry if it's a double post, first time user of a mailing list. Won't do
>> it again (I hope)
>>
>>        [[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.
>> -- Also note that this is not the r-help list where general R questions should go.
>>
>
> _______________________________________________
> 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.
> -- Also note that this is not the r-help list where general R questions should go.
>



More information about the R-SIG-Finance mailing list