1

I don't seem to find is there a way to see Rule name/label of the transaction when reviewing them. I use getTxns() but it is from blotter package and it is not aware of rules that are created by quantstrat. What would be best way to do that?

nesvarbu
  • 986
  • 2
  • 9
  • 24

2 Answers2

1

As a general rule, blotter doesn't know anything about what quantstrat does (other than the transactions quantstrat creates).

I believe the tradeOrderStats function does something close to what you're looking for. It merges the quantstrat order book, which contains the rule label, with the blotter txn table.

For example:

require(quantstrat)
demo("macd", ask=FALSE)
head(tradeOrderStats(portfolio.st, stock.str),2)
           Order.Qty Order.Price  Order.Type Order.Side Order.Threshold
2007-08-17 "all"     "117.049995" "market"   "long"     NA             
2008-01-16 "all"     "169.039997" "market"   "long"     NA             
           Order.Status Order.StatusTime      Prefer Order.Set Txn.Fees Rule  
2007-08-17 "closed"     "2007-08-17 00:00:00" ""     "exit2"   "0"      "exit"
2008-01-16 "closed"     "2008-01-16 00:00:00" ""     "exit2"   "0"      "exit"
           Time.In.Force Start        End          Init.Pos Max.Pos Num.Txns
2007-08-17 ""            "2007-03-16" "2007-08-17" "100"    "100"   "2"     
2008-01-16 ""            "2007-09-05" "2008-01-16" "100"    "100"   "2"     
           Max.Notional.Cost Net.Trading.PL MAE          MFE         
2007-08-17 " 8957"           " 3249.0002"   "    0.0000" " 5643.0003"
2008-01-16 "14416"           " 1547.9994"   "-1239.0003" " 5566.9992"
           Pct.Net.Trading.PL Pct.MAE       Pct.MFE       tick.Net.Trading.PL
2007-08-17 " 0.36273308"      " 0.00000000" "0.630010074" " 3249.0002"       
2008-01-16 " 0.10738065"      "-0.08594619" "0.386168086" " 1547.9994"       
           tick.MAE     tick.MFE    
2007-08-17 "    0.0000" " 5643.0003"
2008-01-16 "-1239.0003" " 5566.9992"
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
0

You can merge Quantstrat's Orderbook with Blotter's Transactions manually which will give you the full list of transactions (entries and exits) as well as the Rule label for that trade.

library(plyr)

QSOrderbook <- ldply(getOrderBook(portfolio.st), data.frame)
rownames(QSOrderbook) <- as.POSIXct(QSOrderbook$data.Order.StatusTime, format = "%Y-%m-%d %H:%M")

bltrTransactions <- as.data.frame(getTxns(Portfolio=portfolio.st, symbols))

Transactions <- merge(QSOrderbook, bltrTransactions[-1,], by=0)
Ed Wilson
  • 267
  • 3
  • 12