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

B3 Indexes

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

indexes_get()
#>  [1] "AGFS" "BDRX" "GPTW" "IBOV" "IBRA" "IBXL" "IBXX" "ICO2" "ICON" "IDIV"
#> [11] "IEEX" "IFIL" "IFIX" "IFNC" "IGCT" "IGCX" "IGNM" "IMAT" "IMOB" "INDX"
#> [21] "ISEE" "ITAG" "IVBX" "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.0295  4394245879
#>  2 ALPA4  0.00089  208965950
#>  3 ALSO3  0.00593  532616595
#>  4 ARZZ3  0.00222   62305891
#>  5 ASAI3  0.00775 1349645897
#>  6 AZUL4  0.00237  327593725
#>  7 B3SA3  0.0358  5694552584
#>  8 BBAS3  0.0326  1420949112
#>  9 BBDC3  0.00959 1500728902
#> 10 BBDC4  0.0373  5146576868
#> # ℹ 76 more rows

The IBr100 Index (IBXX)

index_weights_get("IBXX")
#> # A tibble: 100 × 3
#>    symbol  weight   position
#>    <chr>    <dbl>      <dbl>
#>  1 ABEV3  0.0283  4394245879
#>  2 ALPA4  0.00086  208965950
#>  3 ALSO3  0.00568  532616595
#>  4 ARZZ3  0.00213   62305891
#>  5 ASAI3  0.00743 1349645897
#>  6 AURE3  0.00195  301966319
#>  7 AZUL4  0.00227  327593725
#>  8 B3SA3  0.0343  5694552584
#>  9 BBAS3  0.0313  1420949112
#> 10 BBDC3  0.00919 1500728902
#> # ℹ 90 more rows

The Small Caps Index (SMLL)

index_weights_get("SMLL")
#> # A tibble: 117 × 3
#>    symbol  weight  position
#>    <chr>    <dbl>     <dbl>
#>  1 AALR3  0.00015   5721492
#>  2 ABCB4  0.00423  66485201
#>  3 AERI3  0.00071 214066952
#>  4 AESB3  0.0122  317103937
#>  5 AGRO3  0.00498  59736251
#>  6 ALPA4  0.00629 208965950
#>  7 ALSO3  0.0417  532616595
#>  8 ALUP11 0.0142  145652351
#>  9 AMBP3  0.00321  43853759
#> 10 ANIM3  0.00333 256834750
#> # ℹ 107 more rows

Index Composition

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

index_comp_get("SMLL")
#>   [1] "AALR3"  "ABCB4"  "AERI3"  "AESB3"  "AGRO3"  "ALPA4"  "ALSO3"  "ALUP11"
#>   [9] "AMBP3"  "ANIM3"  "ARML3"  "ARZZ3"  "AZUL4"  "BEEF3"  "BLAU3"  "BMOB3" 
#>  [17] "BPAN4"  "BRAP4"  "BRPR3"  "BRSR6"  "CAML3"  "CASH3"  "CBAV3"  "CEAB3" 
#>  [25] "CIEL3"  "CLSA3"  "COGN3"  "CSMG3"  "CURY3"  "CVCB3"  "CYRE3"  "DASA3" 
#>  [33] "DIRR3"  "DXCO3"  "ECOR3"  "EMBR3"  "ENAT3"  "ESPA3"  "EVEN3"  "EZTC3" 
#>  [41] "FESA4"  "FLRY3"  "FRAS3"  "GFSA3"  "GGPS3"  "GOAU4"  "GOLL4"  "GRND3" 
#>  [49] "GUAR3"  "HBSA3"  "IFCM3"  "IGTI11" "INTB3"  "IRBR3"  "JALL3"  "JHSF3" 
#>  [57] "KEPL3"  "LAVV3"  "LEVE3"  "LJQQ3"  "LOGG3"  "LOGN3"  "LUPA3"  "LWSA3" 
#>  [65] "MATD3"  "MBLY3"  "MEGA3"  "MILS3"  "MLAS3"  "MOVI3"  "MRFG3"  "MRVE3" 
#>  [73] "MYPK3"  "ODPV3"  "ONCO3"  "ORVR3"  "PCAR3"  "PETZ3"  "PGMN3"  "PLPL3" 
#>  [81] "PNVL3"  "POMO4"  "POSI3"  "PTBL3"  "QUAL3"  "RANI3"  "RAPT4"  "RECV3" 
#>  [89] "ROMI3"  "RRRP3"  "SAPR11" "SBFG3"  "SEER3"  "SEQL3"  "SIMH3"  "SLCE3" 
#>  [97] "SMFT3"  "SMTO3"  "SOMA3"  "SQIA3"  "STBP3"  "TAEE11" "TASA4"  "TEND3" 
#> [105] "TGMA3"  "TRIS3"  "TTEN3"  "TUPY3"  "UNIP6"  "USIM5"  "VIIA3"  "VIVA3" 
#> [113] "VLID3"  "VULC3"  "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.0260         0.0260    1.48e9 2023-09-11
#>  2 EMBR3  Bens Indls / Mat Transporte 0.00671        0.00671   7.35e8 2023-09-11
#>  3 AZUL4  Bens Indls/Transporte       0.00222        0.0222    3.28e8 2023-09-11
#>  4 CCRO3  Bens Indls/Transporte       0.00604        0.0222    9.95e8 2023-09-11
#>  5 GOLL4  Bens Indls/Transporte       0.00066        0.0222    1.98e8 2023-09-11
#>  6 RAIL3  Bens Indls/Transporte       0.0133         0.0222    1.22e9 2023-09-11
#>  7 BRFS3  Cons N  Básico / Alimentos… 0.00736        0.0227    1.68e9 2023-09-11
#>  8 JBSS3  Cons N  Básico / Alimentos… 0.0104         0.0227    1.13e9 2023-09-11
#>  9 MRFG3  Cons N  Básico / Alimentos… 0.0011         0.0227    2.93e8 2023-09-11
#> 10 BEEF3  Cons N  Básico / Alimentos… 0.00113        0.0227    2.61e8 2023-09-11
#> # ℹ 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()
#> [1] "2023-09-11"