Learn R Programming

FinancialInstrument (version 1.3.1)

buildRatio: construct price ratios of 2 instruments

Description

Calculates time series of ratio of 2 instruments using available data. Returned object will be ratios calculated using Bids, Asks, and Mids, or Opens, Closes, and Adjusteds.

Usage

buildRatio(x, env = .GlobalEnv, silent = FALSE)

Arguments

x

vector of instrument names. e.g. c("SPY","DIA")

env

environment where xts data is stored

silent

silence warnings?

Value

An xts object with columns of Bid, Ask, Mid OR Open, Close, Adjusted OR Price

Details

x should be a vector of 2 instrument names. An attempt will be made to get the data for both instruments. If there are no xts data stored under either of the names, it will try to return prebuilt data with a call to .get_rate.

If the data are not of the same frequency, or are not of the same type (OHLC, BBO, etc.) An attempt will be made to make them compatible. Preference is given to the first leg.

If the data in x[1] is daily or slower and the data in x[2] is intraday (e.g. if you give it daily OHLC and intraday Bid Ask Mid, it will use all of the OHLC columns of x[1] and only the the End of Day Mid price of the BAM object.

If the data in x[1] is intraday, and the data in x[2] is daily or slower, for each day, the previous closing value of x[2] will be filled forward with na.locf

See Also

redenominate buildSpread fn_SpreadBuilder

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
syms <- c("SPY","DIA")
getSymbols(syms)
rat <- buildRatio(syms)
summary(rat)
# }

Run the code above in your browser using DataLab