Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
meirelesff committed Sep 9, 2018
1 parent 179db39 commit 7a5c79e
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .Rproj.user/E51B518C/sources/prop/69E33048
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cursorPosition" : "35,1",
"cursorPosition" : "34,51",
"scrollLine" : "15",
"tempName" : "Untitled1"
}
4 changes: 2 additions & 2 deletions .Rproj.user/E51B518C/sources/prop/7FB47E98
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"cursorPosition" : "92,14",
"scrollLine" : "80"
"cursorPosition" : "107,48",
"scrollLine" : "103"
}
4 changes: 2 additions & 2 deletions .Rproj.user/E51B518C/sources/prop/8C0CDA9B
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"cursorPosition" : "6,68",
"scrollLine" : "0"
"cursorPosition" : "133,45",
"scrollLine" : "131"
}
190 changes: 190 additions & 0 deletions .Rproj.user/E51B518C/sources/s-E0D6A191/5B3F5667-contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->
deflateBR
=========

[![Travis-CI Build
Status](https://travis-ci.org/meirelesff/deflateBR.svg?branch=master)](https://travis-ci.org/meirelesff/deflateBR)
[![AppVeyor Build
Status](https://ci.appveyor.com/api/projects/status/github/meirelesff/deflateBR?branch=master&svg=true)](https://ci.appveyor.com/project/meirelesff/deflateBR)

`deflateBR` is an `R` package used to deflate nominal Brazilian Reais
using several popular price indexes.

How does it work?
-----------------

The `deflateBR`’s main function, `deflate`, requires three arguments to
work: a `numeric` vector of nominal Reais (`nominal_values`); a `Date`
vector of corresponding dates (`nominal_dates`); and a reference date in
the `DD/MM/YYYY` format (`real_date`), used to deflate the values. An
example:

``` r
# Load the package
library(deflateBR)

# Deflate January 2000 reais
deflate(nominal_values = 100, nominal_dates = as.Date("2000-01-01"), real_date = "01/01/2018")
#>
#> Downloading necessary data from IPEA's API
#> ...
#> [1] 310.3893
```

Behind the scenes, `deflateBR` requests data from
[IPEADATA](http://www.ipeadata.gov.br/)’s API on one these five
Brazilian price indexes:
[IPCA](https://ww2.ibge.gov.br/english/estatistica/indicadores/precos/inpc_ipca/defaultinpc.shtm)
and
[INPC](https://ww2.ibge.gov.br/english/estatistica/indicadores/precos/inpc_ipca/defaultinpc.shtm),
maintained by [IBGE](https://ww2.ibge.gov.br/home/); and
[IGP-M](http://portalibre.fgv.br/main.jsp?lumChannelId=402880811D8E34B9011D92B6160B0D7D),
[IGP-DI](http://portalibre.fgv.br/main.jsp?lumChannelId=402880811D8E34B9011D92B6160B0D7D),
and
[IPC](http://portalibre.fgv.br/main.jsp?lumChannelId=402880811D8E34B9011D92B7350710C7)
maintained by
[FGV/IBRE](http://portalibre.fgv.br/main.jsp?lumChannelId=402880811D8E2C4C011D8E33F5700158).
To select one of the available price indexes, just provide one of the
following options to the `index =` argument: `ipca`, `igpm`, `igpdi`,
`ipc`, and `inpc`. In the following, the INPC index is used.

``` r
# Deflate January 2000 reais using the FGV/IBRE's INCP price index
deflate(100, as.Date("2000-01-01"), "01/01/2018", index = "inpc")
#>
#> Downloading necessary data from IPEA's API
#> ...
#> [1] 318.1845
```

With the same syntax, a vector of nominal Reais can also be deflated,
what is useful while working with `data.frames`:

``` r
# Create some data
df <- tibble::tibble(reais = seq(101, 200),
dates = seq.Date(from = as.Date("2001-01-01"), by = "month", length.out = 100)
)

# Reference date to deflate the nominal values
reference <- "01/01/2018"

# Deflate using IGP-DI
head(deflate(df$reais, df$dates, reference, "igpdi"))
#>
#> Downloading necessary data from IPEA's API
#> ...
#> [1] 341.0412 342.7393 344.9315 345.5051 344.9379 346.6979
```

### Working with the tidyverse

For `tidyverse` users, the `deflate` function can be easily used inside
code chains:

``` r
library(tidyverse)

df %>%
mutate(deflated_reais = deflate(reais, dates, reference, "ipca"))
#>
#> Downloading necessary data from IPEA's API
#> ...
#> # A tibble: 100 x 3
#> reais dates deflated_reais
#> <int> <date> <dbl>
#> 1 101 2001-01-01 296.
#> 2 102 2001-02-01 297.
#> 3 103 2001-03-01 299.
#> 4 104 2001-04-01 300.
#> 5 105 2001-05-01 301.
#> 6 106 2001-06-01 303.
#> 7 107 2001-07-01 304.
#> 8 108 2001-08-01 303.
#> 9 109 2001-09-01 304.
#> 10 110 2001-10-01 306.
#> # ... with 90 more rows
```

### Convenience functions

To facilitate the task of deflating nominal Reais, the `deflateBR`
package also provides five convenience functions: `ipca`, `inpc`,
`igpm`, `igpdi`, and `ipc`. Each one of these functions deflate nominal
values using their corresponding price indexes. For instance, to deflate
nominal Reais using IGP-M, one can execute the following code:

``` r
igpm(100, as.Date("2000-01-01"), "01/01/2018")
```

Or, using the IPCA index:

``` r
ipca(100, as.Date("2000-01-01"), "01/01/2018")
```

In addition, the `deflateBR` package contains a function called
`inflation` that calculates the inflation rate between two dates
quickly. Providing initial and end dates in the DD/MM/YYYY format, plus
one price index, the function returns the inflation rate in percent:

``` r
# Inflation rate between January and December of 2017
inflation("01/01/2017", "01/12/2017", "ipca")
#>
#> Downloading necessary data from IPEA's API
#> ...
#> [1] 2.947421
```

Installing
----------

Install the latest released version from CRAN with:

``` r
install.packages("deflateBR")
```

To install the development version of the package, use:

``` r
if (!require("devtools")) install.packages("devtools")
devtools::install_github("meirelesff/deflateBR")
```

Methodology
-----------

Following standard practice, seconded by the [Brazilian Central
Bank](https://www3.bcb.gov.br/CALCIDADAO/publico/metodologiaCorrigirIndice.do?method=metodologiaCorrigirIndice),
the `deflateBR` adjusts for inflation by multiplying nominal Reais by
the ratio between the original and the reference price indexes. For
example, to adjust 100 reais of January 2018, with IPCA index of
4916.46, to August 2018, with IPCA of 5056.56 in the previous month, we
first calculate the ratio between the two indexes (e.g., 5056.56 /
4916.46 = 1.028496) and then multiply this value by 100 (e.g., 102.84
adjusted Reais). The `deflate` function gives exactly the same result:

``` r
deflate(100, as.Date("2018-01-01"), "01/08/2018", "ipca")
#>
#> Downloading necessary data from IPEA's API
#> ...
#> [1] 102.8496
```

Citation
--------

To cite `deflateBR` in publications, please use:

``` r
citation('deflateBR')
```

Author
------

[Fernando Meireles](http://fmeireles.com)
4 changes: 2 additions & 2 deletions .Rproj.user/E51B518C/sources/s-E0D6A191/B2632C42
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"path" : "~/GitHub/deflateBR/README.Rmd",
"project_path" : "README.Rmd",
"properties" : {
"cursorPosition" : "92,14",
"scrollLine" : "80"
"cursorPosition" : "107,48",
"scrollLine" : "103"
},
"relative_order" : 2,
"source_on_save" : false,
Expand Down
6 changes: 3 additions & 3 deletions .Rproj.user/E51B518C/sources/s-E0D6A191/E684772D
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"folds" : "",
"hash" : "0",
"id" : "E684772D",
"lastKnownWriteTime" : 1536517584,
"last_content_update" : 1536517584174,
"lastKnownWriteTime" : 1536518614,
"last_content_update" : 1536518614426,
"path" : "~/GitHub/deflateBR/R/inflation.R",
"project_path" : "R/inflation.R",
"properties" : {
"cursorPosition" : "35,1",
"cursorPosition" : "34,51",
"scrollLine" : "15",
"tempName" : "Untitled1"
},
Expand Down
2 changes: 1 addition & 1 deletion .Rproj.user/E51B518C/sources/s-E0D6A191/E684772D-contents
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ inflation <- function(initial_date, end_date, index = c("ipca", "inpc", "igpm",
initial_date <- lubridate::dmy(initial_date)

# Inflation rate
(deflate(1, initial_date, end_date, index) - 1) * 100
deflate(100, initial_date, end_date, index) - 100
}
2 changes: 1 addition & 1 deletion R/inflation.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ inflation <- function(initial_date, end_date, index = c("ipca", "inpc", "igpm",
initial_date <- lubridate::dmy(initial_date)

# Inflation rate
(deflate(1, initial_date, end_date, index) - 1) * 100
deflate(100, initial_date, end_date, index) - 100
}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ Or, using the IPCA index:
ipca(100, as.Date("2000-01-01"), "01/01/2018")
```

In addition, the `deflateBR` package contains a function called
`inflation` that calculates the inflation rate between two dates
quickly. Providing initial and end dates in the DD/MM/YYYY format, plus
one price index, the function returns the inflation rate in percent:

``` r
# Inflation rate between January and December of 2017
inflation("01/01/2017", "01/12/2017", "ipca")
#>
#> Downloading necessary data from IPEA's API
#> ...
#> [1] 2.947421
```

Installing
----------

Expand Down

0 comments on commit 7a5c79e

Please sign in to comment.