[Blotter-commits] r1299 - pkg/quantstrat/inst/tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 16 17:14:37 CET 2012


Author: milktrader
Date: 2012-12-16 17:14:37 +0100 (Sun, 16 Dec 2012)
New Revision: 1299

Added:
   pkg/quantstrat/inst/tests/cross_test.R
Modified:
   pkg/quantstrat/inst/tests/bbands_version_for_tests.R
Log:
added cross_test system for inter-platform testing

Modified: pkg/quantstrat/inst/tests/bbands_version_for_tests.R
===================================================================
--- pkg/quantstrat/inst/tests/bbands_version_for_tests.R	2012-12-14 20:37:15 UTC (rev 1298)
+++ pkg/quantstrat/inst/tests/bbands_version_for_tests.R	2012-12-16 16:14:37 UTC (rev 1299)
@@ -97,6 +97,6 @@
 
 ######################## APPLY STRAT  ###################################################
 
-out<-try(applyStrategy(strategy=stratBBands , portfolios='bbands',parameters=list(sd=SD,n=N)) )
+out<-try(applyStrategy(strategy=stratBBands , portfolios='bbands',parameters=list(sd=SD,n=N), verbose=FALSE))
 
 updatePortf(Portfolio='bbands',Dates=paste('::',as.Date(Sys.time()),sep=''))

Added: pkg/quantstrat/inst/tests/cross_test.R
===================================================================
--- pkg/quantstrat/inst/tests/cross_test.R	                        (rev 0)
+++ pkg/quantstrat/inst/tests/cross_test.R	2012-12-16 16:14:37 UTC (rev 1299)
@@ -0,0 +1,139 @@
+#!/usr/bin/Rscript --vanilla
+#
+# cross_test.R
+#
+# this produces trade statistics that can be compared 
+# with results from other frameworks
+#
+# copyright (c) 2009-2012, Algorithm Alpha, LLC
+# Licensed GPL-2
+#
+################### LOAD QUANTSTRAT #################
+
+suppressMessages(require(quantstrat))
+
+###################### LOAD DATA ######################
+
+data('spx')
+
+############################# DEFINE VARIABLES ##############################
+
+sym           = spx
+port          = 'test_port'
+acct          = 'test_acct'
+initEq        = 100000
+initDate      = '1969-12-31'
+fast          = 3 
+slow          = 8
+
+############################# INITIALIZE ####################################
+
+currency('USD')
+stock('sym' ,currency='USD', multiplier=1)
+initPortf(port, 'sym', initDate=initDate)
+initAcct(acct, port, initEq=initEq, initDate=initDate)
+initOrders(port, initDate=initDate )
+cross_test = strategy(port)
+
+############################# MAX POSITION LOGIC ############################
+# 
+ addPosLimit(
+             portfolio=port,
+             symbol='sym', 
+             timestamp=initDate,  
+             maxpos=100)
+# 
+# 
+############################# INDICATORS ####################################
+
+cross_test <- add.indicator(
+                     strategy  = cross_test, 
+                     name      = 'SMA', 
+                     arguments = list(x=quote(Cl(mktdata)), 
+                                      n=fast),
+                     label     = 'fast' )
+
+cross_test <- add.indicator(
+                     strategy  = cross_test, 
+                     name      = 'SMA', 
+                     arguments = list(x=quote(Cl(mktdata)), 
+                                      n=slow),
+                     label     = 'slow' )
+
+############################# SIGNALS #######################################
+
+cross_test <- add.signal(
+                  strategy  = cross_test,
+                  name      = 'sigCrossover',
+                  arguments = list(columns=c('fast','slow'), 
+                                   relationship='lt'),
+                  label     = 'fast.lt.slow')
+
+cross_test <- add.signal(
+                  strategy  = cross_test,
+                  name      = 'sigCrossover',
+                  arguments = list(columns=c('fast','slow'),
+                                   relationship='gt'),
+                  label     = 'fast.gt.slow')
+
+############################# RULES #########################################
+
+cross_test <- add.rule(
+                strategy  = cross_test,
+                name      = 'ruleSignal',
+                arguments = list(sigcol    = 'fast.gt.slow',
+                                 sigval    = TRUE,
+                                 orderqty  = 100,
+                                 ordertype = 'market',
+                                 orderside = 'long',
+                                 osFUN     = 'osMaxPos'),
+
+                type      = 'enter',
+                label     = 'EnterLONG')
+
+cross_test <- add.rule(
+                strategy  = cross_test,
+                name      = 'ruleSignal',
+                arguments = list(sigcol    = 'fast.lt.slow',
+                                 sigval    = TRUE,
+                                 orderqty  = 'all',
+                                 ordertype = 'market',
+                                 orderside = 'long'),
+                type      = 'exit',
+                label     = 'ExitLONG')
+
+cross_test <- add.rule(
+                strategy  = cross_test,
+                name      = 'ruleSignal',
+                arguments = list(sigcol     = 'fast.lt.slow',
+                                  sigval    = TRUE,
+                                  orderqty  =  -100,
+                                  ordertype = 'market',
+                                  orderside = 'short',
+                                  osFUN     = 'osMaxPos'),
+                type      = 'enter',
+                label     = 'EnterSHORT')
+
+cross_test <- add.rule(
+                strategy  = cross_test,
+                name      = 'ruleSignal',
+                arguments = list(sigcol     = 'fast.gt.slow',
+                                 sigval     = TRUE,
+                                 orderqty   = 'all',
+                                 ordertype  = 'market',
+                                 orderside  = 'short'),
+                type      = 'exit',
+                label     = 'ExitSHORT')
+
+############################# APPLY STRATEGY ################################
+
+applyStrategy(cross_test, port, prefer='Open', verbose=FALSE)
+
+############################# UPDATE ########################################
+
+updatePortf(port, 'sym', Date=paste('::',as.Date(Sys.time()),sep=''))
+
+########################### USEFUL CONTAINERS #############################
+
+resultsToCompare = tradeStats(port)
+


Property changes on: pkg/quantstrat/inst/tests/cross_test.R
___________________________________________________________________
Added: svn:executable
   + *



More information about the Blotter-commits mailing list