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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 30 19:29:27 CET 2012


Author: milktrader
Date: 2012-12-30 19:29:27 +0100 (Sun, 30 Dec 2012)
New Revision: 1328

Added:
   pkg/quantstrat/inst/tests/aqua.R
Removed:
   pkg/quantstrat/inst/tests/bbands_version_for_tests.R
   pkg/quantstrat/inst/tests/bee_version_for_tests.R
   pkg/quantstrat/inst/tests/xtestthat_bbands.R
   pkg/quantstrat/inst/tests/xtestthat_bee.R
Log:
cleaning up dead functions in tests

Added: pkg/quantstrat/inst/tests/aqua.R
===================================================================
--- pkg/quantstrat/inst/tests/aqua.R	                        (rev 0)
+++ pkg/quantstrat/inst/tests/aqua.R	2012-12-30 18:29:27 UTC (rev 1328)
@@ -0,0 +1,114 @@
+#!/usr/bin/Rscript --vanilla
+#
+# aqua.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 #################
+
+require(quantstrat)
+
+###################### LOAD DATA ######################
+
+data(spx)
+
+############### TIMEZONE HOUSEKEEPING #########################
+
+local_TZ = Sys.getenv("TZ")
+Sys.unsetenv("TZ")
+
+############################# DEFINE VARIABLES ##############################
+
+port          = 'aquaPort'
+acct          = 'aquaAcct'
+initEq        = 1e6
+initDate      = '1969-12-31'
+fast          = 10 
+slow          = 30
+
+############################# 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 )
+aqua = strategy(port)
+
+############################# INDICATORS ####################################
+
+aqua <- add.indicator(
+                     strategy  = aqua, 
+                     name      = 'SMA', 
+                     arguments = list(x=quote(Cl(mktdata)), 
+                                      n=fast),
+                     label     = 'fast' )
+
+aqua <- add.indicator(
+                     strategy  = aqua, 
+                     name      = 'SMA', 
+                     arguments = list(x=quote(Cl(mktdata)), 
+                                      n=slow),
+                     label     = 'slow' )
+
+############################# SIGNALS #######################################
+
+aqua <- add.signal(
+                  strategy  = aqua,
+                  name      = 'sigCrossover',
+                  arguments = list(columns=c('fast','slow'), 
+                                   relationship='lt'),
+                  label     = 'fast.lt.slow')
+
+aqua <- add.signal(
+                  strategy  = aqua,
+                  name      = 'sigCrossover',
+                  arguments = list(columns=c('fast','slow'),
+                                   relationship='gt'),
+                  label     = 'fast.gt.slow')
+
+############################# RULES #########################################
+
+aqua <- add.rule(
+                strategy  = aqua,
+                name      = 'ruleSignal',
+                arguments = list(sigcol    = 'fast.gt.slow',
+                                 sigval    = TRUE,
+                                 orderqty  = 100,
+                                 ordertype = 'market',
+                                 orderside = 'long'),
+
+                type      = 'enter',
+                label     = 'EnterLONG')
+aqua <- add.rule(
+                strategy  = aqua,
+                name      = 'ruleSignal',
+                arguments = list(sigcol    = 'fast.lt.slow',
+                                 sigval    = TRUE,
+                                 orderqty  = 'all',
+                                 ordertype = 'market',
+                                 orderside = 'long'),
+                type      = 'exit',
+                label     = 'ExitLONG')
+
+############################# APPLY STRATEGY ################################
+
+applyStrategy(aqua, port, prefer='Open', verbose=FALSE)
+
+############################# UPDATE ########################################
+
+updatePortf(port, 'spx', Date=paste('::',as.Date(Sys.time()),sep=''))
+
+########################### CONTAINERS CALLED IN TESTING #####################
+
+book = getOrderBook(port)
+
+############################### RESET TZ TO ORIGINAL SETTING ########
+
+Sys.setenv(TZ = local_TZ)

