[Blotter-commits] r1724 - pkg/quantstrat/demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 14 13:54:08 CET 2015


Author: bodanker
Date: 2015-12-14 13:54:08 +0100 (Mon, 14 Dec 2015)
New Revision: 1724

Modified:
   pkg/quantstrat/demo/bbands.R
   pkg/quantstrat/demo/bee.R
   pkg/quantstrat/demo/faber.R
   pkg/quantstrat/demo/faberMC.R
   pkg/quantstrat/demo/faber_rebal.R
   pkg/quantstrat/demo/luxor.1.strategy.basic.R
   pkg/quantstrat/demo/luxor.2.add.paramsets.R
   pkg/quantstrat/demo/luxor.3.paramset.sma.R
   pkg/quantstrat/demo/luxor.4.paramset.timespan.R
   pkg/quantstrat/demo/luxor.5.strategy.ordersets.R
   pkg/quantstrat/demo/luxor.6.paramset.stoploss.R
   pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R
   pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R
   pkg/quantstrat/demo/luxor.7.exit.and.risk.R
   pkg/quantstrat/demo/luxor.8.walk.forward.R
   pkg/quantstrat/demo/luxor.include.R
   pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R
   pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R
   pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R
   pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R
   pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R
   pkg/quantstrat/demo/luxor.sample.walk.forward.R
   pkg/quantstrat/demo/maCross.R
   pkg/quantstrat/demo/macd.R
   pkg/quantstrat/demo/macdParameters.R
   pkg/quantstrat/demo/macdRebalancing.R
   pkg/quantstrat/demo/pair_trade.R
   pkg/quantstrat/demo/rocema.R
   pkg/quantstrat/demo/rsi.R
   pkg/quantstrat/demo/signal.RSI.R
   pkg/quantstrat/demo/signal.SMA.R
Log:
Do not set initDate argument in demos

Do not set initDate for initPortf, initAcct, or initOrders in any of the
demos. Specifying the initDate argument incorrectly can cause errors
that are difficult for users to diagnose, so we shouldn't provide demos
that suggest users need to set initDate manually.

Rename initDate to startDate in all demos in order to avoid confusion
with initDate argument to initPortf, initAcct, and initOrders.


Modified: pkg/quantstrat/demo/bbands.R
===================================================================
--- pkg/quantstrat/demo/bbands.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/bbands.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -1,7 +1,7 @@
 require(quantstrat)
 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'))
+suppressWarnings(rm("account.st","portfolio.st","stock.str","stratBBands","startDate","initEq",'start_t','end_t'))
 
 # some things to set up here
 stock.str='IBM' # what are we trying it on
@@ -14,27 +14,16 @@
 currency('USD')
 stock(stock.str,currency='USD',multiplier=1)
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
-initDate='2006-12-31'
+startDate='2006-12-31'
 initEq=1000000
 
 portfolio.st='bbands'
 account.st='bbands'
 
-initPortf(portfolio.st,symbols=stock.str, initDate=initDate)
-initAcct(account.st,portfolios='bbands', initDate=initDate)
-initOrders(portfolio=portfolio.st,initDate=initDate)
-addPosLimit(portfolio.st, stock.str, initDate, 200, 2 ) #set max pos
+initPortf(portfolio.st, symbols=stock.str)
+initAcct(account.st,portfolios='bbands')
+initOrders(portfolio=portfolio.st)
+addPosLimit(portfolio.st, stock.str, startDate, 200, 2 ) #set max pos
 
 # set up parameters
 maType='SMA'
@@ -113,7 +102,7 @@
 
 #TODO add thresholds and stop-entry and stop-exit handling to test
 
-getSymbols(stock.str,from=initDate,index.class=c('POSIXt','POSIXct'))
+getSymbols(stock.str,from=startDate,index.class=c('POSIXt','POSIXct'))
 start_t<-Sys.time()
 out<-try(applyStrategy(strategy='bbands' , portfolios='bbands',parameters=list(sd=SD,n=N)) )
 
@@ -144,9 +133,3 @@
 # $Id$
 #
 ###############################################################################
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/bee.R
===================================================================
--- pkg/quantstrat/demo/bee.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/bee.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -4,16 +4,9 @@
 # copyright (c) 2009-2012, Algorithm Alpha, LLC
 # Licensed GPL-2
 #
