[Blotter-commits] r1013 - in pkg/FinancialInstrument: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri May 4 17:27:54 CEST 2012
Author: gsee
Date: 2012-05-04 17:27:53 +0200 (Fri, 04 May 2012)
New Revision: 1013
Modified:
pkg/FinancialInstrument/R/buildSpread.R
pkg/FinancialInstrument/man/fn_SpreadBuilder.Rd
Log:
add notional arg to fn_SpreadBuilder; gives the option to not use multipliers
Modified: pkg/FinancialInstrument/R/buildSpread.R
===================================================================
--- pkg/FinancialInstrument/R/buildSpread.R 2012-05-04 14:02:03 UTC (rev 1012)
+++ pkg/FinancialInstrument/R/buildSpread.R 2012-05-04 15:27:53 UTC (rev 1013)
@@ -169,6 +169,8 @@
#' @param from from Date to pass through to getSymbols if needed.
#' @param to to Date to pass through to getSymbols if needed.
#' @param session_times ISO-8601 time subset for the session time, in GMT, in the format 'T08:00/T14:59'
+#' @param notional TRUE/FALSE. Should the prices be multiplied by contract
+#' multipliers before calculating the spread?
#' @param unique_method method for making the time series unique
#' @param auto.assign if \code{TRUE} (the default) the constructed spread will be stored in symbol created with \code{\link{make_spread_id}}. instrument metadata will also be created and stored with the same primary_id.
#' @param env if \code{auto.assign} is \code{TRUE} this is the environment in which to store the data (.GlobalEnv by default)
@@ -206,9 +208,10 @@
#' chartSeries(Cl(fn_SpreadBuilder(getSymbols(c("SPY","DIA")),auto.assign=FALSE)))
#' }
#' @export
-fn_SpreadBuilder <- function(prod1, prod2, ratio=1, currency='USD', from=NULL, to=NULL, session_times=NULL,
- unique_method=c('make.index.unique','duplicated','least.liq','price.change'), silent=FALSE,
- auto.assign=TRUE, env=.GlobalEnv, ...)
+fn_SpreadBuilder <- function(prod1, prod2, ratio=1, currency='USD', from=NULL,
+ to=NULL, session_times=NULL, notional=TRUE,
+ unique_method=c('make.index.unique','duplicated','least.liq','price.change'),
+ silent=FALSE, auto.assign=TRUE, env=.GlobalEnv, ...)
{
##TODO: allow for different methods for calculating Bid and Ask
if (!("package:quantmod" %in% search() || require("quantmod",quietly=TRUE))) {
@@ -246,18 +249,24 @@
}
prod1.instr <- try(getInstrument(prod1, silent=TRUE))
- if (!is.instrument(prod1.instr) || inherits(prod1.instr,'try-error') ) {
- if (!silent) warning(paste('could not find instrument ',
- prod1, '. Using multiplier of 1 and currency of ',
- currency, sep=''))
- prod1.instr <- list(multiplier=1,currency=currency)
+ if (!is.instrument(prod1.instr) || inherits(prod1.instr,'try-error')
+ || !isTRUE(notional)) {
+ if (!silent && isTRUE(notional)) {
+ warning(paste('could not find instrument ', prod1,
+ '. Using multiplier of 1 and currency of ',
+ currency, sep=''))
+ }
+ prod1.instr <- list(multiplier=1, currency=currency)
}
prod2.instr <- try(getInstrument(prod2, silent=TRUE))
- if (!is.instrument(prod2.instr) || inherits(prod2.instr, 'try-error') ) {
- if (!silent) warning(paste('could not find instrument ',
- prod2, '. Using multiplier of 1 and currency of ',
- currency, sep=''))
+ if (!is.instrument(prod2.instr) || inherits(prod2.instr, 'try-error')
+ || !isTRUE(notional)) {
+ if (!silent && isTRUE(notional)) {
+ warning(paste('could not find instrument ', prod2,
+ '. Using multiplier of 1 and currency of ',
+ currency, sep=''))
+ }
prod2.instr <- list(multiplier=1,currency=currency)
}
if (is.null(Data.1)) Data.1 <- try(get(as.character(prod1),envir=.GlobalEnv),silent=TRUE)
Modified: pkg/FinancialInstrument/man/fn_SpreadBuilder.Rd
===================================================================
--- pkg/FinancialInstrument/man/fn_SpreadBuilder.Rd 2012-05-04 14:02:03 UTC (rev 1012)
+++ pkg/FinancialInstrument/man/fn_SpreadBuilder.Rd 2012-05-04 15:27:53 UTC (rev 1013)
@@ -4,7 +4,7 @@
\usage{
fn_SpreadBuilder(prod1, prod2, ratio = 1,
currency = "USD", from = NULL, to = NULL,
- session_times = NULL,
+ session_times = NULL, notional = TRUE,
unique_method = c("make.index.unique", "duplicated", "least.liq", "price.change"),
silent = FALSE, auto.assign = TRUE, env = .GlobalEnv,
...)
@@ -33,6 +33,10 @@
\item{session_times}{ISO-8601 time subset for the session
time, in GMT, in the format 'T08:00/T14:59'}
+ \item{notional}{TRUE/FALSE. Should the prices be
+ multiplied by contract multipliers before calculating the
+ spread?}
+
\item{unique_method}{method for making the time series
unique}
More information about the Blotter-commits
mailing list