[R-SIG-Finance] RBloomberg/RJava Issue

Benjamin, Michael Michael.Benjamin at bernstein.com
Thu Dec 15 13:01:34 CET 2011


Hello

I have upgraded my Bloomberg.  Although my Bloomberg worked with the COM connection, now when I execute 
require(RBloomberg)
require(rJava)
conn <- blpConnect() # or "conn <- blpConnect(blpapi.jar.file="C:\\Program Files\\blp\\API\\blpapi3.jar")"

I get an error message

conn <- blpConnect()
R version 2.14.0 (2011-10-31) 
rJava Version 0.9-2 
RBloomberg Version 0.4-150 
Java environment initialized successfully.
Looking for most recent blpapi3.jar file...
Adding C:\blp\API\blpapi3.jar to Java classpath
Error in .jnew("org/findata/blpwrapper/Connection", java.log.level) : 
  java.lang.NoClassDefFoundError: com/bloomberglp/blpapi/SessionOptions


My session info is

> sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] grDevices datasets  stats     utils     graphics  methods   base     

other attached packages:
[1] RBloomberg_0.4-150           rJava_0.9-2                  RDCOMClient_0.92-0.1                     
[6]          

loaded via a namespace (and not attached):
[1]


Do you know what I need to do to overcome this issue to get the calls


ticker <- "AGS BB Equity"
start.time <- "2011-09-12 08:00:00.000"
end.time <- "2011-09-12 16:30:00.000"
trades.1 <- bar(conn, ticker, "TRADE", start.time, end.time, "1")

to work?

Regards

Michael


-----Original Message-----
From: r-sig-finance-bounces at r-project.org [mailto:r-sig-finance-bounces at r-project.org] On Behalf Of r-sig-finance-request at r-project.org
Sent: 02 December 2011 11:00
To: r-sig-finance at r-project.org
Subject: R-SIG-Finance Digest, Vol 91, Issue 2

Send R-SIG-Finance mailing list submissions to
	r-sig-finance at r-project.org

To subscribe or unsubscribe via the World Wide Web, visit
	https://stat.ethz.ch/mailman/listinfo/r-sig-finance
or, via email, send a message with subject or body 'help' to
	r-sig-finance-request at r-project.org

You can reach the person managing the list at
	r-sig-finance-owner at r-project.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of R-SIG-Finance digest..."


Today's Topics:

   1. Re: HELP: Problem with RBloomberg blp intraday data (John Laing)
   2. Re: PerformanceAnalytics - Sharpes Style Analysis- but with
      intercept? (Philipp)
   3. Constrained Regression with Intercept in pcls (Philipp)
   4. Re: Constrained Regression with Intercept in pcls
      (Enrico Schumann)
   5. Re: Constrained Regression with Intercept in pcls
      (thomas.chan.sf at boci-pru.com.hk)


----------------------------------------------------------------------

Message: 1
Date: Thu, 1 Dec 2011 07:58:23 -0500
From: John Laing <john.laing at gmail.com>
To: "Benjamin, Michael" <Michael.Benjamin at bernstein.com>
Cc: r-sig-finance at r-project.org
Subject: Re: [R-SIG-Finance] HELP: Problem with RBloomberg blp
	intraday data
Message-ID:
	<CAA3Wa=tSoMCzVnZdCy5P970-8dFgXp=VMV2mp=hDcYqN_vELbw at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Michael,

This works in the current version of RBloomberg:

#############################################################
require(RBloomberg)
conn <- blpConnect()

ticker <- "AGS BB Equity"
start.time <- "2011-09-12 08:00:00.000"
end.time <- "2011-09-12 16:30:00.000"

trades.1 <- bar(conn, ticker, "TRADE", start.time, end.time, "1")
trades.510 <- bar(conn, ticker, "TRADE", start.time, end.time, "510")
sum(trades.1$numEvents) == sum(trades.510$numEvents) ## TRUE

bids.1 <- bar(conn, ticker, "BID", start.time, end.time, "1")
bids.510 <- bar(conn, ticker, "BID", start.time, end.time, "510")
sum(bids.1$numEvents) == sum(bids.510$numEvents) ## TRUE

asks.1 <- bar(conn, ticker, "ASK", start.time, end.time, "1")
asks.510 <- bar(conn, ticker, "ASK", start.time, end.time, "510")
sum(asks.1$numEvents) == sum(asks.510$numEvents) ## TRUE
#############################################################

If there are still problems or unexpected NAs after you upgrade, I'd
be happy to help.

Thanks,
John

