Skip to content

Commit b74db8e

Browse files
committed
br-libs dir
1 parent 80c606a commit b74db8e

17 files changed

+156
-423
lines changed

bin-bak/run.exe

0 Bytes
Binary file not shown.

bloomr.build.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### BloomR source
22
## TODO
3+
## Complete commonilisation of Rmd components in Rmd's in BloomR.src/src/br-libs/ as for bloomr-time.Rmd
34
## In bloomr.init.R, eikonapir loading removes requestInfo from .GlobalEnv with a hack. Test it and then delete eikon.fallback()
45
## In bloomr.Rmd bdh always.display.ticker, dates.as.row.names and perhaps more relate to old java package.
56
## Custom polymode (bremacs-rmd-mode), temporary disabled, to be restored in br-setmode.el

src/br-libs/bloomr-bbg.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## ----store, opts.label='purlme'----------------------------------------------------------------------------------------------------
1+
## ----store, opts.label='brfuncs'---------------------------------------------------------------------------------------------------
22
## Purl this first
33
## Store br.* objects in dedicated namespace
44
bloomr.bbg <- new.env(parent=asNamespace("stats"))
@@ -18,7 +18,7 @@ store=function(sym){
1818
}
1919

2020

21-
## ----br.bdh, opts.label='purlme'---------------------------------------------------------------------------------------------------
21+
## ----br.bdh, opts.label='brfuncs'--------------------------------------------------------------------------------------------------
2222
br.bdh=function(
2323
con, securities, fields="PX_LAST", start.date, end.date = NULL,
2424
option.names = NULL, option.values = NULL,
@@ -32,7 +32,7 @@ br.bdh=function(
3232
}
3333
store(br.bdh)
3434

35-
## ----br.bulk.csv, opts.label='purlme'----------------------------------------------------------------------------------------------
35+
## ----br.bulk.csv, opts.label='brfuncs'---------------------------------------------------------------------------------------------
3636
br.bulk.csv=function(con, file, start=Sys.Date()-5, field="PX_LAST", cols=NULL,
3737
addtype=FALSE, showtype=FALSE, use.xts=TRUE, comma=TRUE,
3838
price=TRUE, nrow=5, same.dates=FALSE, no.na=FALSE, empty.sec=0
@@ -77,7 +77,7 @@ br.bulk.csv=function(con, file, start=Sys.Date()-5, field="PX_LAST", cols=NULL,
7777
}
7878
store(br.bulk.csv)
7979

80-
## ----br.bulk.desc, opts.label='purlme'---------------------------------------------------------------------------------------------
80+
## ----br.bulk.desc, opts.label='brfuncs'--------------------------------------------------------------------------------------------
8181
br.bulk.desc=function(con, tiks) {
8282

8383
LL = lapply(tiks, function(tik){
@@ -89,7 +89,7 @@ br.bulk.desc=function(con, tiks) {
8989
}
9090
store(br.bulk.desc)
9191

92-
## ----br.bulk.idx, opts.label='purlme'----------------------------------------------------------------------------------------------
92+
## ----br.bulk.idx, opts.label='brfuncs'---------------------------------------------------------------------------------------------
9393
br.bulk.idx=function(con, index, start=Sys.Date()-5, field="PX_LAST", showtype=FALSE,
9494
include.idx=TRUE, use.xts=TRUE,
9595
nsec=10, price=TRUE, nrow=5,
@@ -139,7 +139,7 @@ br.bulk.idx=function(con, index, start=Sys.Date()-5, field="PX_LAST", showtype=F
139139
}
140140
store(br.bulk.idx)
141141

142-
## ----br.bulk.tiks, opts.label='purlme'---------------------------------------------------------------------------------------------
142+
## ----br.bulk.tiks, opts.label='brfuncs'--------------------------------------------------------------------------------------------
143143
br.bulk.tiks=function(
144144
con,
145145
tiks,
@@ -223,7 +223,7 @@ br.bulk.tiks=function(
223223
}
224224
store(br.bulk.tiks)
225225

226-
## ----br.desc, opts.label='purlme'--------------------------------------------------------------------------------------------------
226+
## ----br.desc, opts.label='brfuncs'-------------------------------------------------------------------------------------------------
227227
br.desc=function(con, tik)
228228
{
229229

@@ -252,7 +252,7 @@ br.desc=function(con, tik)
252252
}
253253
store(br.desc)
254254

255-
## ----br.sample, opts.label='purlme'------------------------------------------------------------------------------------------------
255+
## ----br.sample, opts.label='brfuncs'-----------------------------------------------------------------------------------------------
256256
br.sample=function(nrow, nsec=1, price=TRUE, start=Sys.Date(), mean=ifelse(price, 10, 0.1), sd=1,
257257
jitter=0, same.dates=FALSE, no.na=FALSE, df=FALSE, empty.sec=0, sec.names=NULL)
258258
{
@@ -319,7 +319,7 @@ br.sample=function(nrow, nsec=1, price=TRUE, start=Sys.Date(), mean=ifelse(price
319319
}
320320
store(br.sample)
321321

322-
## ----bbg-internal, opts.label='purlme'---------------------------------------------------------------------------------------------
322+
## ----bbg-internal, opts.label='brfuncs'--------------------------------------------------------------------------------------------
323323

324324
## Check connection token
325325
.br.is.con=function(con) identical(attr(con, 'jclass'), "org/findata/blpwrapper/Connection")
@@ -356,14 +356,14 @@ store(.br.check.type)
356356
store(.br.cuttype)
357357
store(.br.jar)
358358

359-
## ----connections, opts.label='purlme'----------------------------------------------------------------------------------------------
359+
## ----connections, opts.label='brfuncs'---------------------------------------------------------------------------------------------
360360
br.open=function() blpConnect(blpapi.jar.file=.br.jar())
361361
br.close=function(conn) if(!is.null(conn)) blpDisconnect(conn)
362362

363363
store(br.open)
364364
store(br.close)
365365

366-
## ----attach, opts.label='purlme'---------------------------------------------------------------------------------------------------
366+
## ----attach, opts.label='brfuncs'--------------------------------------------------------------------------------------------------
367367
### Make visible br.* in bloomr env and base ns
368368
attach(bloomr.bbg)
369369
rm(store)

src/br-libs/bloomr-bbg.Rmd

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ knit2("bloomr-bbg.Rmd")
7272
knitr::opts_chunk$set(echo=TRUE)
7373
OTS <- knitr::opts_template$set
7474
## Build functions used in first step
75-
OTS(purlme= list(purl=TRUE, eval=!step2, include=FALSE))
75+
OTS(brfuncs= list(purl=TRUE, eval=!step2, include=FALSE))
7676
## Demo functions used in second step
7777
OTS(demofull= list(purl=FALSE, eval=step2, include=TRUE)) # run with code + output
7878
OTS(demorun= list(purl=FALSE, eval=step2, include=TRUE, echo=FALSE)) # run with output, but no code
@@ -88,7 +88,7 @@ RESDIR <- "../../res"
8888
```
8989

9090

91-
```{r store, opts.label='purlme'}
91+
```{r store, opts.label='brfuncs'}
9292
## Purl this first
9393
## Store br.* objects in dedicated namespace
9494
bloomr.bbg <- new.env(parent=asNamespace("stats"))
@@ -241,7 +241,7 @@ A data frame with historical data. If tickers are displayed, the first column sh
241241

242242

243243

244-
```{r br.bdh, opts.label='purlme'}
244+
```{r br.bdh, opts.label='brfuncs'}
245245
br.bdh=function(
246246
con, securities, fields="PX_LAST", start.date, end.date = NULL,
247247
option.names = NULL, option.values = NULL,
@@ -320,7 +320,7 @@ If `use.xts=FALSE`, elements are sub-list, where each element is the historical
320320
If there is only one group, the first (and unique) element of the list will be returned.
321321

322322

323-
```{r br.bulk.csv, opts.label='purlme'}
323+
```{r br.bulk.csv, opts.label='brfuncs'}
324324
br.bulk.csv=function(con, file, start=Sys.Date()-5, field="PX_LAST", cols=NULL,
325325
addtype=FALSE, showtype=FALSE, use.xts=TRUE, comma=TRUE,
326326
price=TRUE, nrow=5, same.dates=FALSE, no.na=FALSE, empty.sec=0
@@ -525,7 +525,7 @@ Value
525525
A list of data frames, each representing the description of a security. For the format of data frames see the function `br.desc`.
526526

527527

528-
```{r br.bulk.desc, opts.label='purlme'}
528+
```{r br.bulk.desc, opts.label='brfuncs'}
529529
br.bulk.desc=function(con, tiks) {
530530
531531
LL = lapply(tiks, function(tik){
@@ -594,7 +594,7 @@ If `use.xts=FALSE`, a list, where each element is the historical data of a const
594594
If `include.idx=TRUE`, the last column or element will be the historical data of the index.
595595

596596

597-
```{r br.bulk.idx, opts.label='purlme'}
597+
```{r br.bulk.idx, opts.label='brfuncs'}
598598
br.bulk.idx=function(con, index, start=Sys.Date()-5, field="PX_LAST", showtype=FALSE,
599599
include.idx=TRUE, use.xts=TRUE,
600600
nsec=10, price=TRUE, nrow=5,
@@ -690,7 +690,7 @@ See Also
690690

691691
[br.bulk.csv](#br.bulk.csv)
692692

693-
```{r br.bulk.tiks, opts.label='purlme'}
693+
```{r br.bulk.tiks, opts.label='brfuncs'}
694694
br.bulk.tiks=function(
695695
con,
696696
tiks,
@@ -798,7 +798,7 @@ Value
798798
-----
799799
A data frame containing the value of the Bloomberg fields form `ds001` to `ds009` and the long field `CIE_DES_BULK`.
800800

801-
```{r br.desc, opts.label='purlme'}
801+
```{r br.desc, opts.label='brfuncs'}
802802
br.desc=function(con, tik)
803803
{
804804
@@ -884,7 +884,7 @@ Value
884884
-----
885885
If `df=TRUE`, a data frame object, where the first column is the vector with all generated dates merged and each subsequent column contains the sampled data of a security. If `df=FALSE`, an xts object, where each element is the sampled data of a security, while the dates will be part of the xts time object. In both cases if `same.dates=FALSE` and/or `empty.sec!=0` generated data points will have different length and the the date gaps will be filled with NAs, except if `no.na=TRUE`. If the generated values are only NAs the output will be converted to a 0-rows xts or data frame, containing only security labels accessible with `dimnames(*)[[2]]`.
886886

887-
```{r br.sample, opts.label='purlme'}
887+
```{r br.sample, opts.label='brfuncs'}
888888
br.sample=function(nrow, nsec=1, price=TRUE, start=Sys.Date(), mean=ifelse(price, 10, 0.1), sd=1,
889889
jitter=0, same.dates=FALSE, no.na=FALSE, df=FALSE, empty.sec=0, sec.names=NULL)
890890
{
@@ -986,7 +986,7 @@ Details
986986
`.br.jar()` returns the path to the blpapi*.jar
987987

988988

989-
```{r bbg-internal, opts.label='purlme'}
989+
```{r bbg-internal, opts.label='brfuncs'}
990990
991991
## Check connection token
992992
.br.is.con=function(con) identical(attr(con, 'jclass'), "org/findata/blpwrapper/Connection")
@@ -1059,7 +1059,7 @@ br.close(con) # Use the token to release the connection
10591059
```
10601060

10611061

1062-
```{r connections, opts.label='purlme'}
1062+
```{r connections, opts.label='brfuncs'}
10631063
br.open=function() blpConnect(blpapi.jar.file=.br.jar())
10641064
br.close=function(conn) if(!is.null(conn)) blpDisconnect(conn)
10651065
@@ -1251,7 +1251,7 @@ parseargs <- function(rmdfile, tmpfile) {
12511251
12521252
```
12531253

1254-
```{r attach, opts.label='purlme'}
1254+
```{r attach, opts.label='brfuncs'}
12551255
### Make visible br.* in bloomr env and base ns
12561256
attach(bloomr.bbg)
12571257
rm(store)

src/br-libs/bloomr-bbg.html

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351

352352
<h1 class="title toc-ignore">BloomR Bloomberg Functions</h1>
353353
<h4 class="author">Antonio Fasano</h4>
354-
<h4 class="date">Jan 28, 2024</h4>
354+
<h4 class="date">Jan 29, 2024</h4>
355355

356356
</div>
357357

@@ -709,6 +709,11 @@ <h2>Demonstration</h2>
709709
<pre class="r"><code>con=NULL #Simulated mode: replace with con=br.open() on terminal</code></pre>
710710
<pre class="r"><code>data=br.bulk.csv(con, &quot;mybloomr/tickers.csv&quot;)</code></pre>
711711
<pre><code>## Processing Financial ...</code></pre>
712+
<pre><code>##
713+
## Attaching package: &#39;zoo&#39;</code></pre>
714+
<pre><code>## The following objects are masked from &#39;package:base&#39;:
715+
##
716+
## as.Date, as.Date.numeric</code></pre>
712717
<pre><code>## Loading 3988 HK Equity</code></pre>
713718
<pre><code>## Loading C US Equity</code></pre>
714719
<pre><code>## Loading 601288 CH Equity</code></pre>
@@ -730,27 +735,27 @@ <h2>Demonstration</h2>
730735
like follows:</p>
731736
<pre class="r"><code>data</code></pre>
732737
<pre><code>## $Financial
733-
## 3988 HK C US 601288 CH BAC US HSBA LN
734-
## 2024-01-23 10.699 10.934 NA 9.724 NA
735-
## 2024-01-24 10.751 8.299 NA 10.803 8.682
736-
## 2024-01-25 NA 9.134 8.952 9.180 NA
737-
## 2024-01-26 NA NA NA 9.616 NA
738-
## 2024-01-27 NA 9.547 NA NA NA
738+
## 3988 HK C US 601288 CH BAC US HSBA LN
739+
## 2024-01-24 11.422 9.112 7.893 NA 9.566
740+
## 2024-01-25 10.193 7.997 9.271 NA 9.276
741+
## 2024-01-26 NA 9.639 9.490 10.193 9.257
742+
## 2024-01-27 NA 9.816 11.021 10.293 8.640
743+
## 2024-01-28 8.480 9.499 10.090 NA 9.282
739744
##
740745
## $Technology
741746
## QCOM US CSCO US 700 HK IBM US INTC US
742-
## 2024-01-23 NA 11.181 NA NA NA
743-
## 2024-01-24 8.594 10.713 11.448 NA NA
744-
## 2024-01-25 NA 10.921 NA 9.858 NA
745-
## 2024-01-26 NA 11.670 8.108 NA 11.79
746-
## 2024-01-27 NA 8.647 NA 10.850 NA
747+
## 2024-01-24 10.359 NA NA 10.176 NA
748+
## 2024-01-25 9.580 9.816 10.665 NA NA
749+
## 2024-01-26 9.866 8.873 NA NA 12.175
750+
## 2024-01-27 9.097 8.878 10.444 NA NA
751+
## 2024-01-28 11.324 12.062 10.415 NA NA
747752
##
748753
## $Indices
749754
## DJI DJUSFN W1TEC
750-
## 2024-01-23 12.122 NA NA
751-
## 2024-01-25 NA 11.06 NA
752-
## 2024-01-26 10.197 NA NA
753-
## 2024-01-27 NA NA 8.158</code></pre>
755+
## 2024-01-24 11.201 NA NA
756+
## 2024-01-25 10.221 NA 8.822
757+
## 2024-01-27 NA 11.246 NA
758+
## 2024-01-28 10.328 NA NA</code></pre>
754759
<p>Note:</p>
755760
<ul>
756761
<li><p>The name of the securities tickers is stored without the security
@@ -970,8 +975,11 @@ <h2>Example</h2>
970975
<pre><code>## Loading MSFT US Equity</code></pre>
971976
<pre><code>## Loading AMZN US Equity</code></pre>
972977
<pre><code>## MSFT US AMZN US
973-
## 2024-01-24 11.636 NA
974-
## 2024-01-25 10.139 9.212</code></pre>
978+
## 2024-01-24 10.194 9.116
979+
## 2024-01-25 NA 11.541
980+
## 2024-01-26 11.037 10.817
981+
## 2024-01-27 10.112 10.578
982+
## 2024-01-28 NA 11.128</code></pre>
975983
<pre class="r"><code>br.close(con) # Use the token to release the connection</code></pre>
976984
</div>
977985
<div id="see-also" class="section level2">

src/br-libs/bloomr-bbg.md

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "BloomR Bloomberg Functions"
33
author: "Antonio Fasano"
4-
date: "Jan 28, 2024"
4+
date: "Jan 29, 2024"
55
---
66

77
R topics documented:
@@ -273,6 +273,17 @@ data=br.bulk.csv(con, "mybloomr/tickers.csv")
273273
## Processing Financial ...
274274
```
275275

276+
```
277+
##
278+
## Attaching package: 'zoo'
279+
```
280+
281+
```
282+
## The following objects are masked from 'package:base':
283+
##
284+
## as.Date, as.Date.numeric
285+
```
286+
276287
```
277288
## Loading 3988 HK Equity
278289
```
@@ -345,27 +356,27 @@ data
345356

346357
```
347358
## $Financial
348-
## 3988 HK C US 601288 CH BAC US HSBA LN
349-
## 2024-01-23 10.699 10.934 NA 9.724 NA
350-
## 2024-01-24 10.751 8.299 NA 10.803 8.682
351-
## 2024-01-25 NA 9.134 8.952 9.180 NA
352-
## 2024-01-26 NA NA NA 9.616 NA
353-
## 2024-01-27 NA 9.547 NA NA NA
359+
## 3988 HK C US 601288 CH BAC US HSBA LN
360+
## 2024-01-24 11.422 9.112 7.893 NA 9.566
361+
## 2024-01-25 10.193 7.997 9.271 NA 9.276
362+
## 2024-01-26 NA 9.639 9.490 10.193 9.257
363+
## 2024-01-27 NA 9.816 11.021 10.293 8.640
364+
## 2024-01-28 8.480 9.499 10.090 NA 9.282
354365
##
355366
## $Technology
356367
## QCOM US CSCO US 700 HK IBM US INTC US
357-
## 2024-01-23 NA 11.181 NA NA NA
358-
## 2024-01-24 8.594 10.713 11.448 NA NA
359-
## 2024-01-25 NA 10.921 NA 9.858 NA
360-
## 2024-01-26 NA 11.670 8.108 NA 11.79
361-
## 2024-01-27 NA 8.647 NA 10.850 NA
368+
## 2024-01-24 10.359 NA NA 10.176 NA
369+
## 2024-01-25 9.580 9.816 10.665 NA NA
370+
## 2024-01-26 9.866 8.873 NA NA 12.175
371+
## 2024-01-27 9.097 8.878 10.444 NA NA
372+
## 2024-01-28 11.324 12.062 10.415 NA NA
362373
##
363374
## $Indices
364375
## DJI DJUSFN W1TEC
365-
## 2024-01-23 12.122 NA NA
366-
## 2024-01-25 NA 11.06 NA
367-
## 2024-01-26 10.197 NA NA
368-
## 2024-01-27 NA NA 8.158
376+
## 2024-01-24 11.201 NA NA
377+
## 2024-01-25 10.221 NA 8.822
378+
## 2024-01-27 NA 11.246 NA
379+
## 2024-01-28 10.328 NA NA
369380
```
370381

371382
Note:
@@ -701,8 +712,11 @@ br.bulk.tiks(con, c("MSFT US", "AMZN US"), addtype=TRUE)
701712

702713
```
703714
## MSFT US AMZN US
704-
## 2024-01-24 11.636 NA
705-
## 2024-01-25 10.139 9.212
715+
## 2024-01-24 10.194 9.116
716+
## 2024-01-25 NA 11.541
717+
## 2024-01-26 11.037 10.817
718+
## 2024-01-27 10.112 10.578
719+
## 2024-01-28 NA 11.128
706720
```
707721

708722
```r

src/br-libs/bloomr-bbg.pdf

245 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)