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

Joshua Ulrich josh.m.ulrich at gmail.com
Thu Jun 4 14:08:00 CEST 2015


On Wed, Jun 3, 2015 at 1:21 PM, Bos, Roger <roger.bos at rothschild.com> wrote:
> Peter, all,
>
> I added the code for FInancialInstruments and I am fine with that, but re-installing blotter (to make sure I have the latest version) is giving me a lot of problems.  In the past I have always been successful running the following (on Windows):
>
>> install.packages('blotter', repos="http://R-Forge.R-project.org", dependencies = TRUE)
> Package which is only available in source form, and may need
>   compilation of C/C++/Fortran: 'blotter'
>   These will not be installed
>>
This seems to suggest something is wrong with your Rtools installation.  I get:

> install.packages('blotter', repos="http://R-Forge.R-project.org", dependencies = TRUE)
Warning: dependencies 'Hmisc', 'RUnit' are not available
Package which is only available in source form, and may need
compilation of C/C++/Fortran: 'blotter'
Do you want to attempt to install these from sources?
y/n:

>
> So I tried building it from source, but that fails as well:
>> install.packages('blotter', repos="http://R-Forge.R-project.org", dependencies = TRUE, type="source")
> trying URL 'http://R-Forge.R-project.org/src/contrib/blotter_0.9.1666.tar.gz'
> Content type 'application/x-gzip' length 72129 bytes (70 KB)
> downloaded 70 KB
>
> '\\rinnycs0051\research\R_HOME'
> CMD.EXE was started with the above path as the current directory.
> UNC paths are not supported.  Defaulting to Windows directory.
<snip package loading>
> * installing *source* package 'blotter' ...
> ** libs
> Warning: running command 'make -f "C:/PROGRA~1/R/R-32~1.0PA/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-32~1.0PA/share/make/winshlib.mk" SHLIB="blotter.dll" WIN=64 TCLBIN=64 OBJECTS="calcPosAvgCost.o"' had status 127
> ERROR: compilation failed for package 'blotter'
> * removing 'C:/Program Files/R/R-3.2.0patched/library/blotter'
>
> The downloaded source packages are in
>         'C:\Users\bosr\AppData\Local\Temp\RtmpkzHy2W\downloaded_packages'
> Warning messages:
> 1: running command '"C:/PROGRA~1/R/R-32~1.0PA/bin/x64/R" CMD INSTALL -l "C:\Program Files\R\R-3.2.0patched\library" C:\Users\bosr\AppData\Local\Temp\RtmpkzHy2W/downloaded_packages/blotter_0.9.1666.tar.gz' had status 1
> 2: In install.packages("blotter", repos = "http://R-Forge.R-project.org",  :
>   installation of package 'blotter' had non-zero exit status
>>
>
> I do have Rtools version 3.3.0.1958 installed and can install any other package I have tried.  Finally, here is my sessionInfo()
>
I just installed R-3.2.0 and Rtools 3.3.0.1958 on 64-bit Windows 7,
and I have no issue installing blotter from source.  I do notice that
you're running R-patched.  Perhaps that has something to do with your
issue?

>> sessionInfo()
> R version 3.2.0 Patched (2015-06-01 r68455)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] datasets  tools     utils     stats     graphics  grDevices methods
> [8] base
>
> other attached packages:
>  [1] sqldf_0.4-10        RSQLite_1.0.0       DBI_0.3.1
>  [4] gsubfn_0.6-6        proto_0.3-10        Rcpp_0.11.6
>  [7] Quandl_2.6.0        testthat_0.10.0     lubridate_1.3.3
> [10] sendmailR_1.2-1     rmarkdown_0.6.1     devtools_1.8.0
> [13] Rpad_1.3.0          formatR_1.2         dplyr_0.4.1
> [16] plyr_1.8.2          reshape2_1.4.1      ggplot2_1.0.1
> [19] xts_0.9-7           zoo_1.7-12          XLConnect_0.2-11
> [22] XLConnectJars_0.2-9 timeDate_3012.100   R2HTML_2.3.1
> [25] RODBC_1.3-11        quadprog_1.5-5      prettyR_2.1-1
> [28] MASS_7.3-40         fortunes_1.5-2      corpcor_1.6.7
> [31] manipulate_1.0.1
>
> loaded via a namespace (and not attached):
>  [1] git2r_0.10.1     base64enc_0.1-2  bitops_1.0-6     digest_0.6.8
>  [5] memoise_0.2.1    gtable_0.1.2     lattice_0.20-31  parallel_3.2.0
>  [9] rJava_0.9-6      knitr_1.10.5     httr_0.6.1       stringr_1.0.0
> [13] rversions_1.0.0  grid_3.2.0       tcltk_3.2.0      XML_3.98-1.2
> [17] magrittr_1.5     htmltools_0.2.6  scales_0.2.4     assertthat_0.1
> [21] colorspace_1.2-6 stringi_0.4-1    RCurl_1.95-4.6   munsell_0.4.2
> [25] chron_2.3-45     crayon_1.2.1
>
> Thanks,
>
> Roger
>
>
>
>
> -----Original Message-----
> From: Joshua Ulrich [mailto:josh.m.ulrich at gmail.com]
> Sent: Wednesday, June 03, 2015 7:46 AM
> To: Peter Chan
> Cc: Bos, Roger; r-sig-finance at r-project.org
> Subject: Re: [R-SIG-Finance] Getting started with blotter (adding transactions)
>
> 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



-- 
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