[R-SIG-Finance] quantstrat: NA for "Order.Prefer" for a stoptrailing order
Joshua Ulrich
josh.m.ulrich at gmail.com
Sun Apr 14 21:53:16 CEST 2013
Ivan,
I've been working on a similar issue for the past few days. Can you
please provide a reproducible example that causes problems for you?
Thanks,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
R/Finance 2013: Applied Finance with R | www.RinFinance.com
On Sun, Apr 14, 2013 at 12:13 PM, Ivan Popivanov
<ivan.popivanov at gmail.com> wrote:
> Not 100% sure about the root cause (could be also some bad logic in my
> script), but I managed to track it as far as addOrder - to me the following
> code seems very dubious at least:
>
> for (i in 1:length(price)) {
> if(is.null(prefer[i])) prefer[i] = ''
>
> Notice that the function has a parameter *prefer* with a default value of
> NULL. The first time this loop is entered, is.null(prefer[1]) is TRUE,
> thus, prefer[i] is set to ''. However, subsequent values will be NA, thus,
> the if is not entered and prefer[2] will be left as NA.
>
> Probably better to initialize prefer prior to the loop?
>
> if(is.null(prefer)) prefer = rep(NULL, length(price))
>
> Thanks,
> Ivan
>
> [[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