Deleted: pkg/quantstrat/inst/tests/bbands_version_for_tests.R
===================================================================
--- pkg/quantstrat/inst/tests/bbands_version_for_tests.R	2012-12-30 18:22:05 UTC (rev 1327)
+++ pkg/quantstrat/inst/tests/bbands_version_for_tests.R	2012-12-30 18:29:27 UTC (rev 1328)
@@ -1,102 +0,0 @@
-#################### CLEANUP PREVIOUS TEST ######################
-
-suppressWarnings(rm(list=ls(.strategy), pos=.strategy))
-suppressWarnings(rm(list=ls(.blotter), pos=.blotter))
-suppressWarnings(rm(list=ls()))
-
-################### LOAD QUANTSTRAT #################
-
-suppressMessages(require(quantstrat))
-
-###################### LOAD DATA ######################
-
-data('spx')
-
-###################### DEFINE VARIABLES #################
-
-SD = 2 
-N = 20
-currency('USD')
-stock('spx', currency='USD', multiplier=1)
-initDate='1969-12-31'
-initEq=1000000
-portfolio.st='bbands'
-account.st='bbands'
-
-############################ INITIALIZE AND POSITION LOGIC ################
-
-initPortf(portfolio.st,symbols='spx', initDate=initDate)
-initAcct(account.st,portfolios='bbands', initDate=initDate)
-initOrders(portfolio=portfolio.st,initDate=initDate)
-addPosLimit(portfolio.st, 'spx', initDate, 200, 2 ) #set max pos
-stratBBands <- strategy("bbands")
-
-############################ INDICATOR ############################
-
-stratBBands <- add.indicator(strategy = stratBBands,
-                             name = "BBands", 
-                             arguments = list(HLC = quote(HLC(mktdata)), 
-                                              maType='SMA'))
-
-
-############################ SIGNALS ##############################
-
-stratBBands <- add.signal(stratBBands,
-                          name="sigCrossover",
-                          arguments = list(columns=c("Close","up"),
-                                           relationship="gt"),
-                          label="Cl.gt.UpperBand")
-
-stratBBands <- add.signal(stratBBands,
-                          name="sigCrossover",
-                          arguments = list(columns=c("Close","dn"),
-                                           relationship="lt"),
-                          label="Cl.lt.LowerBand")
-
-stratBBands <- add.signal(stratBBands,
-                          name="sigCrossover",
-                          arguments = list(columns=c("High","Low","mavg"),
-                                           relationship="op"),
-                          label="Cross.Mid")
-
-############################# RULES ###############################
-
-
-stratBBands <- add.rule(stratBBands,
-                        name='ruleSignal', 
-                        arguments = list(sigcol="Cl.gt.UpperBand",
-                                         sigval=TRUE, 
-                                         orderqty=-100, 
-                                         ordertype='market', 
-                                         orderside=NULL, 
-                                         threshold=NULL,
-                                         osFUN=osMaxPos),
-                        type='enter')
-
-stratBBands <- add.rule(stratBBands,
-                        name='ruleSignal', 
-                        arguments = list(sigcol="Cl.lt.LowerBand",
-                                         sigval=TRUE, 
-                                         orderqty= 100, 
-                                         ordertype='market', 
-                                         orderside=NULL, 
-                                         threshold=NULL,
-                                         osFUN=osMaxPos),
-                        type='enter')
-
-stratBBands <- add.rule(stratBBands,
-                        name='ruleSignal', 
-                        arguments = list(sigcol="Cross.Mid",
-                                         sigval=TRUE, 
-                                         orderqty= 'all', 
-                                         ordertype='market', 
-                                         orderside=NULL, 
-                                         threshold=NULL,
-                                         osFUN=osMaxPos),
-                        type='exit')
-
-######################## APPLY STRAT  ###################################################
-
-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=''))

