[R-SIG-Finance] Getting started with blotter (adding transactions)
Bos, Roger
roger.bos at rothschild.com
Wed Jun 3 20:21:32 CEST 2015
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
>
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.
Loading required package: grDevices
Loading required package: graphics
Loading required package: stats
Loading required package: utils
Loading required package: XLConnectJars
XLConnect 0.2-11 by Mirai Solutions GmbH [aut],
Martin Studer [cre],
The Apache Software Foundation [ctb, cph] (Apache POI, Apache Commons
Codec),
Stephen Colebourne [ctb, cph] (Joda-Time Java library)
http://www.mirai-solutions.com ,
http://miraisolutions.wordpress.com
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Attaching package: 'ggplot2'
The following object is masked _by_ '.GlobalEnv':
%+%
Attaching package: 'dplyr'
The following objects are masked from 'package:plyr':
arrange, count, desc, failwith, id, mutate, rename, summarise,
summarize
The following objects are masked from 'package:xts':
first, last
The following object is masked from 'package:MASS':
select
The following object is masked from 'package:stats':
filter
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Attaching package: 'lubridate'
The following object is masked from 'package:plyr':
here
Attaching package: 'testthat'
The following object is masked from 'package:prettyR':
describe
Loading required package: gsubfn
Loading required package: proto
Loading required package: RSQLite
Loading required package: DBI
* 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'
Warning: closing unused RODBC handle 4
Warning: closing unused RODBC handle 3
Warning: closing unused RODBC handle 2
Warning: closing unused RODBC handle 1
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()
> 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
***************************************************************
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.
-----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
More information about the R-SIG-Finance
mailing list