New R package: GetCVMData
2020-07-18: Package GetCVMData is now named GetDFPData2. See this post for details. The old code in GetCVMData
is still in Github but will no longer be developed.
Package GetCVMData
is an alternative to GetDFPData
. Both have the same objective: fetch corporate data of Brazilian companies trading at B3, but diverge in their source. While GetDFPData
imports data directly from the DFP and FRE systems, GetCVMData
uses the CVM ftp site for grabbing compiled .csv files.
When doing large scale importations, GetDFPData
fells sluggish due to the parsing of large xml files. As an example, building the dataset available in my data page takes around six hours of execution using 10 cores of my home computer.
GetCVMData
is lean and fast. Since the data is already parsed in csv files, all the code does is organize the files, download and read. For comparison, all DFP documents, annual financial reports, available in CVM can be imported in less than 1 minute. Additionally, GetCVMData
can also parse ITR (quarterly) data, which was not available in GetDFPData
.
However, be aware that the output data is not the same. I kept all original column names from CVM and some information, such as tickers, are not available in GetCVMData
.
Here’s an example of usage:
if (!require(devtools)) install.packages('devtools')
if (!require(GetCVMData)) devtools::install_github('msperlin/GetCVMData') # not in CRAN yet
library(GetCVMData)
library(tidyverse)
# fetch information about companies
df_info <- get_info_companies()
# search for companies
df_search <- search_company('odontoprev')
# DFP annual data
id_cvm <- df_search$CD_CVM[1] # use NULL for all companies
df_dfp <- get_dfp_data(companies_cvm_codes = id_cvm,
first_year = 2015,
last_year = 2019,
type_docs = c('DRE', 'BPA', 'BPP'), # income, assets, liabilities
type_format = 'con' # consolidated statements
)
glimpse(df_dfp)
# ITR quarterly data
df_itr <- get_itr_data(companies_cvm_codes = id_cvm,
first_year = 2010,
last_year = 2020,
type_docs = c('DRE', 'BPA', 'BPP'), # income, assets, liabilities
type_format = 'con' # consolidated statements
)
glimpse(df_itr)
# FRE data (not yet implemented..)
#df_fre <- get_fre_data()
Lets plot the quarterly profit of df_itr$DENOM_CIA[1]
:
library(tidyverse)
quarterly_profits <- df_itr %>%
filter(GRUPO_DFP == 'DF Consolidado - Demonstração do Resultado',
DS_CONTA == 'Lucro/Prejuízo Consolidado do Período')
# plot it
p <- ggplot(quarterly_profits, aes(x = DT_FIM_EXERC, y = VL_CONTA)) +
geom_col() +
theme_bw() +
labs(title = paste0('Quarterly profits of ', quarterly_profits$DENOM_CIA[1]),
caption = 'Data from CVM',
x = '',
y = 'Consolidade Profits')
p