2

Hi I am looking at the addTxns function in blotter, and I would like to add fees data/information in the TxnData argument (as a column).

When looking at the function, by running

blotter:::addTxns

it seems to use the column names "Price" and "Quantity" but automatically sets/assigns the TxnFees to zero.

Is there a way of overwriting this, so that it can be included in my analysis?

Here is an example:

rm(list=ls(pos=.blotter),pos=.blotter)
rm(list=ls(pos=.instrument),pos=.instrument)
rm(list=ls(pos=.strategy),pos=.strategy)

currency('USD')
stock("SPY", currency="USD", mulitplier=1)

getSymbols('SPY', from='2012-03-01', to='2012-07-04')

portf.name <- "dummy.Portfolio"  

initPortf(portf.name, 'SPY', initDate='2012-02-29')
initAcct(portf.name, portf.name, initDate='2012-02-29', initEq=1e6)

qty <- rep(c(1,-1), nrow(SPY)/2)
price <- SPY[,4]
txnfees <- rep(-5, nrow(SPY))
txndata <- cbind(qty, price, txnfees)
colnames(txndata) <- c("Quantity","Price","txnfees")

blotter:::addTxns(Portfolio=portf.name, Symbol='SPY', TxnData=txndata )

txns <- getTxns(Portfolio=portf.name, Symbol='SPY')

head(txns)

This will show the buying and selling of 1 share on alternate days at the close but will not show any of the fees relating to each transaction.

h.l.m
  • 13,015
  • 22
  • 82
  • 169
  • You should really this on the r-sig-finance list. Add check its archives as it covers _a lot_ of blotter / quantstrat questions. – Dirk Eddelbuettel Jul 04 '12 at 15:44
  • Haven't see this hit the r-sig-finance list yet, but you're going to need to come up with a reproducible example. Have you read `?addTxns`? `TxnFees` _can_ be a function of `TxnQty` and `TxnPrice`, but it can also just be a negative number (positive for rebates). `txnfees` (note the case) is only set to zero if it is `NULL` or `NA` – GSee Jul 04 '12 at 17:32
  • An example has been added which should hopefully be reproducible... – h.l.m Jul 04 '12 at 23:11

1 Answers1

3

Patched in Rev. 1100.

After checking out, building and installing the new code, I believe this will do what you want:

library(blotter)
currency('USD')
stock("SPY", currency="USD", mulitplier=1)
getSymbols('SPY', from='2012-03-01', to='2012-07-04')
portf.name <- "dummy.Portfolio"
initPortf(portf.name, 'SPY', initDate='2012-02-29')
initAcct(portf.name, portf.name, initDate='2012-02-29', initEq=1e6)
qty <- rep(c(1,-1), nrow(SPY)/2)
price <- SPY[,4]
txnfees <- rep(-5, nrow(SPY))
txndata <- cbind(qty, price, txnfees)
colnames(txndata) <- c("Quantity","Price","TxnFees")
blotter:::addTxns(Portfolio=portf.name, Symbol='SPY', TxnData=txndata )
txns <- getTxns(Portfolio=portf.name, Symbol='SPY')
head(txns)

(Here is link to our discussion on r-sig-finance)

Community
  • 1
  • 1
GSee
  • 48,880
  • 13
  • 125
  • 145