[Blotter-commits] r1356 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jan 15 14:11:18 CET 2013
Author: braverock
Date: 2013-01-15 14:11:18 +0100 (Tue, 15 Jan 2013)
New Revision: 1356
Modified:
pkg/quantstrat/demo/maCross.R
Log:
- add temporary workaround for xts Date issue
- add parameter wrapper for in_test
- add calls to getOrderBook and tradeStats
Modified: pkg/quantstrat/demo/maCross.R
===================================================================
--- pkg/quantstrat/demo/maCross.R 2013-01-13 20:07:28 UTC (rev 1355)
+++ pkg/quantstrat/demo/maCross.R 2013-01-15 13:11:18 UTC (rev 1356)
@@ -5,13 +5,26 @@
#########################################################################################################################################################################
require(quantstrat)
+
+###############
+# workaround to xts Date handling, remove later
+ttz<-Sys.getenv('TZ')
+Sys.setenv(TZ='UTC')
+
suppressWarnings(rm("order_book.macross",pos=.strategy))
suppressWarnings(rm("account.macross","portfolio.macross",pos=.blotter))
suppressWarnings(rm("account.st","portfolio.st","stock.str","stratMACROSS","initDate","initEq",'start_t','end_t'))
+
+
stock.str='AAPL' # what are we trying it on
currency('USD')
stock(stock.str,currency='USD',multiplier=1)
-initDate='2005-12-31'
+
+if(!isTRUE(in_test)){
+ initDate='2005-12-31'
+ endDate=Sys.Date()
+}
+
initEq=1000000
portfolio.st='macross'
account.st='macross'
@@ -35,7 +48,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)
+getSymbols(stock.str,from=initDate,to=endDate)
for(i in stock.str)
assign(i, adjustOHLC(get(i),use.Adjusted=TRUE))
@@ -54,6 +67,12 @@
add_SMA(n=50 , on=1,col='blue')
add_SMA(n=200, on=1)
+book = getOrderBook('macross')
+stats = tradeStats('macross')
+
+#Date workaround, remove later
+Sys.setenv(TZ=ttz)
+
###############################################################################
# R (http://r-project.org/) Quantitative Strategy Model Framework
#
More information about the Blotter-commits
mailing list