Deleted: pkg/quantstrat/inst/tests/bee_version_for_tests.R
===================================================================
--- pkg/quantstrat/inst/tests/bee_version_for_tests.R	2012-12-30 18:22:05 UTC (rev 1327)
+++ pkg/quantstrat/inst/tests/bee_version_for_tests.R	2012-12-30 18:29:27 UTC (rev 1328)
@@ -1,135 +0,0 @@
-
-#################### CLEANUP PREVIOUS TEST ######################
-# 
- suppressWarnings(rm(list=ls(.strategy), pos=.strategy))
- suppressWarnings(rm(list=ls(.blotter), pos=.blotter))
- suppressWarnings(rm(list=ls()))
-# 
-################### LOAD QUANTSTRAT #################
-
-suppressMessages(require(quantstrat))
-
-###################### LOAD DATA ######################
-
-data('spx')
-
-############################# DEFINE VARIABLES ##############################
-
-sym           = spx
-port          = 'bug'
-acct          = 'colony'
-initEq        = 100000
-initDate      = '1969-12-31'
-fast          = 10
-slow          = 30
-sd            = 0.5
-
-
-############################# 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 )
-bee = strategy(port)
-
-############################# MAX POSITION LOGIC ############################
-
-addPosLimit(
-            portfolio=port,
-            symbol='sym', 
-            timestamp=initDate,  
-            maxpos=100)
-
-
-############################# INDICATORS ####################################
-
-bee <- add.indicator( 
-                     strategy  = bee, 
-                     name      = 'BBands', 
-                     arguments = list(HLC=quote(HLC(mktdata)), 
-                                      n=slow, 
-                                      sd=sd))
-
-bee <- add.indicator(
-                     strategy  = bee, 
-                     name      = 'SMA', 
-                     arguments = list(x=quote(Cl(mktdata)), 
-                                      n=fast),
-                     label     = 'fast' )
-
-############################# SIGNALS #######################################
-
-bee <- add.signal(
-                  strategy  = bee,
-                  name      = 'sigCrossover',
-                  arguments = list(columns=c('fast','dn'), 
-                                   relationship='lt'),
-                  label     = 'fast.lt.dn')
-
-bee <- add.signal(
-                  strategy  = bee,
-                  name      = 'sigCrossover',
-                  arguments = list(columns=c('fast','up'),
-                                   relationship='gt'),
-                  label     = 'fast.gt.up')
-
-############################# RULES #########################################
-
-bee <- add.rule(
-                strategy  = bee,
-                name      = 'ruleSignal',
-                arguments = list(sigcol    = 'fast.gt.up',
-                                 sigval    = TRUE,
-                                 orderqty  = 100,
-                                 ordertype = 'market',
-                                 orderside = 'long',
-                                 osFUN     = 'osMaxPos'),
-
-                type      = 'enter',
-                label     = 'EnterLONG')
-
-bee <- add.rule(
-                strategy  = bee,
-                name      = 'ruleSignal',
-                arguments = list(sigcol    = 'fast.lt.dn',
-                                 sigval    = TRUE,
-                                 orderqty  = 'all',
-                                 ordertype = 'market',
-                                 orderside = 'long'),
-                type      = 'exit',
-                label     = 'ExitLONG')
-
-bee <- add.rule(
-                strategy  = bee,
-                name      = 'ruleSignal',
-                arguments = list(sigcol     = 'fast.lt.dn',
-                                  sigval    = TRUE,
-                                  orderqty  =  -100,
-                                  ordertype = 'market',
-                                  orderside = 'short',
-                                  osFUN     = 'osMaxPos'),
-                type      = 'enter',
-                label     = 'EnterSHORT')
-
-bee <- add.rule(
-                strategy  = bee,
-                name      = 'ruleSignal',
-                arguments = list(sigcol     = 'fast.gt.up',
-                                 sigval     = TRUE,
-                                 orderqty   = 'all',
-                                 ordertype  = 'market',
-                                 orderside  = 'short'),
-                type      = 'exit',
-                label     = 'ExitSHORT')
-
-############################# APPLY STRATEGY ################################
-
-out = applyStrategy(bee, port, prefer='Open', verbose=FALSE)
-
-############################# UPDATE ########################################
-
-updatePortf(port, 'sym', Date=paste('::',as.Date(Sys.time()),sep=''))
-
-