-##### PLACE DEMO AND TEST DATES HERE #################
+##### PLACE DEMO DATES HERE #################
 
-if(isTRUE(options('in_test')$in_test))
-  # use test dates
-  {initDate="2011-01-01" 
-  endDate="2012-12-31"   
-  } else
-  # use demo defaults
-  {initDate="1999-12-31"
-  endDate=Sys.Date()}
+startDate="1999-12-31"
 
 ############################# DEFINE VARIABLES ##############################
 
@@ -28,15 +21,15 @@
 ############################# GET DATA ######################################
 
 suppressMessages(require(quantstrat))
-getSymbols(sym, from=initDate, to=endDate, index.class=c("POSIXt","POSIXct"))
+getSymbols(sym, from=startDate, index.class=c("POSIXt","POSIXct"))
 
 ############################# 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 )
+initPortf(port, sym)
+initAcct(acct, port, initEq=initEq)
+initOrders(port)
 bee = strategy(port)
 
 ############################# MAX POSITION LOGIC ############################
@@ -44,7 +37,7 @@
 addPosLimit(
             portfolio=port,
             symbol=sym, 
-            timestamp=initDate,  
+            timestamp=startDate,  
             maxpos=100)
 
 
@@ -140,7 +133,6 @@
 
 ########################### USEFUL CONTAINERS #############################
 
-invisible(mktdata)
 stratStats   = tradeStats(port)
 stratReturns = PortfReturns(acct)
 
@@ -152,9 +144,3 @@
 
 cat('Sortino Ratio for bumblebee is: ', SortinoRatio(stratReturns), '\n')
 
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-book  = getOrderBook(port)
-stats = tradeStats(port)
-rets  = PortfReturns(acct)
-txns  = getTxns(port, sym)
-################################################################

Modified: pkg/quantstrat/demo/faber.R
===================================================================
--- pkg/quantstrat/demo/faber.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/faber.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -53,22 +53,11 @@
 # Try to clean up in case the demo was run previously
 suppressWarnings(rm("account.faber","portfolio.faber",pos=.blotter))
 suppressWarnings(rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate", "equity", 
-            "GSPC", "stratFaber", "initDate", "initEq", "Posn", "UnitSize", "verbose"))
+            "GSPC", "stratFaber", "startDate", "initEq", "Posn", "UnitSize", "verbose"))
 suppressWarnings(rm("order_book.faber",pos=.strategy))
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 # Set initial values
-initDate='1997-12-31'
+startDate='1997-12-31'
 initEq=100000
 
 # Set up instruments with FinancialInstruments package
@@ -92,9 +81,9 @@
 }
 
 # Initialize portfolio and account
-initPortf('faber', symbols=symbols, initDate=initDate)
-initAcct('faber', portfolios='faber', initDate=initDate, initEq=100000)
-initOrders(portfolio='faber', initDate=initDate)
+initPortf('faber', symbols=symbols)
+initAcct('faber', portfolios='faber', initEq=initEq)
+initOrders(portfolio='faber')
 
 print("setup completed")
 
@@ -175,9 +164,3 @@
 # $Id$
 #
 ###############################################################################
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/faberMC.R
===================================================================
--- pkg/quantstrat/demo/faberMC.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/faberMC.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -48,22 +48,11 @@
 # Try to clean up in case the demo was run previously
 suppressWarnings(rm("account.faber","account.faberMC","portfolio.faber","portfolio.combMC", 
                         "portfolio.GDAXI", "portfolio.GSPC", "portfolio.N225",pos=.blotter))
-suppressWarnings(rm("ltaccount","ltportfolio","ClosePrice","CurrentDate","equity","stratFaber","initDate","initEq","Posn","UnitSize","verbose"))
+suppressWarnings(rm("ltaccount","ltportfolio","ClosePrice","CurrentDate","equity","stratFaber","startDate","initEq","Posn","UnitSize","verbose"))
 suppressWarnings(rm("order_book.faber","order_book.combMC", "order_book.GDAXI", "order_book.GSPC", "order_book.N225", pos=.strategy))
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 # Set initial values
-initDate='2000-01-01'
+startDate='2000-01-01'
 initEq=100000
 
 # Set up instruments with FinancialInstruments package
@@ -79,7 +68,7 @@
 colnames(USDJPY)<-"USDJPY"
 colnames(EURUSD)<-"EURUSD"
 
-getSymbols(symbols,from=initDate)
+getSymbols(symbols,from=startDate)
 #takes out the carat
 symbols = c("GSPC", "N225", "GDAXI")
 
@@ -95,12 +84,12 @@
     indexFormat(x)<-'%Y-%m-%d'
     colnames(x)<-gsub("x",symbol,colnames(x))
     assign(symbol,x)
-	initPortf(symbol, symbols=symbol, initDate=initDate, currency=getInstrument(symbol)$currency)
-	initOrders(portfolio=symbol, initDate=initDate)
+	initPortf(symbol, symbols=symbol, currency=getInstrument(symbol)$currency)
+	initOrders(portfolio=symbol)
 }
 
 
-initAcct('faberMC', portfolios=symbols, initDate=initDate, currency="USD")
+initAcct('faberMC', portfolios=symbols, currency="USD")
 
 # Initialize portfolio and account
 
@@ -143,8 +132,8 @@
 print(end_t-start_t)
 
 #and a combined portfolio
-initPortf('combMC', symbols=symbols, initDate=initDate, currency="USD")
-initOrders(portfolio= 'combMC', initDate=initDate)
+initPortf('combMC', symbols=symbols, currency="USD")
+initOrders(portfolio= 'combMC')
 comb.out<-applyStrategy(strategy=stratFaber , portfolios='combMC')
 updatePortf(Portfolio='combMC',Dates=paste('::',as.Date(Sys.time()),sep=''))
 
@@ -172,9 +161,3 @@
 # $Id: faber.R 371 2010-08-12 20:18:09Z braverock $
 #
 ###############################################################################
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/faber_rebal.R
===================================================================
--- pkg/quantstrat/demo/faber_rebal.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/faber_rebal.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -54,22 +54,11 @@
 # Try to clean up in case the demo was run previously
 suppressWarnings(rm("account.faber","portfolio.faber",pos=.blotter))
 suppressWarnings(rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate", "equity", 
-            "GSPC", "stratFaber", "initDate", "initEq", "Posn", "UnitSize", "verbose"))
+            "GSPC", "stratFaber", "startDate", "initEq", "Posn", "UnitSize", "verbose"))
 suppressWarnings(rm("order_book.faber",pos=.strategy))
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 # Set initial values
-initDate='1997-12-31'
+startDate='1997-12-31'
 initEq=100000
 
 # Set up instruments with FinancialInstruments package
@@ -93,15 +82,15 @@
 }
 
 # Initialize portfolio and account
-initPortf('faber', symbols=symbols, initDate=initDate)
-initAcct('faber', portfolios='faber', initDate=initDate, initEq=100000)
-initOrders(portfolio='faber', initDate=initDate)
+initPortf('faber', symbols=symbols)
+initAcct('faber', portfolios='faber', initEq=100000)
+initOrders(portfolio='faber')
 
 # set intial position limits
 posval<-initEq/length(symbols)
 for(symbol in symbols){
     pos<-round((posval/first(getPrice(get(symbol)))[,1]),-2)
-    addPosLimit('faber',symbol,initDate, maxpos=pos,minpos=-pos)
+    addPosLimit('faber', symbol, startDate, maxpos=pos, minpos=-pos)
 }
 print("setup completed")
 
@@ -193,9 +182,3 @@
 # $Id$
 #
 ###############################################################################
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.1.strategy.basic.R
===================================================================
--- pkg/quantstrat/demo/luxor.1.strategy.basic.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.1.strategy.basic.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -10,17 +10,6 @@
 
 require(quantstrat)
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 source(paste0(path.package("quantstrat"),"/demo/luxor.include.R"))
 .fast = 10
 .slow = 30
@@ -29,12 +18,12 @@
 
 ### blotter
 
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+initPortf(portfolio.st, symbols='GBPUSD', currency='USD')
+initAcct(account.st, portfolios=portfolio.st, currency='USD')
 
 ### quantstrat
 
-initOrders(portfolio.st, initDate=initDate)
+initOrders(portfolio.st)
 
 ### define strategy
 
