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

Peter Chan peter at returnandrisk.com
Wed Jun 3 05:20:01 CEST 2015


Hi Roger

There's an example in the help pages under the "blotter-package" entry.  You need to setup your instruments first eg

# Use the FinancialInstrument package to manage information about tradable 
# instruments
require(FinancialInstrument)
# Define a currency and a couple stocks
currency("USD")
symbols = c("EWJ","EWI")
for(symbol in symbols){ # establish tradable instruments
    stock(symbol, currency="USD", multiplier=1)
}

Thanks

Peter
www.returnandrisk.com



---- On Tue, 02 Jun 2015 19:17:53 +0000  Bos<roger.bos at rothschild.com> wrote ---- 
 > 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. 
 >  
 >  
 > _______________________________________________ 
 > R-SIG-Finance at r-project.org mailing list 
 > https://stat.ethz.ch/mailman/listinfo/r-sig-finance 
 > -- Subscriber-posting only. If you want to post, subscribe first. 
 > -- Also note that this is not the r-help list where general R questions should go. 
 >



More information about the R-SIG-Finance mailing list