[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-finance
Subject:    Re: [R-SIG-Finance] RBloomberg: Switch 'periodicity' without
From:       Lüthi_David_(XICD_1)
Date:       2010-02-25 10:33:51
Message-ID: 939D0071146E1941A5ABEB7F23C388C103987C43 () chsa1556 ! share ! beluni ! net
[Download RAW message or body]

During lunch I was given a - fairly obvious :)- hint (thanks to Roger Bergande) which \
I want to share with the list: One can simply create a connection for each \
periodicity in the fashion of

conn.weekly <- blpConnect(periodicity = "weekly")
conn.monthly <- blpConnect(periodicity = "monthly")

Inspecting R-forge is seems that 'RBloomberg' is rapidly growing and improving, \
though let me mention a shortcoming in the current CRAN release 0.1-11 of RBloomberg. \
blpConnect creates an assignment of 'conn' into the global environment (fixed in the \
current version on R-forge). blpDisconnect then removes 'conn' from the global \
environment (also in current R-forge version).  If instead of 'conn' another name is \
chosen the user does not see the shortcoming when connecting and disconnecting \
because careless of the name of the connectiong the global variable 'conn' is created \
and removed.

As blpConnect is already corrected on R-forge I propose to modify 'blpDisconnect' \
from

blpDisconnect <- function(conn){
  ## Garbage collection needed, otherwise COM object is not really
  ## released, preventing any new Bloomberg connection.
  rm(conn, envir=.GlobalEnv);
  gc(verbose=FALSE);
}

to something like

blpDisconnect <- function(x)
{
    ## Garbage collection needed, otherwise COM object is not really
    ## released, preventing any new Bloomberg connection.
    do.call("rm", list(deparse(substitute(x)), envir = .GlobalEnv))
    gc(verbose=FALSE);
}

Cheers, David
David Lüthi
Quant Asset Allocation / Global Investment Solutions
Clariden Leu Ltd 
Claridenstrasse 19
CH - 8002 Zürich
Tel: +41 (0)58 205 6165
david.luethi@claridenleu.com
http://www.claridenleu.com/
This message is for the named person's use only. It may contain confidential, \
proprietary or legally privileged information. No confidentiality or privilege is \
waived or lost by any transmission errors. If you receive this message in error, \
please immediately delete it and all copies of it from your system, destroy any hard \
copies of it and notify the sender. You must not, directly or indirectly, use, \
disclose, distribute, print, or copy any part of this message if you are not the \
intended recipient. CLARIDEN LEU and each of its affiliates each reserve the right to \
intercept and monitor all e-mail communications through its networks if legally \
allowed. Message transmission is not guaranteed to be secure.


> _____________________________________________ 
> From: 	Lüthi David (XICD 1)  
> Sent:	Tuesday, February 23, 2010 10:05 AM
> To:	r-sig-finance@stat.math.ethz.ch
> Subject:	RBloomberg: Switch 'periodicity' without disconnect and reconnect
> 
> Dear list
> 
> I'd like to switch between daily, weekly, and monthly frequencies without \
> disconnect and reconnect, i.e. without evaluating something like conn <- \
> blpConnect(periodicity = "weekly") # fetch some weekly data
> blpDisconnect(conn)
> and 
> conn <- blpConnect(periodicity = "daily")
> # fetch some daily data
> blpDisconnect(conn)
> 
> Passing  the periodicity argument to 'blpGetData' via the '...' argument does not \
> have any impact. See example below. Clearly, I could always download daily data and \
> call 'to.period'. But this is neither efficient nor elegant... 
> Does anybody have a solution?
> 
> Thanks, David
> 
> > library(RBloomberg)
> Loading required package: RDCOMClient
> Loading required package: zoo
> Loading required package: chron
> Warning messages:
> 1: package 'RDCOMClient' was built under R version 2.9.1 and help will not work \
> correctly Please re-install it 
> 2: In file(file, "rt") :
> cannot open file 'C:/blp/API/bbfields.tbl': No such file or directory
> 3: In f(libname, pkgname) :
> I can't find your bbfields file.. see ?blpReadFields
> > .bbfields <- blpReadFields("C:/Program Files/Bloomberg/API")
> conn <- blpConnect(periodicity = "weekly")> 
> > (edb <- blpGetData(conn, "ED1 Comdty", "PX_LAST",start=as.chron(Sys.time() - \
> > 86400 * 30)))
> (edb <- blpGetData(conn, "ED1 Comdty", "PX_LAST",start=as.chron(Sys.time() - 86400 \
> * 30), periodicity = "daily")) blpDisconnect(conn)
> conn <- blpConnect(periodicity = "daily")
> > (edb <- blpGetData(conn, "ED1 Comdty", "PX_LAST",start=as.chron(Sys.time() - \
> > 86400 * 5)))
> (edb <- blpGetData(conn, "ED1 Comdty", "PX_LAST",start=as.chron(Sys.time() - 86400 \
> * 5), periodicity = "weekly")) PX_LAST
> 01/29/10  99.710
> 02/05/10  99.700
> 02/12/10  99.710
> 02/19/10  99.715
> > blpDisconnect(conn)
> PX_LAST
> 01/29/10  99.710
> 02/05/10  99.700
> 02/12/10  99.710
> 02/19/10  99.715
> > sessionInfo()
> used (Mb) gc trigger (Mb) max used (Mb)
> Ncells 354042  9.5     667722 17.9   405902 10.9
> Vcells 762687  5.9    1463436 11.2  1303897 10.0
> > > PX_LAST
> 02/17/10 99.7225
> 02/18/10 99.7225
> 02/19/10 99.7150
> 02/22/10 99.7200
> > PX_LAST
> 02/17/10 99.7225
> 02/18/10 99.7225
> 02/19/10 99.7150
> 02/22/10 99.7200
> > used (Mb) gc trigger (Mb) max used (Mb)
> Ncells 354042  9.5     667722 17.9   431994 11.6
> Vcells 762687  5.9    1463436 11.2  1303897 10.0
> > R version 2.10.1 (2009-12-14) 
> i386-pc-mingw32 
> 
> locale:
> [1] LC_COLLATE=German_Switzerland.1252  LC_CTYPE=German_Switzerland.1252   
> [3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C                       
> [5] LC_TIME=English_Switzerland.1252   
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base     
> 
> other attached packages:
> [1] RBloomberg_0.1-11  chron_2.3-33       zoo_1.6-2          RDCOMClient_0.92-0
> 
> loaded via a namespace (and not attached):
> [1] grid_2.10.1     lattice_0.17-26
> > 
> 
> David Lüthi
> Quant Asset Allocation / Global Investment Solutions
> Clariden Leu Ltd 
> Claridenstrasse 19
> CH > ->  8002 Zürich
> Tel: +41 (0)58 205 6165
> david.luethi@claridenleu.com
> http://www.claridenleu.com/
> This message is for the named person's use only. It may contain confidential, \
> proprietary or legally privileged information. No confidentiality or privilege is \
> waived or lost by any transmission errors. If you receive this message in error, \
> please immediately delete it and all copies of it from your system, destroy any \
> hard copies of it and notify the sender. You must not, directly or indirectly, use, \
> disclose, distribute, print, or copy any part of this message if you are not the \
> intended recipient. CLARIDEN LEU and each of its affiliates each reserve the right \
> to intercept and monitor all e-mail communications through its networks if legally \
> allowed. Message transmission is not guaranteed to be secure. 

	[[alternative HTML version deleted]]



_______________________________________________
R-SIG-Finance@stat.math.ethz.ch 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.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic