[R-SIG-Finance] runMax and DonchianChannel()

Joshua Ulrich josh.m.ulrich at gmail.com
Thu Mar 3 05:13:46 CET 2011


Hi Andrew,

On Wed, Feb 23, 2011 at 6:32 PM, andrew morgan <minkymorgan at gmail.com> wrote:
> Hi all,
>
> can anyone point me in the right direction?
> I'm not particularly strong at R but use quantmod to do a lot of charting -
> so apologize in advance if there's a simple answer to this I've missed.
>
> I am trying to modify DonchianChannel() in TTR so that I can draw the
> channel, but not for the last n days.
> Instead, I'd like to draw it for a trailing n day period, meaning to draw
> the highs/lows over the period from 20 days ago to 10 days ago.
>
> After reviewing the  DonchianChannel() code, it makes use of runMax and
> runMin in TTR that evaluate moving windows of n-days. Is there a similar
> runMax runMin function I can use (or reuse) to build a version of these that
> accept a richer set of parameters, for example nstart=20, nend=10
>
> thanks
>
> Andrew
>

You don't need to modify the function.  Just lag the results appropriately.

require(quantmod)
getSymbols("SPY")
dc <- DonchianChannel(cbind(Hi(SPY),Lo(SPY)), n=10)
# DonchianChannel results from t-20 through t-10
dcLag <- lag(dc,10)

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org 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