[R-SIG-Finance] Issues about "maCross" demo in Quantstrat

Mark Knecht markknecht at gmail.com
Sun Apr 28 20:22:16 CEST 2013


On Sun, Apr 28, 2013 at 6:54 AM, John Han <john.xiaohan at gmail.com> wrote:
>
> Hi,
>
> I ran the demo "maCross" successfully in R. When I enable the commented code, it works also OK and I suppose to get both long and short position happening in the backtesting result.
>
>
> However, I can only see either long or short and never happen at the same time. It seems like that the "exit" and new "entry" can not be at the same day.
> Any insights? The code in the graph is the only part I changed.
>
> Thanks a lot.
> --
>
> Sincerely,
> John Han
>


Hi John,
   I don't know but that demo doesn't seem to generate shorts for me
either. However there seem to be a number of small inconsistencies in
the code and the current documentation isn't easy to understand. (For
me anyway) The following is based on me running R ver 2.15.3

1) I get some errors starting the run in the first few lines which may
be caused by some package not being explicitly loaded?

> initPortf(portfolio.st,symbols=stock.str, initDate=initDate)
Error in exists(paste("portfolio", name, sep = "."), envir = .blotter,  :
  object '.blotter' not found
> initAcct(account.st,portfolios=portfolio.st, initDate=initDate)
Error in exists(paste("account", name, sep = "."), envir = .blotter,
inherits = TRUE) :
  object '.blotter' not found
> initOrders(portfolio=portfolio.st,initDate=initDate)
Error in getPortfolio(portfolio) :
  Portfolio macross  not found, use initPortf() to create a new portfolio

2) The crossover rules use 'columns' and 'column'. Not sure if that
affects the underlying stratMACROSS structure.

3) The long entry/exit uses 100/all, which the short uses -100/100.
Why the inconsistency?

4) Really it's an initialization issue but in the rules greater
than/less than isn't the same as crosses above/crosses below. I'm
unclear if that's somehow handled in the code setup. Maybe this is
handled by name="sigCrossover", but the relationship="gte"/"lt"
implies (to me) just a logical check. (Would like to find the right
docs to better understand that.

5) In RStudio I don't know how to make sense of the stratMACROSS
structure. It's fairly unreadable to my old eyes.

6) It seems that chart.Posn command doesn't actually draw anything
until I run at least one of the add.SMA commands.

   Overall I'm actually pretty excited about all the capabilities
these geniuses are trying to give us. However right now it's a
learning experience.

HTH,
Mark



More information about the R-SIG-Finance mailing list