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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 29 16:58:59 CET 2013


Author: braverock
Date: 2013-03-29 16:58:58 +0100 (Fri, 29 Mar 2013)
New Revision: 1418

Modified:
   pkg/quantstrat/demo/faber.R
Log:
- correct for missing TZ to agree w/ newer xts req.

Modified: pkg/quantstrat/demo/faber.R
===================================================================
--- pkg/quantstrat/demo/faber.R	2013-03-29 15:49:43 UTC (rev 1417)
+++ pkg/quantstrat/demo/faber.R	2013-03-29 15:58:58 UTC (rev 1418)
@@ -45,6 +45,11 @@
 # Load required libraries
 require(quantstrat)
 
+#correct for TZ issues if they crop up
+oldtz<-Sys.getenv('TZ')
+if(oldtz=='') {
+	Sys.setenv(TZ="GMT")
+}
 # 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", 
@@ -140,13 +145,14 @@
 }
 
 ret1 <- PortfReturns('faber')
+ret1$total<-rowSums(ret1)
 View(ret1)
 
 if("package:PerformanceAnalytics" %in% search() || require("PerformanceAnalytics",quietly=TRUE)){
 	getSymbols("SPY", src='yahoo', index.class=c("POSIXt","POSIXct"), from='1999-01-01')
 	SPY<-to.monthly(SPY)
 	SPY.ret<-Return.calculate(SPY$SPY.Close)
-	index(SPY.ret)<-c(as.Date('1999-01-01'),index(ret1))
+	index(SPY.ret)<-index(ret1)
 	dev.new()
 	charts.PerformanceSummary(cbind(ret1$total,SPY.ret), geometric=FALSE, wealth.index=TRUE)
 }
@@ -154,6 +160,7 @@
 faber.stats<-tradeStats('faber')[,c('Net.Trading.PL','Max.Drawdown','Num.Trades','Profit.Factor','Std.Dev.Trade.PL','Largest.Winner','Largest.Loser','Max.Equity','Min.Equity')]
 faber.stats
 
+Sys.setenv(TZ=oldtz)
 ###############################################################################
 # R (http://r-project.org/) Quantitative Strategy Model Framework
 #



More information about the Blotter-commits mailing list