knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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)
The function rb3::indexes_get
list the names of available indexes.
indexes_get()
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")
The IBr100 Index (IBXX
)
index_weights_get("IBXX")
The Small Caps Index (SMLL
)
index_weights_get("SMLL")
rb3::index_comp_get
returns a vector with symbols that compound the given index.
index_comp_get("SMLL")
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")
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)
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") )
rb3::indexes_last_update
returns the date where the indexes have been last updated.
indexes_last_update()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.