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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 17 16:00:16 CET 2012


Author: milktrader
Date: 2012-12-17 16:00:15 +0100 (Mon, 17 Dec 2012)
New Revision: 1301

Added:
   pkg/quantstrat/inst/tests/blue.R
Removed:
   pkg/quantstrat/inst/tests/cross_test.R
Log:
renamed and refactored cross_test.R to blue.R

Added: pkg/quantstrat/inst/tests/blue.R
===================================================================
--- pkg/quantstrat/inst/tests/blue.R	                        (rev 0)
+++ pkg/quantstrat/inst/tests/blue.R	2012-12-17 15:00:15 UTC (rev 1301)
@@ -0,0 +1,130 @@
+#!/usr/bin/Rscript --vanilla
+#
+# blue.R
+#
+# this produces trade statistics that can be compared 
+# with results from other frameworks
+#
+# the data is SPX daily data from 1/1/1970 to 12/31/1972
+#
+# copyright (c) 2009-2012, Algorithm Alpha, LLC
+# Licensed GPL-2
+#
+################### LOAD QUANTSTRAT #################
+
+suppressMessages(require(quantstrat))
+
+###################### LOAD DATA ######################
+
+data('spx')
+
+############################# DEFINE VARIABLES ##############################
+
+port          = 'bluePort'
+acct          = 'blueAcct'
+initEq        = 1e6
+initDate      = '1969-12-31'
+fast          = 3 
+slow          = 8
+
+############################# INITIALIZE ####################################
+
+currency('USD')
+stock('spx' ,currency='USD', multiplier=1)
+initPortf(port, 'spx', initDate=initDate)
+initAcct(acct, port, initEq=initEq, initDate=initDate)
+initOrders(port, initDate=initDate )
+blue = strategy(port)
+
+############################# INDICATORS ####################################
+
+blue <- add.indicator(
+                     strategy  = blue, 
+                     name      = 'SMA', 
+                     arguments = list(x=quote(Cl(mktdata)), 
+                                      n=fast),
+                     label     = 'fast' )
+
+blue <- add.indicator(
+                     strategy  = blue, 
+                     name      = 'SMA', 
+                     arguments = list(x=quote(Cl(mktdata)), 
+                                      n=slow),
+                     label     = 'slow' )
+
+############################# SIGNALS #######################################
+
+blue <- add.signal(
+                  strategy  = blue,
+                  name      = 'sigCrossover',
+                  arguments = list(columns=c('fast','slow'), 
+                                   relationship='lt'),
+                  label     = 'fast.lt.slow')
+
+blue <- add.signal(
+                  strategy  = blue,
+                  name      = 'sigCrossover',
+                  arguments = list(columns=c('fast','slow'),
+                                   relationship='gt'),
+                  label     = 'fast.gt.slow')
+
+############################# RULES #########################################
+
+blue <- add.rule(
+                strategy  = blue,
+                name      = 'ruleSignal',
+                arguments = list(sigcol    = 'fast.gt.slow',
+                                 sigval    = TRUE,
+                                 orderqty  = 100,
+                                 ordertype = 'market',
+                                 orderside = 'long'),
+
+                type      = 'enter',
+                label     = 'EnterLONG')
+
+blue <- add.rule(
+                strategy  = blue,
+                name      = 'ruleSignal',
+                arguments = list(sigcol    = 'fast.lt.slow',
+                                 sigval    = TRUE,
+                                 orderqty  = 'all',
+                                 ordertype = 'market',
+                                 orderside = 'long'),
+                type      = 'exit',
+                label     = 'ExitLONG')
+
+blue <- add.rule(
+                strategy  = blue,
+                name      = 'ruleSignal',
+                arguments = list(sigcol     = 'fast.lt.slow',
+                                  sigval    = TRUE,
+                                  orderqty  =  -100,
+                                  ordertype = 'market',
+                                  orderside = 'short'),
+                type      = 'enter',
+                label     = 'EnterSHORT')
+
+blue <- add.rule(
+                strategy  = blue,
+                name      = 'ruleSignal',
+                arguments = list(sigcol     = 'fast.gt.slow',
+                                 sigval     = TRUE,
+                                 orderqty   = 'all',
+                                 ordertype  = 'market',
+                                 orderside  = 'short'),
+                type      = 'exit',
+                label     = 'ExitSHORT')
+
+############################# APPLY STRATEGY ################################
+
+applyStrategy(blue, port, prefer='Open', verbose=FALSE)
+
+############################# UPDATE ########################################
+
+updatePortf(port, 'spx', Date=paste('::',as.Date(Sys.time()),sep=''))
+
+########################### USEFUL CONTAINERS #############################
+
+blueStats = tradeStats(port)
+
+


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

Deleted: pkg/quantstrat/inst/tests/cross_test.R
===================================================================
--- pkg/quantstrat/inst/tests/cross_test.R	2012-12-16 21:51:14 UTC (rev 1300)
+++ pkg/quantstrat/inst/tests/cross_test.R	2012-12-17 15:00:15 UTC (rev 1301)
@@ -1,139 +0,0 @@
-#!/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)
-



More information about the Blotter-commits mailing list