B3 Indexes

rb3 comes with a diverse range of functions to explore the index delivered by the B3 Exchange. These functions will be presented here.

library(rb3)
library(ggplot2)
library(dplyr)
library(stringr)

B3 Indexes

The function rb3::indexes_get list the names of available indexes.

indexes_get()
#>  [1] "AGFS" "BDRX" "GPTW" "IBBR" "IBEE" "IBEP" "IBHB" "IBLV" "IBOV" "IBRA"
#> [11] "IBSD" "IBXL" "IBXX" "ICO2" "ICON" "IDIV" "IDVR" "IEEX" "IFIL" "IFIX"
#> [21] "IFNC" "IGCT" "IGCX" "IGNM" "IMAT" "IMOB" "INDX" "ISEE" "ITAG" "IVBX"
#> [31] "MLCX" "SMLL" "UTIL"

Indexes Composition and Weights

The composition of B3 indexes are available through the function rb3::index_weights_get. This function returns a data.frame with the current compostion of the requested index, all symbols that compound the index, their weights and theoretical position. Here the IBOVESPA (IBOV) Index has its composition listed.

index_weights_get("IBOV")
#> # A tibble: 86 × 3
#>    symbol  weight   position
#>    <chr>    <dbl>      <dbl>
#>  1 ABEV3  0.0252  4394835131
#>  2 ALOS3  0.0051   502481592
#>  3 ALPA4  0.00057  166460180
#>  4 ASAI3  0.00575 1349687675
#>  5 AURE3  0.00148  291727616
#>  6 AZUL4  0.00079  328421113
#>  7 AZZA3  0.00278  127330493
#>  8 B3SA3  0.0311  5511401013
#>  9 BBAS3  0.0356  2842613858
#> 10 BBDC3  0.00935 1484426957
#> # ℹ 76 more rows

The IBr100 Index (IBXX)

index_weights_get("IBXX")
#> # A tibble: 100 × 3
#>    symbol  weight   position
#>    <chr>    <dbl>      <dbl>
#>  1 ABEV3  0.0237  4394835131
#>  2 ALOS3  0.0048   502481592
#>  3 ALPA4  0.00054  166460180
#>  4 AMBP3  0.00123   41041780
#>  5 ASAI3  0.00541 1349687675
#>  6 AURE3  0.00139  291727616
#>  7 AZUL4  0.00074  328421113
#>  8 AZZA3  0.00262  127330493
#>  9 B3SA3  0.0293  5511401013
#> 10 BBAS3  0.0335  2842613858
#> # ℹ 90 more rows

The Small Caps Index (SMLL)

index_weights_get("SMLL")
#> # A tibble: 119 × 3
#>    symbol  weight  position
#>    <chr>    <dbl>     <dbl>
#>  1 ABCB4  0.00573  73885763
#>  2 AERI3  0.00143  35461088
#>  3 AESB3  0.0121  317101832
#>  4 AGRO3  0.00551  63815593
#>  5 ALOS3  0.0382  502481592
#>  6 ALPA4  0.00427 166460180
#>  7 ALUP11 0.0161  151478409
#>  8 AMBP3  0.00975  41041780
#>  9 ANIM3  0.00281 257040189
#> 10 ARML3  0.00495 171598756
#> # ℹ 109 more rows

Index Composition

rb3::index_comp_get returns a vector with symbols that compound the given index.

index_comp_get("SMLL")
#>   [1] "ABCB4"  "AERI3"  "AESB3"  "AGRO3"  "ALOS3"  "ALPA4"  "ALUP11" "AMBP3" 
#>   [9] "ANIM3"  "ARML3"  "ASAI3"  "AURE3"  "AZEV4"  "AZUL4"  "AZZA3"  "BEEF3" 
#>  [17] "BHIA3"  "BLAU3"  "BMOB3"  "BPAN4"  "BRAP4"  "BRKM5"  "BRSR6"  "CAML3" 
#>  [25] "CASH3"  "CBAV3"  "CEAB3"  "CLSA3"  "COGN3"  "CSMG3"  "CURY3"  "CVCB3" 
#>  [33] "CYRE3"  "DASA3"  "DIRR3"  "DXCO3"  "ECOR3"  "EVEN3"  "EZTC3"  "FESA4" 
#>  [41] "FLRY3"  "FRAS3"  "GFSA3"  "GGPS3"  "GOAU4"  "GRND3"  "GUAR3"  "HBSA3" 
#>  [49] "IGTI11" "INTB3"  "IRBR3"  "JALL3"  "JHSF3"  "JSLG3"  "KEPL3"  "LAVV3" 
#>  [57] "LEVE3"  "LJQQ3"  "LOGG3"  "LWSA3"  "MDIA3"  "MDNE3"  "MGLU3"  "MILS3" 
#>  [65] "MLAS3"  "MOVI3"  "MRFG3"  "MRVE3"  "MTRE3"  "MYPK3"  "ODPV3"  "ONCO3" 
#>  [73] "OPCT3"  "ORVR3"  "PCAR3"  "PETZ3"  "PGMN3"  "PLPL3"  "PNVL3"  "POMO4" 
#>  [81] "PORT3"  "POSI3"  "PTBL3"  "QUAL3"  "RANI3"  "RAPT4"  "RCSL3"  "RECV3" 
#>  [89] "ROMI3"  "RRRP3"  "SAPR11" "SBFG3"  "SEER3"  "SEQL3"  "SIMH3"  "SLCE3" 
#>  [97] "SMFT3"  "SMTO3"  "SOJA3"  "SRNA3"  "STBP3"  "TAEE11" "TASA4"  "TEND3" 
#> [105] "TGMA3"  "TRIS3"  "TTEN3"  "TUPY3"  "UNIP6"  "USIM3"  "USIM5"  "VAMO3" 
#> [113] "VIVA3"  "VLID3"  "VULC3"  "VVEO3"  "WIZC3"  "YDUQ3"  "ZAMP3"

