[Blotter-commits] r216 - pkg/blotter/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jan 29 05:11:50 CET 2010
Author: peter_carl
Date: 2010-01-29 05:11:44 +0100 (Fri, 29 Jan 2010)
New Revision: 216
Modified:
pkg/blotter/demo/amzn_test.R
pkg/blotter/demo/longtrend.R
Log:
- moved cleanup to the beginning
Modified: pkg/blotter/demo/amzn_test.R
===================================================================
--- pkg/blotter/demo/amzn_test.R 2010-01-28 22:29:43 UTC (rev 215)
+++ pkg/blotter/demo/amzn_test.R 2010-01-29 04:11:44 UTC (rev 216)
@@ -1,4 +1,8 @@
require(blotter)
+
+# Remove portfolio and account data if run previously
+try(rm("portfolio.amzn_port","account.amzn_acct",pos=.blotter))
+
# load the example data
data("amzn")
currency("USD")
@@ -14,15 +18,12 @@
# update the portfolio stats
updatePortf("amzn_port",Dates="2010-01-14")
-# getPortfolio("amzn_port")
# update the account P&L
updateAcct("amzn_acct",Dates="2010-01-14")
-# getAccount("amzn_acct")
# and look at it
chart.Posn("amzn_port","amzn",Dates="2010-01-14",theme='white')
-#and clean up the side effects of the demo
-rm("amzn","amzn.trades")
-rm("portfolio.amzn_port","account.amzn_acct",pos=.blotter)
\ No newline at end of file
+portfolio = getPortfolio("amzn_port")
+account = getAccount("amzn_acct")
\ No newline at end of file
Modified: pkg/blotter/demo/longtrend.R
===================================================================
--- pkg/blotter/demo/longtrend.R 2010-01-28 22:29:43 UTC (rev 215)
+++ pkg/blotter/demo/longtrend.R 2010-01-29 04:11:44 UTC (rev 216)
@@ -47,6 +47,10 @@
require(TTR)
require(blotter)
+# Try to clean up in case the demo was run previously
+try(rm("account.longtrend","portfolio.longtrend",pos=.blotter))
+
+
# Set initial values
initDate='1997-12-31'
initEq=100000
@@ -104,16 +108,18 @@
updateEndEq(account, Dates = CurrentDate)
} # End dates loop
cat('\n')
+
# Chart results with quantmod
chart.Posn(portfolio, Symbol = 'GSPC', Dates = '1998::', theme=chartTheme('white',up.col='lightgreen',dn.col='pink'), type='bar')
plot(addTA(GSPC$SMA10['1998::',],pch=1,type='l',col='darkgreen', on=1))
-cat('\n')
-cat('cleaning up \n')
-rm("account","ClosePrice","CurrentDate","equity","GSPC","i","initDate","initEq","portfolio","Posn","UnitSize","verbose")
-rm("account.longtrend","portfolio.longtrend",pos=.blotter)
-rm("GSPC",pos=.instrument)
+getTxns(Portfolio="longtrend", Symbol="GSPC", Date="2000::2004")
+# Copy the results into the local environment
+print("Retrieving resulting portfolio and account")
+portfolio = getPortfolio("longtrend")
+account = getAccount("longtrend")
+
###############################################################################
# Blotter: Tools for transaction-oriented trading systems development
# for R (see http://r-project.org/)
More information about the Blotter-commits
mailing list