Search code examples
rquantmodtrading

R quantmod trading signals and simulation


I would like to use R's quantmod package to test some technical indicators for trading stocks. My goal is to automatically run an indicator over a Stock Symbol and the result tells me what would have been my performance if I would have followed strictly the indicator (e.g. MACD).

The website www.quantmod.com is very interesting, however it seems that the author stopped updating it a few years ago.

What I can do so far: getting stock symbols via the package "quantmod" using the plotting functions and visually interpreting them. e.g. using the MACD one trading signal is when the two lines cross each other.

What I cannot do (but would like to do): - automatically visually indicating the signal (displaying), e.g. with an arrow or any graphical symbol in the plot - the simulation: automatically trade (buy or sell) each time the signal arrives and tells me at the end if this technical indicator is useful for the specific stock or index.

here is some basic code for the plotting:

require(quantmod)
getSymbols("IBM", source="google")
chartSeries(IBM, subset="last 10 weeks", type="candles")
addMACD()

I hope I could explain what I am looking for.

Thanks in advance


Solution

  • You may want to look at the blotter and the quantstrat packages. A.o. the chart.Posn() function there will provide you with the plot that you are looking for, and includes PL and DD curves as well.

    HTH,

    Jan Humme.