how to update lastest equity when doing backtest in quantstrat

56 Views Asked by At

I am trying to use quantstrate to do backest. But could not update the lastest equity using "tradeSize=quote(last(getEndEq(acct,Date = timestamp)))" to get the latest total asset. Hope someone could help. I'm search for this for a long time and tried many times but could not make it. Many many thanks!

# long entry
add.rule(strat,name = "ruleSignal",
         arguments = list(sigcol='EntryLongSig',
                          sigval=TRUE,
                          orderside='long',
                          ordertype='market',
                          osFUN=osDollarATR,
                          pctATR=pctATR,
                          TxnFees=-300,
                          replace=F,
                          prefer='Close',
                          tradeSize=quote(last(getEndEq(acct,Date = timestamp))),
                          atrMod='X'),
         type = 'enter',enabled = TRUE,
         label = "enterLong")
1

There are 1 best solutions below

0
Serhat Akay On

getEndEq(account.st, timestamp) already gives your total equity at specified datetime POSIXct or numerical timestamp object. Using "last" is unnecessary in this condition.

By the way, rules in quantstrat triggers the orders after the signal occurred(next bar). If you wonder your total equity at signal time (previous bar) to calculate order quantity, please try - for instance minutely bar- :

quote(getEndEq(account.st,timestamp-60))

P.S. Try to give reproducible examples in your next questions.