[R-SIG-Finance] Getting started with blotter (adding transactions)

Bos, Roger roger.bos at rothschild.com
Tue Jun 2 21:17:53 CEST 2015


All,

I am trying to learn how to use the blotter package.  I would eventually like to use it to calculate the P&L of a small portfolio.  In my (hopefully) reproducible example below it allows me to add the first transaction, but not the second.
I also get a warning that the instrument is not found.  Could someone point me in the right direction here?  If I have overlooked a good tutorial on this, please let me know that as well.  Here is the error message I get:

> # Add some transactions
> addTxn(portfolio, Symbol='EWJ',  TxnDate='2015-05-13', TxnPrice=30.51, TxnQty = 328, TxnFees=0, verbose=TRUE)
[1] "2015-05-13 00:00:00 EWJ 328 @ 30.51"
Warning messages:
1: In getInstrument(Symbol) :
  instrument EWJ not found, please create it first.
2: In addTxn(portfolio, Symbol = "EWJ", TxnDate = "2015-05-13", TxnPrice = 30.51,  :
  Instrument EWJ  not found, using contract multiplier of 1
> addTxn(portfolio, Symbol='EWJ',  TxnDate='2015-05-15', TxnPrice=31.51, TxnQty = -328, TxnFees=0, verbose=TRUE)
Error in last(PosData[which(index(PosData) <= Date), ][, Columns], n = n) :
  unused argument (n = n)
>

****

require(xts)
require(quantmod)
require(blotter)

Sys.setenv(TZ="EST")

# xts object must be created with explicit index class:
initDate <- '2000-01-01'
getSymbols('SPY', from=initDate, index.class=c("POSIXt","POSIXct"))

portfolio <- "bos"
account <- "acct"
initEq <- 0

# When the test is conducted all blotter related values are written into .blotter environment. If you want repeat the same test, then you need to get rid of all .blotter values. So, you have to run something like this:
rm(list=ls(envir=.blotter), envir = .blotter)

# Add some symbols
sym <- c("EWJ","EWI")
initPortf(name=portfolio, sym, initDate = initDate)
initAcct(account,portfolios=c(portfolio), initDate = initDate, initEq = initEq)

# Add some transactions
addTxn(portfolio, Symbol='EWJ',  TxnDate='2015-05-13', TxnPrice=30.51, TxnQty = 328, TxnFees=0, verbose=TRUE)
addTxn(portfolio, Symbol='EWJ',  TxnDate='2015-05-15', TxnPrice=31.51, TxnQty = -328, TxnFees=0, verbose=TRUE)




***************************************************************
This message and any attachments are for the named person's use only.
This message may contain confidential, proprietary or legally privileged
information. No right to confidential or privileged treatment
of this message is waived or lost by an error in transmission.
If you have received this message in error, please immediately
notify the sender by e-mail, delete the message, any attachments and all
copies from your system and destroy any hard copies. You must
not, directly or indirectly, use, disclose, distribute,
print or copy any part of this message or any attachments if you are not
the intended recipient.




More information about the R-SIG-Finance mailing list