<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/package-getdfpdata/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://msperlin.github.io/2017-12-06-_Package-GetDFPData/"> R and Finance</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p> Downloading Annual Financial Reports and Corporate Events from B3 (formerly Bovespa) – </p>
<p>Financial statements of companies traded at B3 (formerly Bovespa), the<br>
Brazilian stock exchange, are available in its<br>
<a rel="nofollow" href="http://www.bmfbovespa.com.br/" target="_blank">website</a>. Accessing the data for a<br>
single company is straightforward. In the website one can find a simple<br>
interface for accessing this dataset. An example is given<br>
<a rel="nofollow" href="https://www.rad.cvm.gov.br/ENETCONSULTA/frmGerenciaPaginaFRE.aspx?NumeroSequencialDocumento=67775&CodigoTipoInstituicao=2" target="_blank">here</a>.<br>
However, gathering and organizing the data for a large scale research,<br>
with many companies and many dates, is painful. Financial reports must<br>
be downloaded or copied individually and later aggregated. Changes in<br>
the accounting format thoughout time can make this process slow,<br>
unreliable and irreproducible.</p>
<p>Package <code>GetDFPData</code> provides a R interface to all annual financial<br>
statements available in the website and more. It not only downloads the<br>
data but also organizes it in a tabular format and allows the use of<br>
inflation indexes. Users can select companies and a time period to<br>
download all available data. Several information about current<br>
companies, such as sector and available quarters are also at reach. The<br>
main purpose of the package is to make it easy to access financial<br>
statements in large scale research, facilitating the reproducibility of<br>
corporate finance studies with B3 data.</p>
<p>The positive aspects of <code>GetDFDData</code> are:</p>
<ul>
<li>Easy and simple R and web interface</li>
<li>Changes in accounting format are internally handled by the software</li>
<li>Access to corporate events in the FRE system such as dividend<br>
payments, changes in stock holder composition, changes in governance<br>
listings, board composition and compensation, debt composition, and<br>
a lot more!</li>
<li>The output data is automatically organized using tidy data<br>
principles (long format)</li>
<li>A cache system is employed for fast data acquisition</li>
<li>Completely free and open source!</li>
</ul>
<h1>Installation</h1>
<p>The package is (not yet) available in CRAN (release version) and in<br>
Github (development version). You can install any of those with the<br>
following code:</p>
<div>
<div>
<pre><code># Release version in CRAN
install.packages('GetDFPData') # not in CRAN yet

# Development version in Github
devtools::install_github('msperlin/GetDFPData')
</code></pre>
</div>
</div>
<h1>Shinny interface</h1>
<p>The web interface of <code>GetDFPData</code> is available at<br>
<a rel="nofollow" href="http://www.msperlin.com/shiny/GetDFPData/" target="_blank">http://www.msperlin.com/shiny/GetDFPData/</a>.</p>
<h1>How to use <code>GetDFPData</code></h1>
<p>The starting point of <code>GetDFPData</code> is to find the official names of<br>
companies in B3. Function <code>gdfpd.search.company</code> serves this purpose.<br>
Given a string (text), it will search for a partial matches in companies<br>
names. As an example, let’s find the <em>official</em> name of Petrobras, one<br>
of the largest companies in Brazil:</p>
<div>
<div>
<pre><code>library(GetDFPData)
library(tibble)

gdfpd.search.company('petrobras',cache.folder = tempdir())

## 
## Reading info file from github
## Found 43873 lines for 687 companies  [Actives =  521  Inactives =  167 ]
## Last file update:  2017-10-19
## Caching RDATA into tempdir()
## 
## Found 1 companies:
## PETRÓLEO BRASILEIRO  S.A.  - PETROBRAS | situation = ATIVO | first date = 1998-12-31 | last date - 2016-12-31

## [1] &quot;PETRÓLEO BRASILEIRO  S.A.  - PETROBRAS&quot;
</code></pre>
</div>
</div>
<p>Its official name in Bovespa records is<br>
<code>PETRÓLEO BRASILEIRO  S.A.  - PETROBRAS</code>. Data for quarterly and annual<br>
statements are available from 1998 to 2017. The situation of the<br>
company, active or canceled, is also given. This helps verifying the<br>
availability of data.</p>
<p>The content of all available financial statements can be accessed with<br>
function <code>gdfpd.get.info.companies</code>. It will read and parse a .csv file<br>
from my <a rel="nofollow" href="https://github.com/msperlin/GetDFPData_auxiliary" target="_blank">github<br>
repository</a>. This will<br>
be periodically updated for new information. Let’s try it out:</p>
<div>
<div>
<pre><code>df.info &lt;- gdfpd.get.info.companies(type.data = 'companies', cache.folder = tempdir())

## 
## Reading info file from github
## Found 43873 lines for 687 companies  [Actives =  521  Inactives =  167 ]
## Last file update:  2017-10-19
## Caching RDATA into tempdir()

glimpse(df.info)

## Observations: 689
## Variables: 8
## $ name.company    </code></pre></div></div>