tbl: Add table

Description Usage Arguments Examples

View source: R/generics.R

Description

Add table

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## S3 method for class 'Data'
tbl(
  this,
  name,
  download = NULL,
  one_by_one = TRUE,
  price_align = FALSE,
  fun_table = NULL,
  fun_component = NULL,
  fun_download = "getSymbols",
  currency = NULL,
  ex_rate = NULL,
  action_seq = c("cbind", "fun", "price", "ex_rate"),
  ...
)

tbl(
  this,
  name,
  download,
  one_by_one,
  price_align,
  fun_table,
  fun_component,
  fun_download,
  action_seq,
  ...
)

Arguments

this

Data

name

character, name of table

download

character, names to download,

one_by_one

logical, if true then full vector of download argument will be passed to getSymbols

price_align

logical, if true then table will be aligned with data_raw

fun_table

function / character name of function, function will be applied on your table after cbind components and before alignment

fun_component

function / character name of function, function that will be applied to each component in table after download

fun_download

function/ list of functions/ character name of function or it can be a table or list of xts tables, this function will be used to download data. By default it is getSymbols

currency

character/NULL/list, name of currency. See example below

ex_rate

character / NULL, identifier for defined exchange rate in the this

action_seq

character, this sequence describes how table should be created. Available values are:

1. cbind - Reduce('cbind') tables

2. ex_rate - apply currency exchange

3. na.locf - do na.locf

4. na.locfl - do na.locf(fromLast=TRUE)

5. fun - apply function from fun_table

6. price - do aligning to price

...

params for fun_download

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Not run: 
data <- Data() %>%
modify("from", '2015-01-01') %>%
  stock("AAPL",
        src ='yahoo',
        currency = 'USD') %>%
  tbl("ETFS",
      download = c("XLB", 'ACWI'), # multiple instruments
      currency = c("USD", "RUB"), # multiple currencies
      ex_rate =  list(c(NA, "USDRUB"), # exchange rate for each instrument for the first call
                      "USDJPY"), # exchange rate for the second call
      fun_table = list(c(function(x) x * 10,  function(x) x / 2), # function to apply for each instrument for the first call
                       function(x) x * 10), # function for the second call
      price_align =TRUE, # align with closee
      fun_component = 'Ad', # apply this function to each instrument before additional actions
      action_seq = c("fun", 'ex_rate', 'cbind', "fun", "price", "ex_rate", "na.locfl")) %>% # actions to apply
  tbl("Derived",
      download = "XLB",
      price_align=TRUE,
      fun_table = function(x){
        x * ETFS[,1] # we can use defined above names
      },
      fun_component ='Ad'
  ) %>%
  getSymbols

## End(Not run)

Vitalic57/datastorage3pub documentation built on Feb. 22, 2022, 5:34 a.m.