SCM

SCM Repository

[blotter] Diff of /pkg/quantstrat/demo/faber.R
ViewVC logotype

Diff of /pkg/quantstrat/demo/faber.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1370, Thu Jan 17 20:58:10 2013 UTC revision 1530, Tue Oct 15 18:15:40 2013 UTC
# Line 45  Line 45 
45  # Load required libraries  # Load required libraries
46  require(quantstrat)  require(quantstrat)
47    
48    #correct for TZ issues if they crop up
49    oldtz<-Sys.getenv('TZ')
50    if(oldtz=='') {
51            Sys.setenv(TZ="GMT")
52    }
53  # Try to clean up in case the demo was run previously  # Try to clean up in case the demo was run previously
54  suppressWarnings(rm("account.faber","portfolio.faber",pos=.blotter))  suppressWarnings(rm("account.faber","portfolio.faber",pos=.blotter))
55  suppressWarnings(rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate", "equity",  suppressWarnings(rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate", "equity",
56              "GSPC", "stratFaber", "initDate", "initEq", "Posn", "UnitSize", "verbose"))              "GSPC", "stratFaber", "initDate", "initEq", "Posn", "UnitSize", "verbose"))
57  suppressWarnings(rm("order_book.faber",pos=.strategy))  suppressWarnings(rm("order_book.faber",pos=.strategy))
58    
59  ##### PLACE THIS BLOCK AHEAD OF DATE INITS IN DEMO SCRIPT ######  ##### PLACE DEMO AND TEST DATES HERE #################
60  # if(!exists('in_test') || !isTRUE(in_test)){  #
61  #     initDate='2005-12-31' # ensure this is demo default  #if(isTRUE(options('in_test')$in_test))
62  #     endDate=Sys.Date()    # ensure this is demo default  #  # use test dates
63  # }  #  {initDate="2011-01-01"
64  ################################################################  #  endDate="2012-12-31"
65    #  } else
66    #  # use demo defaults
67    #  {initDate="1999-12-31"
68    #  endDate=Sys.Date()}
69    
70  # Set initial values  # Set initial values
71  initDate='1997-12-31'  initDate='1997-12-31'
# Line 120  Line 129 
129  start_t<-Sys.time()  start_t<-Sys.time()
130  updatePortf(Portfolio='faber',Dates=paste('::',as.Date(Sys.time()),sep=''))  updatePortf(Portfolio='faber',Dates=paste('::',as.Date(Sys.time()),sep=''))
131  updateAcct('faber')  updateAcct('faber')
132    updateEndEq('faber')
133  end_t<-Sys.time()  end_t<-Sys.time()
134  print("trade blotter portfolio update:")  print("trade blotter portfolio update:")
135  print(end_t-start_t)  print(end_t-start_t)
# Line 137  Line 147 
147    
148  ret1 <- PortfReturns('faber')  ret1 <- PortfReturns('faber')
149  ret1$total<-rowSums(ret1)  ret1$total<-rowSums(ret1)
150  ret1  View(ret1)
151    
152  if("package:PerformanceAnalytics" %in% search() || require("PerformanceAnalytics",quietly=TRUE)){  if("package:PerformanceAnalytics" %in% search() || require("PerformanceAnalytics",quietly=TRUE)){
153          getSymbols("SPY", src='yahoo', index.class=c("POSIXt","POSIXct"), from='1999-01-01')          getSymbols("SPY", src='yahoo', index.class=c("POSIXt","POSIXct"), from='1999-01-01')
# Line 149  Line 159 
159  }  }
160    
161  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<-tradeStats('faber')[,c('Net.Trading.PL','Max.Drawdown','Num.Trades','Profit.Factor','Std.Dev.Trade.PL','Largest.Winner','Largest.Loser','Max.Equity','Min.Equity')]
162  faber.stats  View(faber.stats)
163    
164    Sys.setenv(TZ=oldtz)
165  ###############################################################################  ###############################################################################
166  # R (http://r-project.org/) Quantitative Strategy Model Framework  # R (http://r-project.org/) Quantitative Strategy Model Framework
167  #  #

Legend:
Removed from v.1370  
changed lines
  Added in v.1530

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge