1

Currently working on a strategy in quantstrat using Quandl futures data. However, when I try to applyStrategy() after adding indicators, signals and order rules, I receive the following error message, Error in getPrice(mktdata, prefer = prefer) : object 'prefer' not found. applyIndicators() and applySignals() works well when debugging so the error is most likely in the processing of the rules. Below is the tail end of the mktdata variable that results after applying the signals in addition to the end part of the code.

mktdata:

enter image description here

Code:

initPortf(portfolio.mom, symbols=allInstruments, initDate=initDate, currency='USD')
initAcct(account.mom, portfolios=portfolio.mom, initDate=initDate, currency='USD')
initOrders(portfolio.mom, initDate=initDate)
strategy(strategy.mom, store=TRUE)

#Indicators
strategy.mom <- add.indicator(strategy=strategy.mom, name="tsMOM", arguments=list(futDataRet = quote(Cl(mktdata)), momLookback=momLookback, tradingDays=tradingDays), label="tsMOM")
strategy.mom <- add.indicator(strategy=strategy.mom, name="retVol", arguments=list(futDataRet = quote(Cl(mktdata)), volLookback=volLookback, tradingDays=tradingDays), label="retVol")

#Signals
strategy.mom <- add.signal(strategy.mom,name="sigThreshold",arguments=list(threshold=posTradeThresh, column="tsMOM", relationship="gt", cross=FALSE), label="LongCond")
strategy.mom <- add.signal(strategy.mom,name="sigThreshold",arguments=list(threshold=negTradeThresh, column="tsMOM", relationship="lt", cross=FALSE), label="ShortCond")

strategy.mom <- add.signal(strategy.mom, name="sigFormula",  arguments=list(columns=c("tsMOM","LongCond"), formula="((LongCond != 1) & (tsMOM >= 0))", cross=FALSE), label="NeutralPosCond")
strategy.mom <- add.signal(strategy.mom, name="sigFormula",  arguments=list(columns=c("tsMOM","ShortCond"), formula="((tsMOM < 0) & (ShortCond != 1))", cross=FALSE), label="NeutralNegCond")

# Entry Rule
strategy.mom <- add.rule(strategy.mom, name="ruleSignal", arguments=list(sigcol="LongCond", sigval=TRUE, orderqty=1000, ordertype="market", orderside="long", prefer = "Close", TxnFees = -100), type="enter")
strategy.mom <- add.rule(strategy.mom, name="ruleSignal", arguments=list(sigcol="ShortCond", sigval=TRUE, orderqty=1000, ordertype="market", orderside="short", prefer = "Close", TxnFees = -100), type="enter")
# Exit Rule
strategy.mom <- add.rule(strategy.mom, name="ruleSignal", arguments=list(sigcol="NeutralPosCond", sigval=TRUE, orderqty="all", ordertype="market", orderside="short", prefer = "Close", TxnFees = -100), type="exit")
strategy.mom <- add.rule(strategy.mom, name="ruleSignal", arguments=list(sigcol="NeutralNegCond", sigval=TRUE, orderqty="all", ordertype="market", orderside="long", prefer = "Close", TxnFees = -100), type="exit")

applyStrategy(strategy=strategy.mom, portfolios=portfolio.mom, prefer="Close")
updatePortf(portfolio.mom)
updateAcct(account.mom)
updateEndEq(account.mom)

Output of sessionInfo():

enter image description here

user6893
  • 143
  • 1
  • 2
  • 9
  • 1
    Please edit the output of `sessionInfo` into your question. – Joshua Ulrich Dec 26 '14 at 19:39
  • @JoshuaUlrich Added output of sessionInfo. – user6893 Dec 26 '14 at 20:22
  • 1
    I think I fixed this in revision 1611. Please update and retry. – Joshua Ulrich Dec 26 '14 at 20:42
  • @JoshuaUlrich That error is gone now. Thank you. But when I run checkBlotterUpdate() from Guy Yollin's demos/presentations. I get that the account and portfolio P&Ls don't match – user6893 Dec 26 '14 at 22:16
  • 2
    This problem had already been fixed, but the user had not installed the updated package. – Joshua Ulrich Dec 27 '14 at 13:53
  • I can look into the difference you're getting from `checkBlotterUpdate`, but I don't think it's an appropriate question for StackOverflow. Please email me a [reproducible example](http://stackoverflow.com/q/5963269/271616) and reference the relevant demo/presentation. – Joshua Ulrich Dec 27 '14 at 13:56

0 Answers0