[Blotter-commits] r450 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Nov 13 19:30:41 CET 2010
Author: braverock
Date: 2010-11-13 19:30:40 +0100 (Sat, 13 Nov 2010)
New Revision: 450
Modified:
pkg/quantstrat/demo/faber.R
pkg/quantstrat/demo/faberMC.R
pkg/quantstrat/demo/macd.R
pkg/quantstrat/demo/rsi.R
Log:
- minor updates to demo code
Modified: pkg/quantstrat/demo/faber.R
===================================================================
--- pkg/quantstrat/demo/faber.R 2010-11-13 18:29:16 UTC (rev 449)
+++ pkg/quantstrat/demo/faber.R 2010-11-13 18:30:40 UTC (rev 450)
@@ -117,8 +117,8 @@
# hack for new quantmod graphics, remove later
themelist<-chart_theme()
-themelist$up.col<-'lightgreen'
-themelist$down.col<-'pink'
+themelist$col$up.col<-'lightgreen'
+themelist$col$dn.col<-'pink'
for(symbol in symbols){
dev.new()
chart.Posn(Portfolio='faber',Symbol=symbol,theme=themelist)
Modified: pkg/quantstrat/demo/faberMC.R
===================================================================
--- pkg/quantstrat/demo/faberMC.R 2010-11-13 18:29:16 UTC (rev 449)
+++ pkg/quantstrat/demo/faberMC.R 2010-11-13 18:30:40 UTC (rev 450)
@@ -138,8 +138,8 @@
# hack for new quantmod graphics, remove later
themelist<-chart_theme()
-themelist$up.col<-'lightgreen'
-themelist$down.col<-'pink'
+themelist$col$up.col<-'lightgreen'
+themelist$col$dn.col<-'pink'
for(symbol in symbols){
dev.new()
chart.Posn(Portfolio=symbol,Symbol=symbol,theme=themelist)
Modified: pkg/quantstrat/demo/macd.R
===================================================================
--- pkg/quantstrat/demo/macd.R 2010-11-13 18:29:16 UTC (rev 449)
+++ pkg/quantstrat/demo/macd.R 2010-11-13 18:30:40 UTC (rev 450)
@@ -26,6 +26,12 @@
currency('USD')
stock(stock.str,currency='USD',multiplier=1)
+#or use fake data
+#stock.str='sample_matrix' # what are we trying it on
+#data(sample_matrix) # data included in package xts
+#sample_matrix<-as.xts(sample_matrix)
+
+
initDate='2006-12-31'
initEq=1000000
portfolio.st='macd'
@@ -45,6 +51,8 @@
stratMACD <- add.rule(strategy = stratMACD,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty=100, ordertype='market', orderside='long', threshold=NULL),type='enter')
stratMACD <- add.rule(strategy = stratMACD,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty=-100, ordertype='stoplimit', orderside='long', threshold=.85,tmult=TRUE),type='risk')
+# alternately, use a trailing order
+# stratMACD <- add.rule(strategy = stratMACD,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty=-100, ordertype='stoptrailing', orderside='long', threshold=.9,tmult=TRUE),type='risk')
stratMACD <- add.rule(strategy = stratMACD,name='ruleSignal', arguments = list(sigcol="signal.lt.zero",sigval=TRUE, orderqty='all', ordertype='market', orderside='long', threshold=NULL),type='exit')
getSymbols(stock.str,from=initDate)
@@ -62,6 +70,9 @@
chart.Posn(Portfolio=portfolio.st,Symbol=stock.str)
plot(add_MACD(fast=fastMA, slow=slowMA, signal=signalMA,maType="EMA"))
+#look at the order book
+getOrderBook('macd')
+
###############################################################################
# R (http://r-project.org/) Quantitative Strategy Model Framework
#
Modified: pkg/quantstrat/demo/rsi.R
===================================================================
--- pkg/quantstrat/demo/rsi.R 2010-11-13 18:29:16 UTC (rev 449)
+++ pkg/quantstrat/demo/rsi.R 2010-11-13 18:30:40 UTC (rev 450)
@@ -71,8 +71,8 @@
# hack for new quantmod graphics, remove later
themelist<-chart_theme()
-themelist$up.col<-'lightgreen'
-themelist$down.col<-'pink'
+themelist$col$up.col<-'lightgreen'
+themelist$col$dn.col<-'pink'
for(symbol in symbols){
dev.new()
chart.Posn(Portfolio=port.st,Symbol=symbol,theme=themelist)
More information about the Blotter-commits
mailing list