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

Joshua Ulrich josh.m.ulrich at gmail.com
Wed Jun 3 13:46:26 CEST 2015


As Peter said, you need to create a currency and instruments to avoid
the warnings.  I cannot replicate the error using blotter from
revision 1688 on R-Forge.  What's your sessionInfo() output?

On Tue, Jun 2, 2015 at 10:20 PM, Peter Chan <peter at returnandrisk.com> wrote:
> 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)
>  >
>  >
>  >
>  >
>  > _______________________________________________
>  > 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.
>  >
>
> _______________________________________________
> 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.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2015 | www.rinfinance.com



More information about the R-SIG-Finance mailing list