Index by Segment

rb3::index_by_segment_get returns a data.frame with all stocks that are in the index, their economic segment, weights, position and segment weight in the index.

index_by_segment_get("IBOV")
#> # A tibble: 86 × 6
#>    symbol segment                      weight segment_weight position refdate   
#>    <chr>  <chr>                         <dbl>          <dbl>    <dbl> <date>    
#>  1 WEGE3  Bens Indls / Máqs e Equips  0.0335          0.0335   1.27e9 2024-10-24
#>  2 EMBR3  Bens Indls / Mat Transporte 0.0170          0.0170   7.35e8 2024-10-24
#>  3 AZUL4  Bens Indls/Transporte       0.00085         0.0224   3.28e8 2024-10-24
#>  4 CCRO3  Bens Indls/Transporte       0.00561         0.0224   9.92e8 2024-10-24
#>  5 RAIL3  Bens Indls/Transporte       0.0108          0.0224   1.22e9 2024-10-24
#>  6 STBP3  Bens Indls/Transporte       0.00512         0.0224   8.56e8 2024-10-24
#>  7 BRFS3  Cons N  Básico / Alimentos… 0.00932         0.0326   8.15e8 2024-10-24
#>  8 JBSS3  Cons N  Básico / Alimentos… 0.0189          0.0326   1.14e9 2024-10-24
#>  9 MRFG3  Cons N  Básico / Alimentos… 0.00206         0.0326   3.02e8 2024-10-24
#> 10 BEEF3  Cons N  Básico / Alimentos… 0.00068         0.0326   2.61e8 2024-10-24
#> # ℹ 76 more rows

Indexes Time Series

rb3 downloads data from B3 website to build time series for B3 indexes.

The function rb3::index_get downloads data from B3 for the given index name and returns data structured in a data.frame. The index names are obtained with rb3::indexes_get function.

index_name <- "IBOV"
index_data <- index_get(index_name, as.Date("2019-01-01"))
head(index_data)
#> # A tibble: 6 × 3
#>   refdate    index_name   value
#>   <date>     <chr>        <dbl>
#> 1 2019-02-01 IBOV        97861.
#> 2 2019-03-01 IBOV        94604.
#> 3 2019-04-01 IBOV        96054.
#> 4 2019-07-01 IBOV       101340.
#> 5 2019-08-01 IBOV       102126.
#> 6 2019-10-01 IBOV       104053.

The returned data.frame has three columns: refdate, index_name and value.

index_data |>
  ggplot(aes(x = refdate, y = value)) +
  geom_line() +
  labs(
    x = NULL, y = "Index",
    title = str_glue("{index_name} Historical Data"),
    caption = str_glue("Data imported using rb3")
  )

The IBOVESPA index starts at 1968 and the series is adjusted for all economic events the that affected the Brazilian currency in the 80-90’s decades.

index_data <- index_get(index_name, as.Date("1968-01-01"))
index_data |>
  ggplot(aes(x = refdate, y = value)) +
  geom_line() +
  scale_y_log10() +
  labs(
    x = NULL, y = "Index (log scale)",
    title = str_glue("{index_name} Historical Data - since 1968"),
    caption = str_glue("Data imported using rb3")
  )

The y-axis was transformed to log scale in order to get the visualization improved.

Change index_name to get data for other indexes, for example, the Small Caps Index SMLL.

index_name <- "SMLL"
index_data <- index_get(index_name, as.Date("2010-01-01"))
index_data |>
  ggplot(aes(x = refdate, y = value)) +
  geom_line() +
  labs(
    x = NULL, y = "Index",
    title = str_glue("{index_name} Historical Data"),
    caption = str_glue("Data imported using rb3")
  )

Indexes Last Update

rb3::indexes_last_update returns the date where the indexes have been last updated.

indexes_last_update()