Time-series (xts)

After getting data as a dplyr tibble, the first thing you might want to do is convert it into a time-series (xts) object. Here’s the recommended way:

indices <- Indices() #for IndiaGsecTimeSeries

ycInd <- indices$IndiaGsecTimeSeries() %>%
    filter(NAME == "5_10" & TIME_STAMP >= startDate) %>%
    select(TIME_STAMP, YIELD = YTM) %>%
    collect() %>%
    mutate(TIME_STAMP = as.Date(TIME_STAMP))

ycIndXts <- xts(ycInd$YIELD, ycInd$TIME_STAMP)

Just in case the above code snippet doesn’t render properly:

The mutate has to come after the collect. Otherwise, mutate ends up running as an SQL query in the database and TIME_STAMP remains a string.

Questions? slack me!

Packages

To get started with R notebooks on pluto, some standard libraries need to be imported and config files sourced. Start with these, in this specific order:

library(DBI)
library(plutoDbR)
library(plutoR)
library(tidyverse)

options("scipen"=999)
options(stringsAsFactors = FALSE)

source("/usr/share/pluto/config.R")

The first set allows you to access pluto datasets, the second is some common-sense settings and lastly, the config file.

To get productive, add these:

source("/usr/share/pluto/goofy/plot.common.R")
source("/usr/share/pluto/goofy/misc.common.R")

library(ggthemes)
library(reshape2)
library(quantmod)
library(lubridate)
library(ggrepel)
library(PerformanceAnalytics)

options(repr.plot.width=16, repr.plot.height=8)

goofy is a set of common plotting and date-resetting functions. The rest are some commonly used packages for financial data analysis in R.

If you need any specific package for your work, either raise an issue on github or slack me!