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.