@@ -145,9 +134,3 @@
 # save the strategy in an .RData object for later retrieval
 
 save.strategy(strategy.st)
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.2.add.paramsets.R
===================================================================
--- pkg/quantstrat/demo/luxor.2.add.paramsets.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.2.add.paramsets.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -8,17 +8,6 @@
 
 require(quantstrat)
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 source(paste0(path.package("quantstrat"),"/demo/luxor.include.R"))
 
 ###
@@ -116,9 +105,3 @@
 ###
 
 save.strategy(strategy.st)
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.3.paramset.sma.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.paramset.sma.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.3.paramset.sma.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -16,12 +16,12 @@
 
 ### blotter
 
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+initPortf(portfolio.st, symbols='GBPUSD', currency='USD')
+initAcct(account.st, portfolios=portfolio.st, currency='USD')
 
 ### quantstrat
 
-initOrders(portfolio.st, initDate=initDate)
+initOrders(portfolio.st)
 
 load.strategy(strategy.st)
 

Modified: pkg/quantstrat/demo/luxor.4.paramset.timespan.R
===================================================================
--- pkg/quantstrat/demo/luxor.4.paramset.timespan.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.4.paramset.timespan.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -15,12 +15,12 @@
 
 ### blotter
 
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+initPortf(portfolio.st, symbols='GBPUSD', currency='USD')
+initAcct(account.st, portfolios=portfolio.st, currency='USD')
 
 ### quantstrat
 
-initOrders(portfolio.st, initDate=initDate)
+initOrders(portfolio.st)
 
 load.strategy(strategy.st)
 

Modified: pkg/quantstrat/demo/luxor.5.strategy.ordersets.R
===================================================================
--- pkg/quantstrat/demo/luxor.5.strategy.ordersets.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.5.strategy.ordersets.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -10,17 +10,6 @@
 
 require(quantstrat)
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 source(paste0(path.package("quantstrat"),"/demo/luxor.include.R"))
 
 ### define strategy
@@ -350,9 +339,3 @@
 ###############################################################################
 
 save.strategy(strategy.st)
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoploss.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoploss.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -10,34 +10,23 @@
 
 require(quantstrat)
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 source(paste0(path.package("quantstrat"),"/demo/luxor.include.R"))
 source(paste0(path.package("quantstrat"),"/demo/luxor.getSymbols.R"))
 
 ###
 
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+initPortf(portfolio.st, symbols='GBPUSD', currency='USD')
 addPosLimit(
             portfolio=portfolio.st,
             symbol='GBPUSD',
-            timestamp=initDate,
+            timestamp=startDate,
             maxpos=.orderqty)
 
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+initAcct(account.st, portfolios=portfolio.st, currency='USD')
 
 ###
 
-initOrders(portfolio.st, initDate=initDate)
+initOrders(portfolio.st)
 
 load.strategy(strategy.st)
 
@@ -72,9 +61,3 @@
 View(t(stats))
 
 plot(100*stats$StopLossLONG, stats$Net.Trading.PL, type='b', xlab='Stoploss %', ylab='Net.Trading.PL', main='Luxor')
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -10,34 +10,23 @@
 
 require(quantstrat)
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 source(paste0(path.package("quantstrat"),"/demo/luxor.include.R"))
 source(paste0(path.package("quantstrat"),"/demo/luxor.getSymbols.R"))
 
 ###
 
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+initPortf(portfolio.st, symbols='GBPUSD', currency='USD')
 addPosLimit(
             portfolio=portfolio.st,
             symbol='GBPUSD',
-            timestamp=initDate,
+            timestamp=startDate,
             maxpos=.orderqty)
 
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+initAcct(account.st, portfolios=portfolio.st, currency='USD')
 
 ###
 
-initOrders(portfolio.st, initDate=initDate)
+initOrders(portfolio.st)
 
 load.strategy(strategy.st)
 
@@ -72,9 +61,3 @@
 View(t(stats))
 
 plot(100*stats$StopTrailingLONG, stats$Net.Trading.PL, type='b', xlab='StopTrailing %', ylab='Net.Trading.PL', main='Luxor')
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -10,34 +10,23 @@
 
 require(quantstrat)
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 source(paste0(path.package("quantstrat"),"/demo/luxor.include.R"))
 source(paste0(path.package("quantstrat"),"/demo/luxor.getSymbols.R"))
 
 ###
 
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+initPortf(portfolio.st, symbols='GBPUSD', currency='USD')
 addPosLimit(
             portfolio=portfolio.st,
             symbol='GBPUSD',
-            timestamp=initDate,
+            timestamp=startDate,
             maxpos=.orderqty)
 
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+initAcct(account.st, portfolios=portfolio.st, currency='USD')
 
 ###
 
