[Blotter-commits] r714 - in pkg/FinancialInstrument: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Aug 6 18:13:07 CEST 2011
Author: gsee
Date: 2011-08-06 18:13:07 +0200 (Sat, 06 Aug 2011)
New Revision: 714
Added:
pkg/FinancialInstrument/man/instrument_attr.Rd
Modified:
pkg/FinancialInstrument/NAMESPACE
pkg/FinancialInstrument/R/instrument.R
pkg/FinancialInstrument/R/redenominate.R
pkg/FinancialInstrument/R/synthetic.R
pkg/FinancialInstrument/man/build_spread_symbols.Rd
pkg/FinancialInstrument/man/instrument.Rd
pkg/FinancialInstrument/man/redenominate.Rd
pkg/FinancialInstrument/man/synthetic.ratio.Rd
Log:
- add instrument_attr fun for adding/updating slots in an instrument.
- future_series no longer requires suffix_id if primary_id has an underscore. (still no root_id arg)
- update roxygen and roxygenize to get closer to passing R CMD check
Modified: pkg/FinancialInstrument/NAMESPACE
===================================================================
--- pkg/FinancialInstrument/NAMESPACE 2011-08-06 15:07:10 UTC (rev 713)
+++ pkg/FinancialInstrument/NAMESPACE 2011-08-06 16:13:07 UTC (rev 714)
@@ -17,6 +17,7 @@
export(getSymbols.FI)
export(guaranteed_spread)
export(instrument)
+export(instrument_attr)
export(instrument.table)
export(is.currency)
export(is.instrument)
Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R 2011-08-06 15:07:10 UTC (rev 713)
+++ pkg/FinancialInstrument/R/instrument.R 2011-08-06 16:13:07 UTC (rev 714)
@@ -55,7 +55,8 @@
#' before assignment.
#'
#' @param primary_id string describing the unique ID for the instrument
-#' @param ... any other passthru parameters, including underlying_id for derivatives -- the identifier of the instrument that this one is derived from, may be NULL for cash settled instruments
+#' @param ... any other passthru parameters, including
+#' @param underlying_id for derivatives, the identifier of the instrument that this one is derived from, may be NULL for cash settled instruments
#' @param currency string describing the currency ID of an object of type \code{\link{currency}}
#' @param multiplier numeric multiplier to apply to the price in the instrument currency to get to notional value
#' @param tick_size the tick increment of the instrument price in it's trading venue, as numeric quantity (e.g. 1/8 is .125)
@@ -180,6 +181,12 @@
#' @export
#' @rdname series_instrument
future_series <- function(primary_id , suffix_id, first_traded=NULL, expires=NULL, identifiers = NULL, ...){
+ if (!identical(primary_id,gsub("_","",primary_id)) && missing(suffix_id)) {
+ #if primary_id has an underscore in it and there is no suffix_id
+ ss <- strsplit(primary_id, "_")[[1]]
+ primary_id <- ss[1]
+ suffix_id <- ss[2]
+ }
contract<-try(getInstrument(primary_id))
if(!inherits(contract,"future")) stop("futures contract spec must be defined first")
@@ -472,3 +479,30 @@
}
#TODO add Date support to instrument, to get the proper value given a specific date
}
+
+
+#' add or change an attribute of an instrument
+#'
+#' This function will add or overwrite the data stored in the specified slot of the specified instrument.
+#' @param primary_id primary_id of the instrument that will be updated
+#' @param attr name of the slot that will be added or changed
+#' @param value what to assign to the \code{attr} slot of the \code{primary_id} instrument
+#' @return called for side-effect
+#' @examples
+#' \dontrun{
+#' currency("USD")
+#' stock("SPY","USD")
+#' instrument_attr('USD','description',"U.S. Dollar")
+#' instrument_attr("SPY", "description", 'An ETF')
+#' getInstrument("USD")
+#' getInstrument("SPY")
+#' }
+#' @export
+instrument_attr <- function(primary_id, attr, value) {
+ instr <- try(getInstrument(primary_id))
+ if (inherits(instr, 'try-error') || !is.instrument(instr))
+ stop(paste('instrument ',primary_id,' must be defined first.',sep=''))
+ instr[[attr]] <- value
+ assign(primary_id, instr, pos=.instrument)
+}
+
Modified: pkg/FinancialInstrument/R/redenominate.R
===================================================================
--- pkg/FinancialInstrument/R/redenominate.R 2011-08-06 15:07:10 UTC (rev 713)
+++ pkg/FinancialInstrument/R/redenominate.R 2011-08-06 16:13:07 UTC (rev 714)
@@ -264,7 +264,7 @@
#' Redenominate (change the base of) an instrument
#'
-#'
+#' Redenominate (change the base of) an instrument
#'
#' If \code{x} is the name of an instrument, old_base is not required
#' and will become whatever is in the currency slot of the instrument.
Modified: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R 2011-08-06 15:07:10 UTC (rev 713)
+++ pkg/FinancialInstrument/R/synthetic.R 2011-08-06 16:13:07 UTC (rev 714)
@@ -36,11 +36,10 @@
#' @param currency string describing the currency ID of an object of type \code{\link{currency}}
#' @param multiplier numeric multiplier to apply to the price in the instrument currency to get to notional value
#' @param identifiers character vector of any other identifiers that should also be stored for this instrument
-#' @param ... any other passthru parameters
+#' @param ... any other passthru parameters such as tick_size -- the tick increment of the instrument price in it's trading venue, as numeric quantity (e.g. 1/8 is .125)
#' @param type class string, should not be set by users
#' @param members character vector of instrument identifiers that make up the synthetic
#' @param memberratio numeric vector of ratio relationships between members, e.g. c(4,3) for a 4:3 spread
-#' @param tick_size the tick increment of the instrument price in it's trading venue, as numeric quantity (e.g. 1/8 is .125)
#' @note DEPRECATED
#' @export
synthetic.ratio <- function(primary_id , currency , members, memberratio, ..., multiplier=1, identifiers = NULL, type=c("synthetic.ratio","synthetic","instrument"))
@@ -234,4 +233,4 @@
memberratio = memberratio, multiplier = multiplier, identifiers = NULL,
tick_size=tick_size, ... = ..., type = c("guaranteed_spread", "spread",
"synthetic.instrument", "synthetic", "instrument"))
-}
\ No newline at end of file
+}
Modified: pkg/FinancialInstrument/man/build_spread_symbols.Rd
===================================================================
--- pkg/FinancialInstrument/man/build_spread_symbols.Rd 2011-08-06 15:07:10 UTC (rev 713)
+++ pkg/FinancialInstrument/man/build_spread_symbols.Rd 2011-08-06 16:13:07 UTC (rev 714)
@@ -42,7 +42,10 @@
string describing the cycle on which the guaranteed
calendar spreads are to be consructed, e.g. '1' for
one-month spreads, '1,3' for one and three month spreads,
- '1,6,12' for 1, 6, and 12 month spreads, etc.
+ '1,6,12' for 1, 6, and 12 month spreads, etc. For
+ quarterly symbols, the correct \code{contracts_ahead} may
+ be something like '1,2,3' for quarterly, bi-annual, and
+ annual spreads.
\code{active_months} is a numeric field indicating how
many months including the month of the \code{start_date}
Modified: pkg/FinancialInstrument/man/instrument.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument.Rd 2011-08-06 15:07:10 UTC (rev 713)
+++ pkg/FinancialInstrument/man/instrument.Rd 2011-08-06 16:13:07 UTC (rev 714)
@@ -34,11 +34,12 @@
\item{primary_id}{string describing the unique ID for the
instrument}
- \item{...}{any other passthru parameters, including
- underlying_id for derivatives -- the identifier of the
- instrument that this one is derived from, may be NULL for
- cash settled instruments}
+ \item{...}{any other passthru parameters, including}
+ \item{underlying_id}{for derivatives, the identifier of
+ the instrument that this one is derived from, may be NULL
+ for cash settled instruments}
+
\item{currency}{string describing the currency ID of an
object of type \code{\link{currency}}}
Added: pkg/FinancialInstrument/man/instrument_attr.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument_attr.Rd (rev 0)
+++ pkg/FinancialInstrument/man/instrument_attr.Rd 2011-08-06 16:13:07 UTC (rev 714)
@@ -0,0 +1,34 @@
+\name{instrument_attr}
+\alias{instrument_attr}
+\title{add or change an attribute of an instrument}
+\usage{
+ instrument_attr(primary_id, attr, value)
+}
+\arguments{
+ \item{primary_id}{primary_id of the instrument that will
+ be updated}
+
+ \item{attr}{name of the slot that will be added or
+ changed}
+
+ \item{value}{what to assign to the \code{attr} slot of
+ the \code{primary_id} instrument}
+}
+\value{
+ called for side-effect
+}
+\description{
+ This function will add or overwrite the data stored in
+ the specified slot of the specified instrument.
+}
+\examples{
+\dontrun{
+currency("USD")
+stock("SPY","USD")
+instrument_attr('USD','description',"U.S. Dollar")
+instrument_attr("SPY", "description", 'An ETF')
+getInstrument("USD")
+getInstrument("SPY")
+}
+}
+
Modified: pkg/FinancialInstrument/man/redenominate.Rd
===================================================================
--- pkg/FinancialInstrument/man/redenominate.Rd 2011-08-06 15:07:10 UTC (rev 713)
+++ pkg/FinancialInstrument/man/redenominate.Rd 2011-08-06 16:13:07 UTC (rev 714)
@@ -27,7 +27,7 @@
currency (base).
}
\description{
-
+ Redenominate (change the base of) an instrument
}
\details{
If \code{x} is the name of an instrument, old_base is not
Modified: pkg/FinancialInstrument/man/synthetic.ratio.Rd
===================================================================
--- pkg/FinancialInstrument/man/synthetic.ratio.Rd 2011-08-06 15:07:10 UTC (rev 713)
+++ pkg/FinancialInstrument/man/synthetic.ratio.Rd 2011-08-06 16:13:07 UTC (rev 714)
@@ -21,7 +21,10 @@
identifiers that should also be stored for this
instrument}
- \item{...}{any other passthru parameters}
+ \item{...}{any other passthru parameters such as
+ tick_size -- the tick increment of the instrument price
+ in it's trading venue, as numeric quantity (e.g. 1/8 is
+ .125)}
\item{type}{class string, should not be set by users}
@@ -30,10 +33,6 @@
\item{memberratio}{numeric vector of ratio relationships
between members, e.g. c(4,3) for a 4:3 spread}
-
- \item{tick_size}{the tick increment of the instrument
- price in it's trading venue, as numeric quantity (e.g.
- 1/8 is .125)}
}
\description{
THIS FUNCTION HAS BEEN DEPRECATED. Use
More information about the Blotter-commits
mailing list