[Blotter-commits] r384 - in pkg/FinancialInstrument: R demo man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Sep 3 15:06:31 CEST 2010


Author: braverock
Date: 2010-09-03 15:06:31 +0200 (Fri, 03 Sep 2010)
New Revision: 384

Modified:
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/synthetic.R
   pkg/FinancialInstrument/demo/demo.R
   pkg/FinancialInstrument/man/future_series.Rd
   pkg/FinancialInstrument/man/instrument.Rd
   pkg/FinancialInstrument/man/synthetic.ratio.Rd
Log:
- add tick_size to instruments
- update docs and demo

Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R	2010-09-02 18:22:04 UTC (rev 383)
+++ pkg/FinancialInstrument/R/instrument.R	2010-09-03 13:06:31 UTC (rev 384)
@@ -30,10 +30,11 @@
 #' All 'currency' instruments must be defined before instruments of other types may be defined
 #' 
 #' @param primary_id string describing the unique ID for the instrument
+#' @param ... any other passthru parameters 
 #' @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)
 #' @param identifiers character vector of any other identifiers that should also be stored for this instrument
-#' @param ... any other passthru parameters 
 #' @param type instrument type to be appended to the class definition
 #' @param underlying_id for derivatives, the identifier of the instrument that this one is derived from, may be NULL for cash settled instruments
 #' @aliases 
@@ -48,7 +49,7 @@
 #' \code{\link{option_series}}
 #' \code{\link{future_series}}
 #' @export
-instrument<-function(primary_id , currency , multiplier , identifiers = NULL, ...,type=NULL ){
+instrument<-function(primary_id , ..., currency , multiplier , tick_size=NULL, identifiers = NULL, type=NULL ){
   if(is.null(primary_id)) stop("you must specify a primary_id for the instrument")
 
   # not sure this is correct, maybe should store the primary_id for the currency instead.  Why doesn't R have pointers?
@@ -58,7 +59,8 @@
 
   ## note that multiplier could be a time series, probably add code here to check
   if(!is.numeric(multiplier) | length(multiplier) > 1) stop("multiplier must be a single number")
-
+  if(!is.numeric(tick_size) | length(tick_size) > 1) stop("tick_size must be a single number")
+  
   if(is.null(type)) tclass="instrument" else tclass = c(type,"instrument")
 
   ## now structure and return
@@ -66,6 +68,7 @@
                          type = type,
                          currency = currency,
                          multiplier = multiplier,
+						 tick_size=tick_size,
                          identifiers = identifiers
                         ),
                     class = tclass
@@ -74,23 +77,14 @@
 }
 
 #' @export
