Learn R Programming

FinancialInstrument (version 1.3.1)

buildSpread: Construct a price/level series for pre-defined multi-leg spread instrument

Description

Build price series for spreads, butterflies, or other synthetic instruments, using metadata of a previously defined synthetic instrument.

Usage

buildSpread(spread_id, Dates = NULL, onelot = TRUE, prefer = NULL,
  auto.assign = TRUE, env = .GlobalEnv)

buildBasket(spread_id, Dates = NULL, onelot = TRUE, prefer = NULL, auto.assign = TRUE, env = .GlobalEnv)

Arguments

spread_id

The name of the instrument that contains members and memberratio

Dates

Date range on which to subset. Also, if a member's data is not available via get getSymbols will be called, and the values of the from and to arguments will be determined using .parseISO8601 on Dates.

onelot

Should the series be divided by the first leg's ratio?

prefer

Price column to use to build structure.

auto.assign

Assign the spread? If FALSE, the xts object will be returned.

env

Environment holding data for members as well as where spread data will be assigned.

Value

If auto.assign is FALSE, a univariate xts object. Otherwise, the xts object will be assigned to spread_id and the spread_id will be returned.

Details

The spread and all legs must be defined instruments.

This function can build multileg spreads such as calendars, butterflies, condors, etc. However, the returned series will be univariate. It does not return multiple columns (e.g. ‘Bid’, ‘Ask’, ‘Mid’) like fn_SpreadBuilder does.

buildBasket is an alias

TODO: allow for multiplier (divisor) that is a vector.

See Also

fn_SpreadBuilder spread for instructions on defining the spread

Examples

Run this code
# NOT RUN {
currency("USD")
stock("SPY","USD",1)
stock("DIA","USD",1)
getSymbols(c("SPY","DIA")) 

spread("SPYDIA", "USD", c("SPY","DIA"),c(1,-1)) #define it.
buildSpread('SPYDIA') #build it.
head(SPYDIA)

# }

Run the code above in your browser using DataLab