-initOrders(portfolio.st, initDate=initDate)
+initOrders(portfolio.st)
 
 load.strategy(strategy.st)
 
@@ -72,9 +61,3 @@
 View(t(stats))
 
 plot(100*stats$TakeProfitLONG, stats$Net.Trading.PL, type='b', xlab='TakeProfit %', ylab='Net.Trading.PL', main='Luxor')
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.7.exit.and.risk.R
===================================================================
--- pkg/quantstrat/demo/luxor.7.exit.and.risk.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.7.exit.and.risk.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -12,23 +12,12 @@
 
 source(paste0(path.package("quantstrat"),"/demo/luxor.include.R"))
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
 source(paste0(path.package("quantstrat"),"/demo/luxor.getSymbols.R"))
 
 ### blotter
 
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+initPortf(portfolio.st, symbols='GBPUSD', currency='USD')
+initAcct(account.st, portfolios=portfolio.st, currency='USD')
 
 ### quantstrat
 
@@ -45,10 +34,10 @@
 addPosLimit(
             portfolio=portfolio.st,
             symbol='GBPUSD',
-            timestamp=initDate,
+            timestamp=startDate,
             maxpos=.orderqty)
 
-initOrders(portfolio.st, initDate=initDate)
+initOrders(portfolio.st)
 
 applyStrategy(strategy.st, portfolio.st, prefer='Open')
 
@@ -75,9 +64,3 @@
 chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MAE')
 dev.new()
 chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MFE')
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.8.walk.forward.R
===================================================================
--- pkg/quantstrat/demo/luxor.8.walk.forward.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.8.walk.forward.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -29,12 +29,12 @@
 
 ### blotter
 
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD', initEq=100000)
+initPortf(portfolio.st, symbols='GBPUSD', currency='USD')
+initAcct(account.st, portfolios=portfolio.st, currency='USD', initEq=100000)
 
 ### quantstrat
 
-initOrders(portfolio.st, initDate=initDate)
+initOrders(portfolio.st)
 
 load.strategy(strategy.st)
 
@@ -45,7 +45,7 @@
 addPosLimit(
             portfolio=portfolio.st,
             symbol='GBPUSD',
-            timestamp=initDate,
+            timestamp=startDate,
             maxpos=.orderqty)
 
 ### objective function

Modified: pkg/quantstrat/demo/luxor.include.R
===================================================================
--- pkg/quantstrat/demo/luxor.include.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.include.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -7,9 +7,9 @@
 
 ###
 
-initDate = '2002-10-21'
+startDate = '2002-10-21'
 
-.from=initDate
+.from=startDate
 
 #.to='2008-07-04'
 .to='2002-10-31'

Modified: pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R
===================================================================
--- pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -21,20 +21,3 @@
 	 type='MAE',
 	 scale='cash'
 )
-
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R
===================================================================
--- pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -21,21 +21,3 @@
 	 type='MAE',
 	 scale='percent'
 )
-
-
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R
===================================================================
--- pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -21,21 +21,3 @@
 	 type='MFE',
 	 scale='percent'
 )
-
-
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R
===================================================================
--- pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -25,20 +25,3 @@
 	statistics = c("Net.Trading.PL", "maxDrawdown", "Avg.Trade.PL", "Num.Trades", "Profit.Factor"),
 	title = 'Luxor SMA Parameter Scan'
 )
-
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R
===================================================================
--- pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -35,20 +35,3 @@
 	statistics=c('Net.Trading.PL','maxDrawdown',"Avg.Trade.PL",'Num.Trades',"Profit.Factor"),
 	title = 'Luxor Intraday TimeWindow Scan'
 )
