knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

riscoBrasil

riscoBrasil is a (tiny) R package to load the 'Brazil Risk' data that the Instituto Brasileiro de Geografia e Estatística IBGE maintain publicly from J.P. Morgan's Emerging Markets Bond Index. I was going to put this on CRAN, but I might not get around to satisfying the reqs.

Installation

if(!require(devtools)) install.packages("devtools")
devtools::install_github("RobertMyles/riscoBrasil")

Usage

The package has one function, riscoBrasil(), which takes two optional arguments, start and end. Without specifying either of these two, riscoBrasil() returns a data frame with data going back to 1994. The data frame has two columns, 'date' and 'risk', the first being POSIXct, the second being a numeric column. A specific period may be requested with start and/or end. If these parameters are used, they must be in a certain format, as a character string. For those familiar with the lubridate package, the format is "Ymd", for those not familiar with this style, the 1st of March 2017 is specified as: "2017-03-01". Both startand end must be in this format, otherwise the function will stop and return an error.

riscoBrasil <- function(start = NULL, end = NULL)

These data are then ideal for time series analysis, particularly with ARIMA-style models that posit that the values of a time-series are explained mostly by their past values.

Example

Here is how we can download and plot the series starting from May 2007:

library(riscoBrasil)
series <- riscoBrasil(start = "2007-05-01")

library(ggplot2)
ggplot(series, aes(x = date, y = risk)) + 
  geom_line(colour = "#1874CD") +
  theme_classic()

The 'Brazil Risk' numbers, published daily by the Brazilian Institute of Geography and Statistics from JP Morgan's Emerging Market Bond Index, are a time-series spanning 1994 to the present, and as such, are a great source of data to use for the teaching of time series in R.

Forecasting with riscoBrasil

The data returned from riscoBrasil() can be used with a variety of packages and functions. In this example, I'll use facebook's new prophet package.

if(!require(prophet)) install.packages("prophet", 
                                       repos = "http://cran.us.r-project.org")
library(prophet)
library(riscoBrasil)

series <- riscoBrasil(start = "2002-01-01")

colnames(series) <- c("ds", "y")   # for prophet to work
model <- prophet(series)
future <- make_future_dataframe(model, periods = 365)
forecast <- predict(model, future)
plot(model, forecast)


RobertMyles/riscoBrasil documentation built on May 5, 2019, 11:05 p.m.