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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Dec 18 14:19:40 CET 2012


Author: milktrader
Date: 2012-12-18 14:19:40 +0100 (Tue, 18 Dec 2012)
New Revision: 1302

Added:
   pkg/quantstrat/inst/tests/nuke_environments.R
   pkg/quantstrat/inst/tests/test_book.R
   pkg/quantstrat/inst/tests/xtestthat_bbands.R
   pkg/quantstrat/inst/tests/xtestthat_bee.R
Removed:
   pkg/quantstrat/inst/tests/testthat_bbands.R
   pkg/quantstrat/inst/tests/testthat_bee.R
Modified:
   pkg/quantstrat/inst/tests/bbands_version_for_tests.R
   pkg/quantstrat/inst/tests/blue.R
Log:
reworking framework and adding nuke_environments

Modified: pkg/quantstrat/inst/tests/bbands_version_for_tests.R
===================================================================
--- pkg/quantstrat/inst/tests/bbands_version_for_tests.R	2012-12-17 15:00:15 UTC (rev 1301)
+++ pkg/quantstrat/inst/tests/bbands_version_for_tests.R	2012-12-18 13:19:40 UTC (rev 1302)
@@ -1,8 +1,8 @@
 #################### CLEANUP PREVIOUS TEST ######################
 
- suppressWarnings(rm(list=ls(.strategy), pos=.strategy))
- suppressWarnings(rm(list=ls(.blotter), pos=.blotter))
- suppressWarnings(rm(list=ls()))
+suppressWarnings(rm(list=ls(.strategy), pos=.strategy))
+suppressWarnings(rm(list=ls(.blotter), pos=.blotter))
+suppressWarnings(rm(list=ls()))
 
 ################### LOAD QUANTSTRAT #################
 

Modified: pkg/quantstrat/inst/tests/blue.R
===================================================================
--- pkg/quantstrat/inst/tests/blue.R	2012-12-17 15:00:15 UTC (rev 1301)
+++ pkg/quantstrat/inst/tests/blue.R	2012-12-18 13:19:40 UTC (rev 1302)
@@ -73,26 +73,37 @@
 blue <- add.rule(
                 strategy  = blue,
                 name      = 'ruleSignal',
-                arguments = list(sigcol    = 'fast.gt.slow',
+                arguments = list(sigcol    = 'fast.lt.slow',
                                  sigval    = TRUE,
-                                 orderqty  = 100,
+                                 orderqty  = 'all',
                                  ordertype = 'market',
                                  orderside = 'long'),
+                type      = 'exit',
+                label     = 'ExitLONG')
 
-                type      = 'enter',
-                label     = 'EnterLONG')
+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')
 
 blue <- add.rule(
                 strategy  = blue,
                 name      = 'ruleSignal',
-                arguments = list(sigcol    = 'fast.lt.slow',
+                arguments = list(sigcol    = 'fast.gt.slow',
                                  sigval    = TRUE,
-                                 orderqty  = 'all',
+                                 orderqty  = 100,
                                  ordertype = 'market',
                                  orderside = 'long'),
-                type      = 'exit',
-                label     = 'ExitLONG')
 
+                type      = 'enter',
+                label     = 'EnterLONG')
+
 blue <- add.rule(
                 strategy  = blue,
                 name      = 'ruleSignal',
@@ -104,17 +115,6 @@
                 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)
@@ -123,8 +123,8 @@
 
 updatePortf(port, 'spx', Date=paste('::',as.Date(Sys.time()),sep=''))
 
-########################### USEFUL CONTAINERS #############################
+########################### CONTAINERS CALLED IN TESTING #####################
 
-blueStats = tradeStats(port)
+book = getOrderBook(port)
 
 

Added: pkg/quantstrat/inst/tests/nuke_environments.R
===================================================================
--- pkg/quantstrat/inst/tests/nuke_environments.R	                        (rev 0)
+++ pkg/quantstrat/inst/tests/nuke_environments.R	2012-12-18 13:19:40 UTC (rev 1302)
@@ -0,0 +1,3 @@
+suppressWarnings(rm(list=ls(.strategy), pos=.strategy))
+suppressWarnings(rm(list=ls(.blotter), pos=.blotter))
+suppressWarnings(rm(list=ls()))

Added: pkg/quantstrat/inst/tests/test_book.R
===================================================================
--- pkg/quantstrat/inst/tests/test_book.R	                        (rev 0)
+++ pkg/quantstrat/inst/tests/test_book.R	2012-12-18 13:19:40 UTC (rev 1302)
@@ -0,0 +1,33 @@
+require(testthat)
+
+######################## DEFINE VARIABLES TO BE TESTED #######
+
+source('blue.R')
+
+rule   = book$bluePort$spx[,'Rule']
+status = book$bluePort$spx[,'Order.Status']
+qty    = book$bluePort$spx[,'Order.Qty']
+
+
+
+######################## RUN TEST SUITE ######################
+
+context("Order Book is consistent ")
+
+test_that("The first entry is not a trade", 
+          { expect_that(as.character(rule[1]) =="", is_true()) })
+
+test_that("The first trade is a long entry", 
+          { expect_that(as.character(rule[3]) =="EnterLONG", is_true()) })
+
+test_that("The first short exit order is rejected", 
+          { expect_that(as.character(status[2]) =="rejected", is_true()) })
+
+test_that("The first short exit order is rejected", 
+          { expect_that(as.character(status[2]) =="rejected", is_true()) })
+
+test_that("The first long signal is entered long", 
+          { expect_that(as.character(qty[3]) =="100", is_true()) })
+
+test_that("The first short signal is entered short", 
+          { expect_that(as.character(qty[5]) =="-100", is_true()) })

Deleted: pkg/quantstrat/inst/tests/testthat_bbands.R
===================================================================
--- pkg/quantstrat/inst/tests/testthat_bbands.R	2012-12-17 15:00:15 UTC (rev 1301)
+++ pkg/quantstrat/inst/tests/testthat_bbands.R	2012-12-18 13:19:40 UTC (rev 1302)
@@ -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/testthat_bee.R
===================================================================
--- pkg/quantstrat/inst/tests/testthat_bee.R	2012-12-17 15:00:15 UTC (rev 1301)
+++ pkg/quantstrat/inst/tests/testthat_bee.R	2012-12-18 13:19:40 UTC (rev 1302)
@@ -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)) })
-
-

Added: pkg/quantstrat/inst/tests/xtestthat_bbands.R
===================================================================
--- pkg/quantstrat/inst/tests/xtestthat_bbands.R	                        (rev 0)
+++ pkg/quantstrat/inst/tests/xtestthat_bbands.R	2012-12-18 13:19:40 UTC (rev 1302)
@@ -0,0 +1,62 @@
+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)) })
+
+

Added: pkg/quantstrat/inst/tests/xtestthat_bee.R
===================================================================
--- pkg/quantstrat/inst/tests/xtestthat_bee.R	                        (rev 0)
+++ pkg/quantstrat/inst/tests/xtestthat_bee.R	2012-12-18 13:19:40 UTC (rev 1302)
@@ -0,0 +1,59 @@
+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