On Tue, Nov 29, 2011 at 7:11 AM, Benjamin, Michael
<Michael.Benjamin at bernstein.com> wrote:
> John
>
> Thanks for looking into this for me.
>
> Details of what I am using is as follows:
>
> ============================================================
>> sessionInfo()
> R version 2.10.1 (2009-12-14)
> i386-pc-mingw32
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252
> [2] LC_CTYPE=English_United Kingdom.1252
> [3] LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United Kingdom.1252
>
> attached base packages:
> [1] grDevices datasets ?stats ? ? utils ? ? graphics ?methods ? base
>
> other attached packages:
> ?[1] RBloomberg_0.2-98
> ?[3]
> ?[5]
> ?[7]
> ?[9]
> [11]
>
> ============================================================
>
>
> I agree that what is being processed is pretty straightforward which is why it is strange that it works for some data and not for others despite using an old version of RBloomberg. ?I will update my RBloomber soon, but out of curiosity, as the issue is not the "TRADE" ticks being returned over a time range (which works OK for me) but the "number of ticks" for bid or ask prices.
>
> Do you have any issues if you
>
> ?increase the barsize to 510
>
> and
>
> request the total number of ticks for bid, ask and trade ticks for the same stock over the same time period?
>
>
> Best regards
>
> Michael
>
>
>
> -----Original Message-----
> From: John Laing [mailto:john.laing at gmail.com]
> Sent: 29 November 2011 00:23
> To: Benjamin, Michael
> Cc: r-sig-finance at r-project.org
> Subject: Re: [R-SIG-Finance] HELP: Problem with RBloomberg blp intraday data
>
> Michael,
>
> It is helpful if you provide information about the version of R and
> various packages that you are running. The sessionInfo() function is
> an excellent way to do that.
>
> The timeout argument to blpConnect was eliminated in early 2010, so I
> assume your version of RBloomberg is very old. There are now several
> recent threads on this list about how to upgrade and the dependencies
> involved. I recommend you read some of these.
>
> In the current RBloomberg what you're trying to do is pretty straightforward:
>
> library(RBloomberg)
> conn <- blpConnect()
> trades <- bar(conn, "AGS BB Equity", "TRADE", "2011-09-12
> 08:00:00.000", "2011-09-12 16:30:00.000", "1")
>
> Hope that helps,
> John
>
> On Thu, Nov 24, 2011 at 5:45 AM, Benjamin, Michael
> <Michael.Benjamin at bernstein.com> wrote:
>> Hello
>>
>> I am trying to download some intraday data, the number of ticks over a time range. ?Packages installed are "package:RBloomberg" and "package:RDCOMClient".
>>
>> The data request is for the number of ticks over a date range using
>>
>> conn<-blpConnect(timeout=120000,show.days="week",na.action="na",periodicity="daily")
>> blp(conn, "AGS BB EQUITY",fields=c("LAST_PRICE"),start="2011-09-12 08:00",end="2011-09-12 16:30",barsize=510, barfields="NUMBER_TICKS")
>>
>> which returns the number 3574. ?When passing the argument fields=c("BID") or fields=c("ASK") the number of bid or ask ticks returns <NA>.
>>
>> blp(conn, "AGS BB EQUITY",fields=c("BID"),start="2011-09-12 08:00",end="2011-09-12 16:30",barsize=510, barfields="NUMBER_TICKS")
>> blp(conn, "AGS BB EQUITY",fields=c("ASK"),start="2011-09-12 08:00",end="2011-09-12 16:30",barsize=510, barfields="NUMBER_TICKS")
>>
>> The issue is this is not consistent behavour with other stocks, for example, for EBS AV EQUITY the BID, ASK LAST_PRICE number of ticks is
>> 33800, 33800,2232
>>
>> Has anyone got any idea why this happens or if there is a way to resolve it?
>>
>> Best regards
>>
>> Michael
>>
>> ............................................................................
>>
>> Sanford C. Bernstein Limited (registered in England and Wales under company number 3760267) is authorised and regulated in the United Kingdom by the Financial Services Authority. The company has its registered office at 50 Berkeley Street, London W1J 8SB.
>>
>> Trading instructions sent electronically to Bernstein shall not be deemed accepted until a representative of Bernstein acknowledges receipt electronically or by telephone. Comments in this e-mail transmission and any attachments may form part of a larger body of investment analysis. For our research reports, which contain information that may be used to support investment decisions and disclosures see our website at www.bernsteinresearch.com.
>>
>> For further important information about AllianceBernstein please click here http://www.alliancebernstein.com/disclaimer/email/disclaimer.html
>>
>> Please note that as of 7 November, 2011 Sanford C. Bernstein Limited will be located at 50 Berkeley Street, London W1J 8SB.
>>
>> ? ? ? ?[[alternative HTML version deleted]]
>>
>> _______________________________________________
>> 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.
>>



------------------------------

Message: 2
Date: Thu, 1 Dec 2011 08:04:21 -0800 (PST)
From: Philipp <jasonhome at freenet.de>
To: r-sig-finance at r-project.org
Subject: Re: [R-SIG-Finance] PerformanceAnalytics - Sharpes Style
	Analysis- but with intercept?
Message-ID: <1322755461301-4129124.post at n4.nabble.com>
Content-Type: text/plain; charset=us-ascii

Thanks for the commented Function. So i can understand a little bit more
about it. 

In fact I want to run following constrained Regression. R.f=w0 +
w1*Rs_1+w2*Rs_2+w3*Rs_3 
with the constraints: (1) w1+w2+w3 =1 (2) w1,w2,w3>0. So the Intercept(w0)
is not included in the Constraints. In my case, R.f is a country return,
which I regress on an intercept and Industryreturnbenchmarks. The purpose is
to find a quantity of how well the Industries can explain a country-index.
(Which will be done by Rsquared, The question why an intercept is integrated
(That has been done in some papers, considering this topic), I can not
explain.Maybe because of a better fit). 

If I would consider an intercept I have to fix the Calculation of D and d in
the code of style.QPfit. The purpose is to minimize Var(R.fund-sum[w_i*Rs_i
+w0]). Then I get Var(R.f)(=0)+Var(wiRs_i+w0)-2Cov(Rfund, Rstyle+w0). So in
the Calculation of D and d I get D (=Dmat)=Cov(Rstyle+w0); d=Cov(R.fund,
Rstyle+w0). So my Problem is now to find the right function to minimize
under estimating w, without changing the constraints. 

Thanks,

Best regards

Philipp

--
View this message in context: http://r.789695.n4.nabble.com/PerformanceAnalytics-Sharpes-Style-Analysis-but-with-intercept-tp4125767p4129124.html
Sent from the Rmetrics mailing list archive at Nabble.com.



------------------------------

Message: 3
Date: Thu, 1 Dec 2011 08:18:14 -0800 (PST)
From: Philipp <jasonhome at freenet.de>
To: r-sig-finance at r-project.org
Subject: [R-SIG-Finance] Constrained Regression with Intercept in pcls
Message-ID: <1322756294407-4129187.post at n4.nabble.com>
Content-Type: text/plain; charset=us-ascii

Dear all,

I already asked about to run a constrained regression like y=b0 +
b1X1+b2x2+b3x3, with constraints:

b1+b2+b3=1 and b1,b2,b3>=0. I thought it will run with style.QPfit with the
performance Analytic packages.

However the style.QPfit function does not estimate an intercept. As i really
can not extend this function for my problem, I noticed pcls. Pcls is maybe
an alternative for my problem. Can somebody help me to implement the
constraints in pcls. Maybe it can be done by designing a designed matrix X
with extra column for the inercept (b0) and to force C in a way. But how I
do not know.

Your help is greatly appreciated

Philipp

--
View this message in context: http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4129187.html
Sent from the Rmetrics mailing list archive at Nabble.com.



------------------------------

Message: 4
Date: Thu, 01 Dec 2011 22:24:52 +0100
From: Enrico Schumann <enricoschumann at yahoo.de>
To: Philipp <jasonhome at freenet.de>
Cc: r-sig-finance at r-project.org
Subject: Re: [R-SIG-Finance] Constrained Regression with Intercept in
	pcls

Content-Type: text/plain; charset=ISO-8859-1; format=flowed


Hi Philipp,

you should be able to solve this with package quadprog/solve.QP.

require(quadprog)

p <- 3    ## number of regressors
T <- 100  ## number of obs
X <- array(rnorm(T*p), dim = c(T,p))
X <- cbind(1,X)  ## add a constant
y <- rnorm(T)


## variant 1 -- linear regression
coef(lm(y ~ -1 + X))


## variant 2 -- quadprog (should be the same as variant 1)
Dmat <- crossprod(X)
dvec <- as.vector(t(as.matrix(y)) %*% X)
Amat <- as.matrix(rep(0, p+1))
solve.QP(Dmat = Dmat, dvec = dvec, Amat = Amat)$solution


## variant 3 -- quadprog, now with restrictions
bvec <- c(1, rep(0, p))
Amat <- rbind(1,diag(p))
Amat <- cbind(0, Amat)
w <- solve.QP(Dmat = Dmat, dvec = dvec, Amat = t(Amat), bvec=bvec, 
meq=1)$solution
w          ## result
sum(w[-1]) ## check constraint

see also here http://comisef.wikidot.com/tutorial:minimisevariance

regards,
Enrico




Am 01.12.2011 17:18, schrieb Philipp:
> Dear all,
>
> I already asked about to run a constrained regression like y=b0 +
> b1X1+b2x2+b3x3, with constraints:
>
> b1+b2+b3=1 and b1,b2,b3>=0. I thought it will run with style.QPfit with the
> performance Analytic packages.
>
> However the style.QPfit function does not estimate an intercept. As i really
> can not extend this function for my problem, I noticed pcls. Pcls is maybe
> an alternative for my problem. Can somebody help me to implement the
> constraints in pcls. Maybe it can be done by designing a designed matrix X
> with extra column for the inercept (b0) and to force C in a way. But how I
> do not know.
>
> Your help is greatly appreciated
>
> Philipp
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4129187.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> 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.
>

-- 
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/



------------------------------

Message: 5
Date: Fri, 2 Dec 2011 09:37:24 +0800
From: thomas.chan.sf at boci-pru.com.hk
To: Philipp <jasonhome at freenet.de>
Cc: r-sig-finance at r-project.org, r-sig-finance-bounces at r-project.org
Subject: Re: [R-SIG-Finance] Constrained Regression with Intercept in
	pcls
Message-ID:
	<OF90B4A92B.1BA4D71E-ON4825795A.000871CE-4825795A.0008EAF4 at boci-pru.com.hk>
	
Content-Type: text/plain; charset=US-ASCII

Alternatively, the lsei (least squares with equalities and inequalities) fu
nction in the limSolve package solves for the least square solution to a
system of equations with linear and nonlinear constraints.


|------------>
| From:      |
|------------>
  >----------------------------------------------------------------------------------------------------------------------------------------|
  |Philipp <jasonhome at freenet.de>                                                                                                          |
  >----------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| To:        |
|------------>
  >----------------------------------------------------------------------------------------------------------------------------------------|
  |r-sig-finance at r-project.org                                                                                                             |
  >----------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Date:      |
|------------>
  >----------------------------------------------------------------------------------------------------------------------------------------|
  |02/12/2011 00:20                                                                                                                        |
  >----------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Subject:   |
|------------>
  >----------------------------------------------------------------------------------------------------------------------------------------|
  |[R-SIG-Finance] Constrained Regression with Intercept in pcls                                                                           |
  >----------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Sent by:   |
|------------>
  >----------------------------------------------------------------------------------------------------------------------------------------|
  |r-sig-finance-bounces at r-project.org                                                                                                     |
  >----------------------------------------------------------------------------------------------------------------------------------------|





Dear all,

I already asked about to run a constrained regression like y=b0 +
b1X1+b2x2+b3x3, with constraints:

b1+b2+b3=1 and b1,b2,b3>=0. I thought it will run with style.QPfit with the
performance Analytic packages.

However the style.QPfit function does not estimate an intercept. As i
really
can not extend this function for my problem, I noticed pcls. Pcls is maybe
an alternative for my problem. Can somebody help me to implement the
constraints in pcls. Maybe it can be done by designing a designed matrix X
with extra column for the inercept (b0) and to force C in a way. But how I
do not know.

Your help is greatly appreciated

Philipp

--
View this message in context:
http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4129187.html

Sent from the Rmetrics mailing list archive at Nabble.com.

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

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________



---------------------------------------------------------------------------------------

Important : The information contained in this e-mail and any attachment thereof is intended only for use of the addressee and is confidential and may be privileged and/or otherwise protected from disclosure. If you are not the intended recipient, you are hereby notified that any use, copying, dissemination or any other action taken or omitted to be taken in reliance upon this information is strictly prohibited. If you have received this communication in error, please notify the sender immediately by reply and delete this message from your system. Any views expressed in this e-mail are those of the individual sender except where the e-mail states otherwise and the sender is authorized to state them to be the views of BOCI-Prudential Asset Management Limited. Unless otherwise stated, any information given in this e-mail shall not be regarded as an offer, solicitation, invitation, advice or recommendation to buy or sell any investment or securities within or outside Hong Kong S!
 AR. Any reference to the terms of executed transactions should be treated as preliminary only and subject to our formal written confirmation.


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com



------------------------------

_______________________________________________
R-SIG-Finance mailing list
R-SIG-Finance at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-finance


End of R-SIG-Finance Digest, Vol 91, Issue 2



More information about the R-SIG-Finance mailing list