-stock <- function(primary_id , currency , multiplier, identifiers = NULL, ...){
-  stock_temp = instrument(primary_id , currency , multiplier , identifiers = identifiers, ..., type="stock" )
-  ## now structure and return
-  assign(primary_id, structure( list(primary_id = stock_temp$primary_id,
-                         currency = stock_temp$currency,
-                         multiplier = stock_temp$multiplier,
-                         identifiers = stock_temp$identifiers
-                        ),
-                    class=c("stock","instrument")
-                  ), # end structure
-         envir=as.environment(.instrument)
-  )
+stock <- function(primary_id , currency=NULL , multiplier=1 , tick_size=.01, identifiers = NULL, ...){
+	stock_temp=  instrument(primary_id=primary_id , currency=currency , multiplier=multiplier , tick_size=tick_size, identifiers = identifiers, ..., type="stock")
+	assign(primary_id, stock_temp, envir=as.environment(.instrument) )
 }
 
 #' @export
-future <- function(primary_id , currency , multiplier , identifiers = NULL, ..., underlying_id=NULL){
-  future_temp = instrument(primary_id , currency , multiplier , identifiers = identifiers, ... , type="future" )
+future <- function(primary_id , currency , multiplier , tick_size=NULL, identifiers = NULL, ..., underlying_id=NULL){
+  future_temp = instrument(primary_id=primary_id , currency=currency , multiplier=multiplier , tick_size=tick_size, identifiers = identifiers, ... , type="future" )
 
   if(is.null(underlying_id)) {
       warning("underlying_id should only be NULL for cash-settled futures")
@@ -101,7 +95,8 @@
   assign(primary_id, structure( list(primary_id = future_temp$primary_id,
                          currency = future_temp$currency,
                          multiplier = future_temp$multiplier,
-                         identifiers = future_temp$identifiers,
+						 tick_size=future_temp$tick_size,
+						 identifiers = future_temp$identifiers,
                          underlying_id = future_temp$underlying_id
                         ),
                     class=c("future","instrument")
@@ -140,7 +135,8 @@
                          suffix_id = suffix_id,
                          currency = contract$currency,
                          multiplier = contract$multiplier,
-                         first_traded = first_traded,
+						 tick_size=contract$tick_size,
+						 first_traded = first_traded,
                          expires = expires,
                          identifiers = identifiers
                         ),
@@ -152,8 +148,8 @@
 }
 
 #' @export
-option <- function(primary_id , currency , multiplier , identifiers = NULL, ..., underlying_id=NULL){
-  option_temp = instrument(primary_id , currency , multiplier, identifiers = identifiers, ..., type="option")
+option <- function(primary_id , currency , multiplier , tick_size=NULL, identifiers = NULL, ..., underlying_id=NULL){
+  option_temp = instrument(primary_id=primary_id , currency=currency , multiplier=multiplier , tick_size=tick_size, identifiers = identifiers, ..., type="option")
 
   if(is.null(underlying_id)) {
       warning("underlying_id should only be NULL for cash-settled options")
@@ -164,6 +160,7 @@
   assign(primary_id, structure( list(primary_id = option_temp$primary_id,
                          currency = option_temp$currency,
                          multiplier = option_temp$multiplier,
+						 tick_size = option_temp$tick_size,
                          identifiers = option_temp$identifiers,
                          underlying_id = option_temp$underlying_id
                         ),
@@ -192,6 +189,7 @@
                          first_traded = first_traded,
                          currency = contract$currency,
                          multiplier = contract$multiplier,
+						 tick_size=contract$tick_size,
                          expires = expires,
                          callput = callput,
                          identifiers = identifiers
@@ -210,6 +208,7 @@
                          type = "currency",
                          currency = primary_id,
                          multiplier = 1,
+                         tick_size=.01,
                          identifiers = identifiers
                         ),
                     class=c("currency","instrument")
@@ -234,16 +233,18 @@
 #' @param ... any other passthru parameters
 #' @export
 exchange_rate <- function (primary_id , currency , second_currency, identifiers = NULL, ...){
-  exchange_rate_temp = instrument(primary_id , currency , multiplier=1 , identifiers = identifiers, ..., type="exchange_rate")
+  # exchange_rate_temp = instrument(primary_id , currency , multiplier=1 , tick_size=.01, identifiers = identifiers, ..., type="exchange_rate")
 
   if(!exists(currency, where=.instrument,inherits=TRUE)) warning("currency not found") # assumes that we know where to look
   if(!exists(second_currency, where=.instrument,inherits=TRUE)) warning("second_currency not found") # assumes that we know where to look
 
   ## now structure and return
-  assign(primary_id, structure( list(primary_id = exchange_rate_temp$primary_id,
-                         currency = exchange_rate_temp$currency,
-                         second_currency = exchange_rate_temp$second_currency,
-                         identifiers = exchange_rate_temp$identifiers
+  assign(primary_id, structure( list(primary_id = primary_id,
+                         currency = currency,
+                         multiplier=1,
+                         tick_size=.01,
+                         second_currency = second_currency,
+                         identifiers = identifiers
                         ),
                     class=c("exchange_rate","instrument")
                   ), # end structure
@@ -253,18 +254,9 @@
 
 #@TODO: government bond
 #@TODO  auction dates, coupons, etc for govmt. bonds
-bond <- function(primary_id , currency , multiplier, identifiers = NULL, ...){
-    bond_temp = instrument(primary_id , currency , multiplier , identifiers = identifiers, ..., type="bond" )
-    ## now structure and return
-    assign(primary_id, structure( list(primary_id = bond_temp$primary_id,
-                            currency = bond_temp$currency,
-                            multiplier = bond_temp$multiplier,
-                            identifiers = bond_temp$identifiers
-                    ),
-                    class=c("bond","instrument")
-            ), # end structure
-            envir=as.environment(.instrument)
-    )
+bond <- function(primary_id , currency , multiplier, tick_size=NULL , identifiers = NULL, ...){
+    bond_temp = instrument(primary_id=primary_id , currency=currency , multiplier=multiplier , tick_size=tick_size, identifiers = identifiers, ..., type="bond" )
+    assign( primary_id, bond_temp, envir=as.environment(.instrument) )
 }
 
 

Modified: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R	2010-09-02 18:22:04 UTC (rev 383)
+++ pkg/FinancialInstrument/R/synthetic.R	2010-09-03 13:06:31 UTC (rev 384)
@@ -36,7 +36,7 @@
 #' @param ... any other passthru parameters 
 #' @param cl 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 relationchips between members, e.g. c(4,3) for a 4:3 spread
+#' @param memberratio numeric vector of ratio relationships between members, e.g. c(4,3) for a 4:3 spread
 #' @aliases
 #' synthetic
 #' spread 

Modified: pkg/FinancialInstrument/demo/demo.R
===================================================================
--- pkg/FinancialInstrument/demo/demo.R	2010-09-02 18:22:04 UTC (rev 383)
+++ pkg/FinancialInstrument/demo/demo.R	2010-09-03 13:06:31 UTC (rev 384)
@@ -16,7 +16,7 @@
 
 # now a stock and an option contract on it
 stock("IBM","USD",1)
-option(".IBM","USD",100,underlying_id="IBM")
+option(".IBM","USD",multiplier=100,tick_size=.01, underlying_id="IBM")
 #@TODO:Jeff to pull put and call option series for 2009
 
 # bond & bond future

Modified: pkg/FinancialInstrument/man/future_series.Rd
===================================================================
--- pkg/FinancialInstrument/man/future_series.Rd	2010-09-02 18:22:04 UTC (rev 383)
+++ pkg/FinancialInstrument/man/future_series.Rd	2010-09-03 13:06:31 UTC (rev 384)
@@ -1,6 +1,7 @@
 \name{future_series}
 \title{constructors for series contracts on instruments such as options and futures...}
-\usage{future_series(primary_id, suffix_id, first_traded, expires, identifiers, ...)}
+\usage{future_series(primary_id, suffix_id, first_traded, expires,
+    identifiers, ...)}
 \description{constructors for series contracts on instruments such as options and futures}
 \alias{option_series}
 \alias{future_series}

Modified: pkg/FinancialInstrument/man/instrument.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument.Rd	2010-09-02 18:22:04 UTC (rev 383)
+++ pkg/FinancialInstrument/man/instrument.Rd	2010-09-03 13:06:31 UTC (rev 384)
@@ -1,6 +1,7 @@
 \name{instrument}
 \title{instrument class constructors...}
-\usage{instrument(primary_id, currency, multiplier, identifiers, ..., type)}
+\usage{instrument(primary_id, ..., currency, multiplier, tick_size,
+    identifiers, type)}
 \description{instrument class constructors}
 \details{All 'currency' instruments must be defined before instruments of other types may be defined}
 \alias{stock}
@@ -13,9 +14,10 @@
 \code{\link{option_series}}
 \code{\link{future_series}}}
 \arguments{\item{primary_id}{string describing the unique ID for the instrument}
+\item{...}{any other passthru parameters}
 \item{currency}{string describing the currency ID of an object of type \code{\link{currency}}}
 \item{multiplier}{numeric multiplier to apply to the price in the instrument currency to get to notional value}
+\item{tick_size}{the tick increment of the instrument price in it's trading venue, as numeric quantity (e.g. 1/8 is .125)}
 \item{identifiers}{character vector of any other identifiers that should also be stored for this instrument}
-\item{...}{any other passthru parameters}
 \item{type}{instrument type to be appended to the class definition}
 \item{underlying_id}{for derivatives, the identifier of the instrument that this one is derived from, may be NULL for cash settled instruments}}

Modified: pkg/FinancialInstrument/man/synthetic.ratio.Rd
===================================================================
--- pkg/FinancialInstrument/man/synthetic.ratio.Rd	2010-09-02 18:22:04 UTC (rev 383)
+++ pkg/FinancialInstrument/man/synthetic.ratio.Rd	2010-09-03 13:06:31 UTC (rev 384)
@@ -1,6 +1,8 @@
 \name{synthetic.ratio}
 \title{constructors for synthetic instruments...}
-\usage{synthetic.ratio(primary_id, currency, multiplier=1, identifiers, ..., cl=c("synthetic.ratio", "synthetic", "instrument"), members, memberratio)}
+\usage{synthetic.ratio(primary_id, currency, multiplier=1, identifiers, ...,
+    cl=c("synthetic.ratio", "synthetic", "instrument"), members,
+    memberratio)}
 \description{constructors for synthetic instruments}
 \alias{synthetic}
 \alias{spread}
@@ -12,4 +14,4 @@
 \item{...}{any other passthru parameters}
 \item{cl}{class string, should not be set by users}
 \item{members}{character vector of instrument identifiers that make up the synthetic}
-\item{memberratio}{numeric vector of ratio relationchips between members, e.g. c(4,3) for a 4:3 spread}}
+\item{memberratio}{numeric vector of ratio relationships between members, e.g. c(4,3) for a 4:3 spread}}



More information about the Blotter-commits mailing list