[Blotter-commits] r282 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 14 18:09:15 CET 2010
Author: braverock
Date: 2010-03-14 18:09:15 +0100 (Sun, 14 Mar 2010)
New Revision: 282
Modified:
pkg/quantstrat/demo/BBands.R
Log:
- move setup strings to top of file
Modified: pkg/quantstrat/demo/BBands.R
===================================================================
--- pkg/quantstrat/demo/BBands.R 2010-03-09 23:19:16 UTC (rev 281)
+++ pkg/quantstrat/demo/BBands.R 2010-03-14 17:09:15 UTC (rev 282)
@@ -1,10 +1,16 @@
require(quantstrat)
try(rm("order_book.bbands",pos=.strategy),silent=TRUE)
try(rm("account.bbands","portfolio.bbands",pos=.blotter),silent=TRUE)
-try(rm("account.st","portfolio.st","IBM","s","initDate","initEq",'start_t','end_t'),silent=TRUE)
+try(rm("account.st","portfolio.st","stock.str","s","initDate","initEq",'start_t','end_t'),silent=TRUE)
+# some things to set up here
+stock.str='IBM' # what are we trying it on
+SD = 2 # how many standard deviations, traditionally 2
+N = 20 # how many periods for the moving average
+
+
currency('USD')
-stock('IBM',currency='USD',multiplier=1)
+stock(stock.str,currency='USD',multiplier=1)
initDate='2006-12-31'
initEq=1000000
@@ -12,13 +18,12 @@
portfolio.st='bbands'
account.st='bbands'
-initPortf(portfolio.st,symbols='IBM', initDate=initDate)
+initPortf(portfolio.st,symbols=stock.str, initDate=initDate)
initAcct(account.st,portfolios='bbands', initDate=initDate)
initOrders(portfolio=portfolio.st,initDate=initDate)
s <- strategy("bbands")
-SD = 2
-N = 20
+
#s <- add.indicator(strategy = s, name = "SMA", arguments = list(x = quote(Cl(mktdata)), n=10), label="SMA10")
s <- add.indicator(strategy = s, name = "BBands", arguments = list(HLC = quote(HLC(mktdata)), sd=SD, n=N, maType=quote(SMA)))
@@ -45,7 +50,7 @@
s <- add.rule(s,name='ruleSignal', arguments = list(data=quote(mktdata),sigcol="Cross.Mid",sigval=TRUE, orderqty= 'all', ordertype='market', orderside=NULL, threshold=NULL),type='exit')
#TODO add thresholds and stop-entry and stop-exit handling to test
-getSymbols("IBM",from=initDate)
+getSymbols(stock.str,from=initDate)
start_t<-Sys.time()
out<-try(applyStrategy(strategy='s' , portfolios='bbands'))
# look at the order book
@@ -53,7 +58,7 @@
end_t<-Sys.time()
end_t-start_t
updatePortf(Portfolio='bbands',Dates=paste('::',as.Date(Sys.time()),sep=''))
-chart.Posn(Portfolio='bbands',Symbol='IBM',theme='white')
+chart.Posn(Portfolio='bbands',Symbol=stock.str,theme='white')
plot(addBBands(on=1,sd=SD,n=N))
###############################################################################
# R (http://r-project.org/) Quantitative Strategy Model Framework
More information about the Blotter-commits
mailing list