Deleted: pkg/quantstrat/inst/tests/xtestthat_bbands.R
===================================================================
--- pkg/quantstrat/inst/tests/xtestthat_bbands.R	2012-12-30 18:22:05 UTC (rev 1327)
+++ pkg/quantstrat/inst/tests/xtestthat_bbands.R	2012-12-30 18:29:27 UTC (rev 1328)
@@ -1,62 +0,0 @@
-require(testthat)
-
-################## bee.r  #########################
-
-source('bbands_version_for_tests.R')
-
-stratstat   = tradeStats(portfolio.st)
-
-Txns      = stratstat$Num.Txns
-Trades    = stratstat$Num.Trades
-NetPL     = stratstat$Net.Trading.PL
-LWinner   = stratstat$Largest.Winner
-LLoser    = stratstat$Largest.Loser
-MaxDD     = stratstat$Max.Drawdown
-# KFactor   = stratstat$K.Factor
-# RINAindex = stratstat$RINA.Index
-# InMarket  = stratstat$In.Market
-# BuyHold   = stratstat$Buy.Hold
-
-# suppressWarnings(rm(list=ls()))
-# suppressWarnings(rm(list=ls(), pos=.strategy))
-# suppressWarnings(rm(list=ls(), pos=.blotter))
-
-# suppressWarnings(rm("order_book.bbands",pos=.strategy))
-# suppressWarnings(rm("account.bbands","portfolio.bbands",pos=.blotter))
-# suppressWarnings(rm("account.st","portfolio.st","stock.str","stratBBands","initDate","initEq",'start_t','end_t'))
-# 
-######################## RUN TEST SUITE #######################
-
-context('Consistent trade statistics for bbands.R')
-
-test_that("Number of transactions is consistent", 
-          { expect_that(Txns, equals(40)) })
-
-test_that("Number of the number of trades is consistent", 
-          { expect_that(Trades, equals(16)) })
-
-test_that("Net Trading PL is consistent", 
-          { expect_that(NetPL, equals(-1637)) })
-
-test_that("Largest Winner is consistent", 
-          { expect_that(LWinner, equals(656)) })
-
-test_that("Largest Loser is consistent", 
-          { expect_that(LLoser, equals(-1303)) })
-
-test_that("Max Drawdown is consistent", 
-          { expect_that(MaxDD, equals(-3037)) })
-
-# test_that("K Factor is consistent", 
-#           { expect_that(KFactor, equals(0)) })
-# 
-# test_that("RINA Index is consistent", 
-#           { expect_that(RINAindex, equals(0)) })
-# 
-# test_that("Time in Market is consistent", 
-#           { expect_that(InMarket, equals(0)) })
-# 
-# test_that("Buy and Hold is consistent", 
-#           { expect_that(BuyHold, equals(0)) })
-
-

Deleted: pkg/quantstrat/inst/tests/xtestthat_bee.R
===================================================================
--- pkg/quantstrat/inst/tests/xtestthat_bee.R	2012-12-30 18:22:05 UTC (rev 1327)
+++ pkg/quantstrat/inst/tests/xtestthat_bee.R	2012-12-30 18:29:27 UTC (rev 1328)
@@ -1,59 +0,0 @@
-require(testthat)
-
-################## bee.r  #########################
-
-source("bee_version_for_tests.R")
-
-stratstat   = tradeStats(port)
-
-Txns      = stratstat$Num.Txns
-Trades    = stratstat$Num.Trades
-NetPL     = stratstat$Net.Trading.PL
-LWinner   = stratstat$Largest.Winner
-LLoser    = stratstat$Largest.Loser
-MaxDD     = stratstat$Max.Drawdown
-# KFactor   = stratstat$K.Factor
-# RINAindex = stratstat$RINA.Index
-# InMarket  = stratstat$In.Market
-# BuyHold   = stratstat$Buy.Hold
-
-
-# suppressWarnings(rm(list=ls()))
-# suppressWarnings(rm(list=ls(), pos=.strategy))
-# suppressWarnings(rm(list=ls(), pos=.blotter))
-
-######################## RUN TEST SUITE #######################
-
-context("Consistent trade statistics for bee.R")
-
-test_that("Number of transactions is consistent", 
-          { expect_that(Txns, equals(18)) })
-
-test_that("Number of the number of trades is consistent", 
-          { expect_that(Trades, equals(12)) })
-
-test_that("Net Trading PL is consistent", 
-          { expect_that(NetPL, equals(199)) })
-
-test_that("Largest Winner is consistent", 
-          { expect_that(LWinner, equals(1336)) })
-
-test_that("Largest Loser is consistent", 
-          { expect_that(LLoser, equals(-525)) })
-
-test_that("Max Drawdown is consistent", 
-          { expect_that(MaxDD, equals(-20359)) })
-
-# test_that("K Factor is consistent", 
-#           { expect_that(KFactor, equals(0)) })
-# 
-# test_that("RINA Index is consistent", 
-#           { expect_that(RINAindex, equals(0)) })
-# 
-# test_that("Time in Market is consistent", 
-#           { expect_that(InMarket, equals(0)) })
-# 
-# test_that("Buy and Hold is consistent", 
-#           { expect_that(BuyHold, equals(0)) })
-
-



More information about the Blotter-commits mailing list