[Blotter-commits] r623 - pkg/quantstrat/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 10 17:47:38 CEST 2011


Author: gsee
Date: 2011-06-10 17:47:38 +0200 (Fri, 10 Jun 2011)
New Revision: 623

Modified:
   pkg/quantstrat/R/traderules.R
Log:
opside now checks for BBO data before using bid/ask.

Modified: pkg/quantstrat/R/traderules.R
===================================================================
--- pkg/quantstrat/R/traderules.R	2011-06-10 01:05:13 UTC (rev 622)
+++ pkg/quantstrat/R/traderules.R	2011-06-10 15:47:38 UTC (rev 623)
@@ -55,14 +55,16 @@
 
 		switch(pricemethod,
                 opside = {
-                    if (orderqty>0) 
-                        prefer='ask'  # we're buying, so pay what they're asking
-                    else
-                        prefer='bid'  # we're selling, so give it to them for what they're bidding
+                    if (is.BBO(data)) {
+                        if (orderqty>0)
+                            prefer='ask'  # we're buying, so pay what they're asking
+                        else
+                            prefer='bid'  # we're selling, so give it to them for what they're bidding
+                    }
                     orderprice <- try(getPrice(x=data, prefer=prefer))[timestamp]
 				}, 
                 market = {
-                    if(is.BBO(mktdata)){
+                    if(is.BBO(data)){
                         if (orderqty>0) 
                             prefer='bid'  # we're buying, so work the bid price
                         else
@@ -132,7 +134,7 @@
         orderqty <- osFUN(strategy=strategy, data=mktdata, timestamp=timestamp, orderqty=orderqty, ordertype=ordertype, orderside=orderside, portfolio=portfolio, symbol=symbol,...=...,ruletype=ruletype, orderprice=as.numeric(orderprice))
         
         
-        if(!is.null(orderqty) & !orderqty == 0 & !is.null(orderprice)){
+        if(!is.null(orderqty) && !orderqty == 0 && !is.null(orderprice)){ #orderqty could have length > 1
             addOrder(portfolio=portfolio, symbol=symbol, timestamp=timestamp, qty=orderqty, price=as.numeric(orderprice), ordertype=ordertype, side=orderside, threshold=threshold, status="open", replace=replace , delay=delay, tmult=tmult, ...=..., TxnFees=TxnFees)
         }
     }
@@ -347,7 +349,8 @@
 # R (http://r-project.org/) Quantitative Strategy Model Framework
 #
 # Copyright (c) 2009-2011
-# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey Ryan, and Joshua Ulrich 
+# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson,
+# Jeffrey Ryan, Joshua Ulrich, and Garrett See
 #
 # This library is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING



More information about the Blotter-commits mailing list