[Blotter-commits] r183 - pkg/FinancialInstrument/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 19 15:55:43 CET 2010


Author: braverock
Date: 2010-01-19 15:55:43 +0100 (Tue, 19 Jan 2010)
New Revision: 183

Added:
   pkg/FinancialInstrument/R/synthetic.R
Log:
- add synthetic instrument template constructors

Added: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R	                        (rev 0)
+++ pkg/FinancialInstrument/R/synthetic.R	2010-01-19 14:55:43 UTC (rev 183)
@@ -0,0 +1,56 @@
+###############################################################################
+# R (http://r-project.org/) Instrument Class Model
+#
+# Copyright (c) 2009-2010
+# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, Joshua Ulrich and Brian G. Peterson
+#
+# This library is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id:$
+#
+###############################################################################
+
+synthetic <- function(primary_id , currency , multiplier=NULL, identifiers = NULL, ..., members=NULL){
+    synthetic_temp = instrument(primary_id , currency , multiplier , identifiers = identifiers, ..., type="synthetic" )
+    if (type=="synthetic") cl<-c("synthetic","instrument")
+    else cl <- c(type,"synthetic", "instrument")
+    ## now structure and return
+    return(structure( list(primary_id = synthetic_temp$primary_id,
+                            currency = synthetic_temp$currency,
+                            multiplier = synthetic_temp$multiplier,
+                            identifiers = synthetic_temp$identifiers,
+                            members = members 
+                    ),
+                    class=cl )
+           )
+}
+
+synthetic.ratio <- function(primary_id , currency , multiplier=NULL, identifiers = NULL, ..., type="synthetic.ratio", members, memberratio){
+    if(!is.list(members)){
+        if(length(members)!=length(memberratios) | length(members)<2){
+            stop("length of members and memberratio must be equal, and contain two or more instruments")
+        } else {
+            memberlist<-list(members=members,memberratio=memberratio,memberpositions=NULL)   
+        }
+    } else {
+        # TODO do some sanity checking here on the list elements
+          memberlist=members
+    }
+    synthetic_temp = synthetic(primary_id , currency , multiplier , identifiers = identifiers, ..., members, type=type )
+    ## now structure and return
+    assign(primary_id, structure( list(primary_id = synthetic_temp$primary_id,
+                            currency = synthetic_temp$currency,
+                            multiplier = synthetic_temp$multiplier,
+                            identifiers = synthetic_temp$identifiers,
+                            members = memberlist
+                    ),
+                    class=class(synthetic_temp)
+            ), # end structure
+            envir=.instrument,inherits=TRUE
+    )
+}
+
+spread <- function(primary_id , currency , multiplier=NULL, identifiers = NULL, ..., members, memberratio){
+    synthetic.ratio(primary_id , currency , multiplier=NULL, identifiers = NULL, ..., type=c("spread","synthetic.ratio"), members, memberratios)
+}


Property changes on: pkg/FinancialInstrument/R/synthetic.R
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author



More information about the Blotter-commits mailing list