tqr package is my first package, and is for my use only for now. This is basically a replacement of self-made functions I wrote in yellen-dashboard. Part of the package name tq
comes from tidyquant package
. I added r
to make the package name tqr
.
For my old functions to work, I had to prepare a data frame of 3 columns named “date”, “symbol” and “price”. tqr
package does not require fixed column names, but requires a tsibble
(tbl_ts class) instead. In a tsibble
, you must specify one column as index
(time pointing column like “date”) and one or more columns as key
(category columns like “symbol”). tqr
assumes all the others are measurement columns of numeric values like “price”. As tqr
works with more than one measurement columns (wide format), you don’t have to gather to one measurement column (tidy or long format). Actually, if you need speed, you had better spread to wide format.
A tsibble
has interval
attribute, like “1M” for monthly data. (Actual attribute is a list, but is printed like “1M”) For a tsibble
to get the right interval
, you have to pre-format index
by functions like yearmonth
for monthly and yearquarter
for quarterly data.
Although it takes some steps to convert a tibble
to a tsibble
, I think it is worthwhile, as I can check missing rows in a tsibble
. As missing rows are dangerous to the functions in tqr
package, I make a tsibble
as required input.
tq_diff
, tq_ma
, tq_gr
and tq_sa
in the package are, except for requiring a tsibble
, backward compatible with my old functions. They calculate differences, moving averages, growth rates and seasonally adjusted values respectively.
tq_diff
, tq_ma
and tq_gr
are manufactured by function factory cal_factory
, and tq_sa
is manufactured by function factory cal_factory_ts
. Other function factories are cal_factory_zoo
and cal_factory_xts
. When I find myself manufacturing the same functions, like maybe tq_logdiff
, I will add them to the package.