Site icon R-bloggers

A New Package for the African Stock Market {BRVM}

[This article was first published on Steve's Data Tips and Tricks, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

BRVM

< section id="introduction" class="level1">

Introduction

This R package provides a user-friendly interface for accessing data from the {BRVM}, which is a regional stock exchange serving multiple West African countries. With this package, users can easily retrieve historical stock price data, trading volumes, and other financial indicators for a variety of stocks traded on the BRVM.

The package is designed to simplify the process of gathering and analyzing financial data, making it easier for researchers, investors, and other users to extract insights and make informed decisions based on the information available. Overall, BRVM library is a valuable tool for anyone looking to gain a better understanding of the BRVM and the financial markets in West Africa.

For now, you can install from GitHub until it is on CRAN (It is on the way)

# github dev version
## We can use devtools
# install.packages("devtools")
devtools::install_github("Koffi-Fredysessie/BRVM")

# Or use remotes
# install.packages("remotes")
remotes::install_github("Koffi-Fredysessie/BRVM")
< section id="examples" class="level1">

Examples

First, let’s load in the BRVM package:

library(BRVM)
< section id="the-brvm_ticker_desc-function" class="level2">

The BRVM_ticker_desc() function

It receives no argument and returns BRVM tickers information such as its full name, sector and country.

# Display tickers of BRVM
tickers <- BRVM_ticker_desc()
tickers
Warning: package 'kableExtra' was built under R version 4.2.3
Ticker Company name Sector Country
ABJC SERVAIR ABIDJAN COTE D’IVOIRE DISTRIBUTION IVORY COAST
BICC BICI COTE D’IVOIRE FINANCE IVORY COAST
BNBC BERNABE COTE D’IVOIRE DISTRIBUTION IVORY COAST
BOAB BANK OF AFRICA BENIN FINANCE BENIN
BOABF BANK OF AFRICA BURKINA FASO FINANCE BURKINA FASO
BOAC BANK OF AFRICA COTE D’IVOIRE FINANCE IVORY COAST
BOAM BANK OF AFRICA MALI FINANCE MALI
BOAN BANK OF AFRICA NIGER FINANCE NIGER
BOAS BANK OF AFRICA SENEGAL FINANCE SENEGAL
CABC SICABLE COTE D’IVOIRE INDUSTRY IVORY COAST
CBIBF CORIS BANK INTERNATIONAL BURKINA FASO FINANCE BURKINA FASO
CFAC CFAO MOTORS COTE D’IVOIRE DISTRIBUTION IVORY COAST
CIEC CIE COTE D’IVOIRE PUBLIC SERVICE IVORY COAST
ECOC ECOBANK COTE D’IVOIRE FINANCE IVORY COAST
ETIT Ecobank Transnational Incorporated TOGO FINANCE TOGO
FTSC FILTISAC COTE D’IVOIRE INDUSTRY IVORY COAST
NEIC NEI-CEDA COTE D’IVOIRE INDUSTRY IVORY COAST
NSBC NSIA BANQUE COTE D’IVOIRE FINANCE IVORY COAST
NTLC NESTLE COTE D’IVOIRE INDUSTRY IVORY COAST
ONTBF ONATEL BURKINA FASO PUBLIC SERVICE BURKINA FASO
ORAC ORANGE COTE D’IVOIRE PUBLIC SERVICE IVORY COAST
ORGT ORAGROUP TOGO FINANCE TOGO
PALC PALM COTE D’IVOIRE AGRICULTURE IVORY COAST
PRSC TRACTAFRIC MOTORS COTE D’IVOIRE DISTRIBUTION IVORY COAST
SAFC SAFCA COTE D’IVOIRE FINANCE IVORY COAST
SCRC SUCRIVOIRE COTE D’IVOIRE AGRICULTURE IVORY COAST
SDCC SODE COTE D’IVOIRE PUBLIC SERVICE IVORY COAST
SDSC BOLLORE TRANSPORT & LOGISTICS COTE D’IVOIRE TRANSPORT IVORY COAST
SEMC CROWN SIEM COTE D’IVOIRE INDUSTRY IVORY COAST
SGBC SOCIETE GENERALE COTE D’IVOIRE FINANCE IVORY COAST
SHEC VIVO ENERGY COTE D’IVOIRE DISTRIBUTION IVORY COAST
SIBC SOCIETE IVOIRIENNE DE BANQUE COTE D’IVOIRE FINANCE IVORY COAST
SICC SICOR COTE D’IVOIRE AGRICULTURE IVORY COAST
SIVC AIR LIQUIDE COTE D’IVOIRE INDUSTRY IVORY COAST
SLBC SOLIBRA COTE D’IVOIRE INDUSTRY IVORY COAST
SMBC SMB COTE D’IVOIRE INDUSTRY IVORY COAST
SNTS SONATEL SENEGAL PUBLIC SERVICE SENEGAL
SOGC SOGB COTE D’IVOIRE AGRICULTURE IVORY COAST
SPHC SAPH COTE D’IVOIRE AGRICULTURE IVORY COAST
STAC SETAO COTE D’IVOIRE OTHER IVORY COAST
STBC SITAB COTE D’IVOIRE INDUSTRY IVORY COAST
SVOC MOVIS COTE D’IVOIRE TRANSPORT IVORY COAST
TTLC TOTAL COTE D’IVOIRE DISTRIBUTION IVORY COAST
TTLS TOTAL SENEGAL DISTRIBUTION SENEGAL
TTRC TRITURAF Ste en Liquid INDUSTRY IVORY COAST
UNLC UNILEVER COTE D’IVOIRE INDUSTRY IVORY COAST
UNXC UNIWAX COTE D’IVOIRE INDUSTRY IVORY COAST
< section id="the-brvm_index-function" class="level2">

The BRVM_index() function :

It receives no argument and returns a table of updated data (with as table header: indexes, previous closing, closing, change (%), Year to Date Change) on all the indices available on the BRVM exchange.

Indexes Previous closing Closing Change (%) Year to Date Change
BRVM-30 99.71 99.75 0.04 0.00
BRVM – AGRICULTURE 281.76 281.25 -0.18 -0.66
BRVM – OTHER SECTOR 1295.58 1357.27 4.76 -7.32
BRVM – COMPOSITE 199.37 199.46 0.05 0.85
BRVM – DISTRIBUTION 346.02 345.33 -0.20 0.69
BRVM – FINANCE 74.53 75.03 0.67 -0.66
BRVM – INDUSTRY 98.33 98.10 -0.23 0.92
BRVM – PRESTIGE 102.61 102.56 -0.05 0.00
BRVM – PRINCIPAL 94.56 94.62 0.06 0.00
BRVM – PUBLIC SERVICES 480.97 479.60 -0.28 2.23
BRVM – TRANSPORT 345.28 341.70 -1.04 0.35
< section id="the-brvm_get.symbol-.from-.to-function" class="level2">

The BRVM_get(“.symbol”, “.from”, “.to”) function

This function will get the data of the companies listed on the BVRM stock exchange in Rich Bourse website. The function takes a single parameter, .symbol (which represents the “Ticker”). The function will automatically format tickers you enter in uppercase using toupper() and then ensure that the passed ticker is in a Google spreadsheet of allowed tickers.

#' Displaying data of SONATEL Senegal stock
BRVM_get(.symbol = "snts")
[1] "SNTS"
# A tibble: 251 × 6
   Date        Open  High   Low Close Volume
   <date>     <dbl> <dbl> <dbl> <dbl>  <dbl>
 1 2022-04-06 15800 15895 15750 15800   7436
 2 2022-04-07 15800 15900 15750 15900   1265
 3 2022-04-08 15900 15995 15800 15900   1164
 4 2022-04-11 15895 15900 15800 15800   4252
 5 2022-04-12 15800 15800 15780 15800   6561
 6 2022-04-13 15800 15865 15795 15850   5409
 7 2022-04-14 15855 15900 15850 15900  16957
 8 2022-04-15 15995 15995 15900 15900    791
 9 2022-04-19 15900 15995 15895 15900  31217
10 2022-04-20 15900 15995 15895 15990  32322
# ℹ 241 more rows
symbols <- c("BiCc","XOM","SlbC")   # We use here three tickers
data_tbl <- BRVM_get(.symbol = symbols, .from = "2020-01-01", .to = Sys.Date() - 1)
[1] "BICC" "SLBC"
# Display the first twenty observations of the table
head(data_tbl, 20)
# A tibble: 20 × 7
   Date        Open  High   Low Close Volume Ticker
   <date>     <dbl> <dbl> <dbl> <dbl>  <dbl> <chr> 
 1 2020-01-10  6500  6500  6500  6500     24 BICC  
 2 2020-01-13  6370  6500  6370  6500     29 BICC  
 3 2020-01-14  6495  6495  6495  6495     10 BICC  
 4 2020-01-29  6010  6010  6010  6010     24 BICC  
 5 2020-01-30  6000  6000  6000  6000     50 BICC  
 6 2020-02-04  5800  5800  5800  5800     12 BICC  
 7 2020-02-07  5650  5650  5650  5650      5 BICC  
 8 2020-02-10  5500  5500  5500  5500      5 BICC  
 9 2020-02-14  5300  5300  5300  5300      9 BICC  
10 2020-02-17  4910  4910  4910  4910    210 BICC  
11 2020-02-18  4910  4910  4910  4910     50 BICC  
12 2020-02-20  4895  4895  4895  4895      5 BICC  
13 2020-02-21  4895  4895  4890  4890     13 BICC  
14 2020-02-25  4525  4525  4525  4525     16 BICC  
15 2020-02-26  4435  4435  4430  4430     21 BICC  
16 2020-02-27  4345  4760  4335  4760   1809 BICC  
17 2020-03-03  4745  4750  4745  4750     11 BICC  
18 2020-03-05  4700  4700  4700  4700      5 BICC  
19 2020-03-06  4695  4695  4695  4695      6 BICC  
20 2020-03-11  4345  4450  4345  4450    135 BICC  
# Display the last twenty elements of the table
tail(data_tbl, 20)
# A tibble: 20 × 7
   Date        Open  High   Low Close Volume Ticker
   <date>     <dbl> <dbl> <dbl> <dbl>  <dbl> <chr> 
 1 2023-02-15 80000 80000 79000 79000      2 SLBC  
 2 2023-02-17 78000 78000 78000 78000      5 SLBC  
 3 2023-02-21 80000 80000 80000 80000      5 SLBC  
 4 2023-02-23 80000 80000 80000 80000     18 SLBC  
 5 2023-02-24 80000 80000 80000 80000      6 SLBC  
 6 2023-02-27 80000 80000 80000 80000     98 SLBC  
 7 2023-02-28 80000 80000 80000 80000     11 SLBC  
 8 2023-03-02 80000 80000 80000 80000     11 SLBC  
 9 2023-03-08 80000 80000 80000 80000      2 SLBC  
10 2023-03-09 80000 80000 80000 80000      2 SLBC  
11 2023-03-13 80005 80005 80000 80000     12 SLBC  
12 2023-03-14 80000 80000 80000 80000      1 SLBC  
13 2023-03-20 80000 80000 80000 80000      3 SLBC  
14 2023-03-21 80000 80000 80000 80000      4 SLBC  
15 2023-03-27 78000 80000 78000 80000    169 SLBC  
16 2023-03-28 80000 80000 80000 80000    435 SLBC  
17 2023-03-30 80000 80000 80000 80000      3 SLBC  
18 2023-03-31 80000 80000 80000 80000      1 SLBC  
19 2023-04-04 80000 86000 80000 86000      3 SLBC  
20 2023-04-05 85950 86000 85950 86000      6 SLBC  
< section id="the-brvm_get1ticker-period-from-to-function" class="level2">

The BRVM_get1(“ticker”, “Period”, “from”, “to”) function

This function will get data of the companies listed on the BVRM stock exchange through the sikafinance site. The function takes in a single parameter of ticker and will auto-format the tickers you input into all upper case by using toupper()

** NB : There is a small difference between the BRVM_get and BRVM_get1 functions. * With BRVM_get it is only possible to download tickers’ daily data. * But with BRVM_get1, you can download daily, weekly, monthly, annual tickers’ data, indices and even market capitalization.

#' Displaying data of SONATEL Senegal stock
BRVM_get1("snts")
[1] "Make sure you have an active internet connection"
# Get daily data of all indexes
all_ind <- BRVM_get1("ALL INDEXES", Period = 0, from = "2020-01-04", to = "2023-03-24") 
[1] "We obtained BRVM10 data from 2019-12-26 to 2023-01-04"
[1] "We obtained BRVMAG data from 2019-12-26 to 2023-03-24"
[1] "We obtained BRVMC data from 2019-12-26 to 2023-03-24"
[1] "We obtained BRVMAS data from 2019-12-26 to 2023-03-24"
[1] "We obtained BRVMDI data from 2019-12-26 to 2023-03-24"
[1] "We obtained BRVMFI data from 2019-12-26 to 2023-03-24"
[1] "We obtained BRVMIN data from 2019-12-26 to 2023-03-24"
[1] "We obtained BRVMSP data from 2019-12-26 to 2023-03-24"
[1] "We obtained BRVMTR data from 2019-12-26 to 2023-03-24"
[1] "We obtained BRVMPR data from 2023-01-01 to 2023-03-24"
[1] "We obtained BRVMPA data from 2023-01-04 to 2023-03-24"
[1] "We obtained BRVM30 data from 2023-01-01 to 2023-03-24"
[1] "We obtained CAPIB data from 2020-01-02 to 2023-03-24"
# display the first two tens elements of the table
head(all_ind, 20)
# A tibble: 20 × 7
   Date        Open  High   Low Close Volume Ticker
   <date>     <dbl> <dbl> <dbl> <dbl>  <dbl> <chr> 
 1 2022-12-26  169.  169.  169.  169.      0 BRVM10
 2 2022-12-27  169.  169.  169.  169.      0 BRVM10
 3 2022-12-28  167.  167.  167.  167.      0 BRVM10
 4 2022-12-29  167.  167.  167.  167.      0 BRVM10
 5 2022-12-30  166.  166.  166.  166.      0 BRVM10
 6 2023-01-02  166.  166.  166.  166.      0 BRVM10
 7 2023-01-03  166.  166.  166.  166.      0 BRVM10
 8 2023-01-04  166.  166.  166.  166.      0 BRVM10
 9 2022-09-26  163.  163.  163.  163.      0 BRVM10
10 2022-09-27  162.  162.  162.  162.      0 BRVM10
11 2022-09-28  162.  162.  162.  162.      0 BRVM10
12 2022-09-29  163.  163.  163.  163.      0 BRVM10
13 2022-09-30  164.  164.  164.  164.      0 BRVM10
14 2022-10-03  162.  162.  162.  162.      0 BRVM10
15 2022-10-04  162.  162.  162.  162.      0 BRVM10
16 2022-10-05  161.  161.  161.  161.      0 BRVM10
17 2022-10-06  161.  161.  161.  161.      0 BRVM10
18 2022-10-07  161.  161.  161.  161.      0 BRVM10
19 2022-10-10  160.  160.  160.  160.      0 BRVM10
20 2022-10-11  160.  160.  160.  160.      0 BRVM10
# display the two tens of the last elements of the table
tail(all_ind, 20)
# A tibble: 20 × 7
   Date          Open    High     Low   Close Volume Ticker
   <date>       <dbl>   <dbl>   <dbl>   <dbl>  <dbl> <chr> 
 1 2020-02-26 4281311 4281311 4281311 4281311      0 CAPIB 
 2 2020-02-27 4314933 4314933 4314933 4314933      0 CAPIB 
 3 2020-02-28 4346515 4346515 4346515 4346515      0 CAPIB 
 4 2020-03-02 4424073 4424073 4424073 4424073      0 CAPIB 
 5 2020-03-03 4379647 4379647 4379647 4379647      0 CAPIB 
 6 2020-03-04 4369550 4369550 4369550 4369550      0 CAPIB 
 7 2020-03-05 4342229 4342229 4342229 4342229      0 CAPIB 
 8 2020-03-06 4359879 4359879 4359879 4359879      0 CAPIB 
 9 2020-03-09 4338293 4338293 4338293 4338293      0 CAPIB 
10 2020-03-10 4357221 4357221 4357221 4357221      0 CAPIB 
11 2020-03-11 4332656 4332656 4332656 4332656      0 CAPIB 
12 2020-03-12 4318096 4318096 4318096 4318096      0 CAPIB 
13 2020-03-13 4318112 4318112 4318112 4318112      0 CAPIB 
14 2020-03-16 4285184 4285184 4285184 4285184      0 CAPIB 
15 2020-03-17 4301727 4301727 4301727 4301727      0 CAPIB 
16 2020-03-18 4288582 4288582 4288582 4288582      0 CAPIB 
17 2020-03-19 4207231 4207231 4207231 4207231      0 CAPIB 
18 2020-03-20 4209788 4209788 4209788 4209788      0 CAPIB 
19 2020-03-23 4154445 4154445 4154445 4154445      0 CAPIB 
20 2020-03-24 4144325 4144325 4144325 4144325      0 CAPIB 
# To get yearly data
yearly_data <- BRVM_get1(c("brvmtr", "BiCc", "BOAS"), Period = 365 ) 
# display the first two tens elements of the table
head(yearly_data, 20) 
# A tibble: 20 × 6
   Date         Open   High    Low  Close Ticker
   <date>      <dbl>  <dbl>  <dbl>  <dbl> <chr> 
 1 2003-04-11   74.0   88.6   73.6   88.6 BRVMTR
 2 2004-01-02   88.6   89.2   72.9   89.2 BRVMTR
 3 2005-01-03   89.2  107.    70.7  104.  BRVMTR
 4 2006-01-02  104.   158.   104.   153.  BRVMTR
 5 2007-01-02  153.   275.   149.   249.  BRVMTR
 6 2008-01-02  249.   386.   226.   296.  BRVMTR
 7 2009-01-02  275.   296.   227.   236.  BRVMTR
 8 2010-01-04  236.   259.   224.   238.  BRVMTR
 9 2011-01-03  238.   249.   204.   239   BRVMTR
10 2012-01-02  239    349.   201.   349.  BRVMTR
11 2013-01-02  349.   794.   339.   789.  BRVMTR
12 2014-01-02  789.  1213.   601.  1213.  BRVMTR
13 2015-01-02 1213.  1525.   653.  1525.  BRVMTR
14 2016-01-04 1525.  1525.  1216.  1432.  BRVMTR
15 2017-01-02 1432.  1433.   764.  1203.  BRVMTR
16 2018-01-02 1114.  1193.   966.   966.  BRVMTR
17 2019-06-03  403.   429.   311.   367.  BRVMTR
18 2020-01-01  367.   475.   292.   379.  BRVMTR
19 2021-01-04  376.   622.   325    622.  BRVMTR
20 2022-01-03  667.   667.   295.   342.  BRVMTR
# display the two tens of the last elements of the table
tail(yearly_data, 20) 
# A tibble: 20 × 6
   Date        Open  High   Low Close Ticker
   <date>     <dbl> <dbl> <dbl> <dbl> <chr> 
 1 2014-01-02  5650  7848  5650  7800 BICC  
 2 2015-01-02  8385 10750  7800 10100 BICC  
 3 2016-01-04 10000 10700  8566  9890 BICC  
 4 2017-01-05  9750 10000  6440  8490 BICC  
 5 2018-01-02  8700  8750  3795  7900 BICC  
 6 2019-01-04  7550  7550  3710  6800 BICC  
 7 2020-01-01  6800  6890  2855  6680 BICC  
 8 2021-01-04  6680  7525  4280  7400 BICC  
 9 2022-01-03  7250  7250  5550  6850 BICC  
10 2023-01-02  6500  6850  5785  6275 BICC  
11 2014-12-10  1613  3225  1613  3225 BOAS  
12 2015-01-02  3370  4300  2900  3950 BOAS  
13 2016-01-04  3700  4101  2000  2350 BOAS  
14 2017-01-02  2325  3875  2035  2500 BOAS  
15 2018-01-02  2400  3250  1700  2020 BOAS  
16 2019-01-02  1900  2000  1500  1545 BOAS  
17 2020-01-01  1550  1700  1295  1495 BOAS  
18 2021-01-04  1480  2750  1340  2350 BOAS  
19 2022-01-03  2350  2780  2200  2450 BOAS  
20 2023-01-02  2580  2585  2175  2265 BOAS  
< section id="the-brvm.index-function" class="level2">

The BRVM.index() function :

It receives no argument and returns the name of all indexes available on BRVM Stock Exchange.

BRVM.index()
 [1] "BRVMAG" "BRVMC"  "BRVMAS" "BRVMDI" "BRVMFI" "BRVMIN" "BRVMSP" "BRVMTR"
 [9] "BRVMPR" "BRVMPA" "BRVM30"

Authors :

Creator : Koffi Frederic Sessie

cph (Copyright Holder) : Koffi Frederic Sessie

License : MIT 2023, BRVM authors. All rights reserved.

To leave a comment for the author, please follow the link and comment on their blog: Steve's Data Tips and Tricks.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version