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 450, Sat Nov 13 18:30:40 2010 UTC revision 599, Thu Apr 28 14:57:19 2011 UTC
# Line 76  Line 76 
76    
77  # Initialize portfolio and account  # Initialize portfolio and account
78  initPortf('faber', symbols=symbols, initDate=initDate)  initPortf('faber', symbols=symbols, initDate=initDate)
79  initAcct('faber', portfolios='faber', initDate=initDate)  initAcct('faber', portfolios='faber', initDate=initDate, initEq=100000)
80  initOrders(portfolio='faber', initDate=initDate)  initOrders(portfolio='faber', initDate=initDate)
81    
82  print("setup completed")  print("setup completed")
# Line 95  Line 95 
95    
96  # There are two rules:  # There are two rules:
97  # The first is to buy when the price crosses above the SMA  # The first is to buy when the price crosses above the SMA
98  stratFaber <- add.rule(stratFaber, name='ruleSignal', arguments = list(sigcol="Cl.gt.SMA", sigval=TRUE, orderqty=1000, ordertype='market', orderside='long', pricemethod='market'), type='enter', path.dep=TRUE)  stratFaber <- add.rule(stratFaber, name='ruleSignal', arguments = list(sigcol="Cl.gt.SMA", sigval=TRUE, orderqty=1000, ordertype='market', orderside='long', pricemethod='market',TxnFees=-5), type='enter', path.dep=TRUE)
99  # The second is to sell when the price crosses below the SMA  # The second is to sell when the price crosses below the SMA
100  stratFaber <- add.rule(stratFaber, name='ruleSignal', arguments = list(sigcol="Cl.lt.SMA", sigval=TRUE, orderqty='all', ordertype='market', orderside='long', pricemethod='market'), type='exit', path.dep=TRUE)  stratFaber <- add.rule(stratFaber, name='ruleSignal', arguments = list(sigcol="Cl.lt.SMA", sigval=TRUE, orderqty='all', ordertype='market', orderside='long', pricemethod='market',TxnFees=-5), type='exit', path.dep=TRUE)
101    
102  # Process the indicators and generate trades  # Process the indicators and generate trades
103  start_t<-Sys.time()  start_t<-Sys.time()
# Line 125  Line 125 
125      plot(add_SMA(n=10,col='darkgreen', on=1))      plot(add_SMA(n=10,col='darkgreen', on=1))
126  }  }
127    
128    ret1 <- PortfReturns('faber')
129    ret1$total<-rowSums(ret1)
130    ret1
131    
132    if("package:PerformanceAnalytics" %in% search() || require("PerformanceAnalytics",quietly=TRUE)){
133            getSymbols("SPY", src='yahoo', index.class=c("POSIXt","POSIXct"), from='1999-01-01')
134            SPY<-to.monthly(SPY)
135            SPY.ret<-Return.calculate(SPY$SPY.Close)
136            index(SPY.ret)<-index(ret1)
137            dev.new()
138            charts.PerformanceSummary(cbind(ret1$total,SPY.ret), geometric=FALSE, wealth.index=TRUE)
139    }
140    
141    faber.stats<-tradeStats('faber')[,c('Net.Trading.PL','maxDrawdown','Num.Trades','Profit.Factor','Std.Dev.Trade.PL','Largest.Winner','Largest.Loser','Max.Equity','Min.Equity')]
142    faber.stats
143    
144  ###############################################################################  ###############################################################################
145  # R (http://r-project.org/) Quantitative Strategy Model Framework  # R (http://r-project.org/) Quantitative Strategy Model Framework

Legend:
Removed from v.450  
changed lines
  Added in v.599

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