pull_futures_market: Retrieves futures market historical data.

Description Usage Arguments Value See Also Examples

View source: R/functions.r

Description

Provided with a set of futures active contract Bloomberg tickers, term structure positions, roll parameters and a time period, queries Bloomberg for the corresponding futures historical market data or retrieves it from an existing storethat SQLite database.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
pull_futures_market(
  source = "Bloomberg",
  type = "term structure",
  active_contract_tickers,
  start,
  end,
  TS_positions = 1L:5L,
  roll_type = "A",
  roll_days = 0L,
  roll_months = 0L,
  roll_adjustment = "N",
  file = NULL,
  verbose = T,
  ...
)

Arguments

source

a scalar character vector. Specifies the data source for the query: "Bloomberg" or "storethat". Defaults to "Bloomberg".

type

a scalar character vector, 'term structure' or 'aggregate'. 'term structure' returns individual futures chain data for a selected portion of the term structure (specify desired positions in TS_positions) while 'aggregate' returns aggregated data over the whole term structure for the corresponding names (active_contract_tickers).

active_contract_tickers

a chatacter vector. Specifies the futures active contract Bloomberg tickers to query data for.

start

a scalar character vector. Specifies the starting date for the query in the following format: 'yyyy-mm-dd'.

end

a scalar character vector. Specifies the end date for the query in the following format: 'yyyy-mm-dd'.

TS_positions

An integer vector. Specifies the term structure positions to query data for.

roll_type

a scalar chatacter vector. Specifies roll type to use for term structure ticker construction. Must be one of 'A', 'B', 'D', 'F', 'N', 'O' or 'R'.

roll_days

a scalar integer vector. Specifies the day the roll should be done. Refers to the day of the month (roll_type = 'F') or the number of days before a reference date (roll_type = 'D', roll_type = 'N', roll_type = 'O', roll_type = 'R'). Works in tandem with roll_months below.

roll_months

a scalar integer vector. Specifies the month the roll should be done. Refers to the number of months before a reference date (roll_type = 'D', roll_type = 'N', roll_type = 'O', roll_type = 'R'). Works in tandem with roll_days above.

roll_adjustment

a scalar chatacter vector. Specifies roll adjustment method to use for term structure ticker construction. Must be one of 'D', 'N', 'R', or 'W'.

file

a scalar chatacter vector. Optional parameter that specifies the target storethat SQLite database file to retrieve data from.

verbose

a logical scalar vector. Should progression messages be printed? Defaults to TRUE.

...

optional parameters to pass to the bdh function from the Rblpapi package used for the query (options parameter).

Value

An S4 object of class FuturesTS (type = 'term structure') or FuturesAggregate (type = 'aggregate').

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 

    BBG_TS <- pull_futures_market(source = "Bloomberg", type = 'term structure',
      active_contract_tickers = c("W A Comdty", "KWA Comdty"),
      start = "2000-01-01", end = as.character(Sys.Date()),
      TS_positions = 1L:5L, roll_type = "A", roll_days = 0L,
      roll_months = 0L, roll_adjustment = "N")

    BBG_agg <- pull_futures_market(source = "Bloomberg", type = "aggregate",
      active_contract_tickers = c("W A Comdty", "KWA Comdty"),
      start = "2000-01-01", end = as.character(Sys.Date()))

    storethat_TS <- pull_futures_market(source = "storethat", type = 'term structure',
      active_contract_tickers = c("W A Comdty", "KWA Comdty"),
      start = "2000-01-01", end = as.character(Sys.Date()),
      TS_positions = 1L:5L, roll_type = "A", roll_days = 0L,
      roll_months = 0L, roll_adjustment = "N")

    storethat_agg <- pull_futures_market(source = "storethat", file = "~/storethat.sqlite",
      type = "aggregate", active_contract_tickers = c("W A Comdty", "KWA Comdty"),
      start = "2000-01-01", end = as.character(Sys.Date()))
  
## End(Not run)

bautheac/pullit documentation built on June 7, 2021, 12:11 p.m.