-
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/luxor.sample.walk.forward.R
===================================================================
--- pkg/quantstrat/demo/luxor.sample.walk.forward.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/luxor.sample.walk.forward.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -12,19 +12,3 @@
 
 chart.forward.training(paste0(path.package("quantstrat"),'/data/luxor.wfa.ples.RData'))
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/maCross.R
===================================================================
--- pkg/quantstrat/demo/maCross.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/maCross.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -20,24 +20,13 @@
 currency('USD')
 stock(stock.str,currency='USD',multiplier=1)
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-if(isTRUE(options('in_test')$in_test)){
-  # use test dates
-  initDate="2011-01-01" 
-  endDate="2012-12-31"   
-} else {
-  # use demo defaults
-  initDate="1999-12-31"
-  endDate=Sys.Date()
-}
-
+startDate="1999-12-31"
 initEq=1000000
 portfolio.st='macross'
 account.st='macross'
-initPortf(portfolio.st,symbols=stock.str, initDate=initDate)
-initAcct(account.st,portfolios=portfolio.st, initDate=initDate,initEq=initEq)
-initOrders(portfolio=portfolio.st,initDate=initDate)
+initPortf(portfolio.st,symbols=stock.str)
+initAcct(account.st,portfolios=portfolio.st, initEq=initEq)
+initOrders(portfolio=portfolio.st)
 
 stratMACROSS<- strategy(portfolio.st)
 
@@ -55,7 +44,7 @@
 # stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal', arguments = list(sigcol="ma50.lt.ma200",sigval=TRUE, orderqty=-100, ordertype='market', orderside='short'),type='enter')
 # stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal', arguments = list(sigcol="ma50.gt.ma200",sigval=TRUE, orderqty=100, ordertype='market', orderside='short'),type='exit')
 
-getSymbols(stock.str,from=initDate,to=endDate)
+getSymbols(stock.str,from=startDate)
 for(i in stock.str)
   assign(i, adjustOHLC(get(i),use.Adjusted=TRUE))
 
@@ -96,9 +85,3 @@
 # $Id$
 #
 ###############################################################################
-#
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
-# book  = getOrderBook(port)
-# stats = tradeStats(port)
-# rets  = PortfReturns(acct)
-################################################################

Modified: pkg/quantstrat/demo/macd.R
===================================================================
--- pkg/quantstrat/demo/macd.R	2015-12-11 14:53:33 UTC (rev 1723)
+++ pkg/quantstrat/demo/macd.R	2015-12-14 12:54:08 UTC (rev 1724)
@@ -13,7 +13,7 @@
 require(quantstrat)
 suppressWarnings(rm("order_book.macd",pos=.strategy))
 suppressWarnings(rm("account.macd","portfolio.macd",pos=.blotter))
-suppressWarnings(rm("account.st","portfolio.st","stock.str","stratMACD","initDate","initEq",'start_t','end_t'))
+suppressWarnings(rm("account.st","portfolio.st","stock.str","stratMACD","startDate","initEq",'start_t','end_t'))
 
 #correct for TZ issues if they crop up
 oldtz<-Sys.getenv('TZ')
@@ -38,25 +38,14 @@
 #data(sample_matrix)                 # data included in package xts
 #sample_matrix<-as.xts(sample_matrix)
 
-##### PLACE DEMO AND TEST DATES HERE #################
-#
-#if(isTRUE(options('in_test')$in_test))
-#  # use test dates
-#  {initDate="2011-01-01" 
-#  endDate="2012-12-31"   
-#  } else
-#  # use demo defaults
-#  {initDate="1999-12-31"
-#  endDate=Sys.Date()}
-
-initDate='2006-12-31'
+startDate='2006-12-31'
 initEq=1000000
 portfolio.st='macd'
 account.st='macd'
 
-initPortf(portfolio.st,symbols=stock.str, initDate=initDate)
-initAcct(account.st,portfolios=portfolio.st, initDate=initDate)
-initOrders(portfolio=portfolio.st,initDate=initDate)
+initPortf(portfolio.st,symbols=stock.str)
+initAcct(account.st,portfolios=portfolio.st)
+initOrders(portfolio=portfolio.st)
 
 strat.st<-portfolio.st
 # define the strategy
@@ -125,7 +114,7 @@
 #end rules
 ####
 
-getSymbols(stock.str,from=initDate, to='2014-06-01')
+getSymbols(stock.str,from=startDate, to='2014-06-01')
 start_t<-Sys.time()
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/blotter -r 1724


More information about the Blotter-commits mailing list