[R-SIG-Finance] applyStrategy() in quantstrat
Joshua Ulrich
josh.m.ulrich at gmail.com
Mon Jul 19 16:24:09 CEST 2010
Brian asked I bounce this to the list...
--
Joshua Ulrich
FOSS Trading: www.fosstrading.com
On Mon, Jul 19, 2010 at 9:00 AM, Brian G. Peterson <brian at braverock.com> wrote:
> On Mon, 2010-07-19 at 12:59 +0100, Raghu wrote:
>> Hi
>>
>> I ran the following code (re-using the BBands.R demo file to test a simple
>> MACD) but it throws an error in the following way. I tried figuring out but
>> could not. Any assistances pls? dput(s) and str(s) as follows. Many thanks.
>>
>>
>> out<-try(applyStrategy(strategy='s' , portfolios='macd1'))
>> Error in list(x) : 'x' is missing
>
> <snip>
>
> The error was in your arguments list:
>
> s <- add.indicator(strategy = s, name = "MACD", arguments = list(Close =
> quote(Close('IBM')), a=a,b=b,c=c, maType=quote(EMA)))
>
> the correct arguments list looks like this:
>
> stratMACD <- add.indicator(strategy = stratMACD, name = "MACD",
> arguments = list(x=quote(Cl(mktdata)), nFast=fastMA, nSlow=slowMA,
> nSig=signalMA,maType="EMA") )
>
>
> The arguments for MACD are
>
> MACD(x, nFast=12, nSlow=26, nSig=9, maType, percent=TRUE, ...)
>
> you tried to pass Close, a, b, c as named arguments with the wrong
> names.
>
> You would also have seen this warning from quantstrat:
>
> In addition: Warning message:
> In applyIndicators(strategy = strategy, mktdata = mktdata, ...) :
> some arguments stored for MACD do not match
>
> which was trying to tell you that your arguments list might have
> something wrong with it.
>
> I've attached a simple MACD strategy script that uses sigThreshold
> (instead of sigCrossover) to use MACD as a simple trend indicator,
> buying when signal is greater than zero, and selling when signal is less
> than zero.
>
> This example has been checked in to SVN.
>
> Regards,
>
> - Brian
>
> --
> Brian G. Peterson
> http://www.braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>
More information about the R-SIG-Finance
mailing list