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 1212, Sat Oct 6 17:47:08 2012 UTC revision 1254, Mon Nov 19 21:15:44 2012 UTC
# Line 83  Line 83 
83  print("setup completed")  print("setup completed")
84    
85  # Initialize a strategy object  # Initialize a strategy object
86  stratFaber <- strategy("faber")  strategy("faber", store=TRUE)
87    
88  # Add an indicator  # Add an indicator
89  stratFaber <- add.indicator(strategy = stratFaber, name = "SMA", arguments = list(x = quote(Cl(mktdata)), n=10), label="SMA10")  add.indicator('faber', name = "SMA", arguments = list(x = quote(Cl(mktdata)), n=10), label="SMA10")
90    
91  # There are two signals:  # There are two signals:
92  # The first is when monthly price crosses over the 10-month SMA  # The first is when monthly price crosses over the 10-month SMA
93  stratFaber <- add.signal(stratFaber,name="sigCrossover",arguments = list(columns=c("Close","SMA10"),relationship="gte"),label="Cl.gt.SMA")  add.signal('faber',name="sigCrossover",arguments = list(columns=c("Close","SMA10"),relationship="gte"),label="Cl.gt.SMA")
94  # The second is when the monthly price crosses under the 10-month SMA  # The second is when the monthly price crosses under the 10-month SMA
95  stratFaber <- add.signal(stratFaber,name="sigCrossover",arguments = list(columns=c("Close","SMA10"),relationship="lt"),label="Cl.lt.SMA")  add.signal('faber',name="sigCrossover",arguments = list(columns=c("Close","SMA10"),relationship="lt"),label="Cl.lt.SMA")
96    
97  # There are two rules:  # There are two rules:
98  # The first is to buy when the price crosses above the SMA  # The first is to buy when the price crosses above the SMA
99  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)  add.rule('faber', 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)
100  # The second is to sell when the price crosses below the SMA  # The second is to sell when the price crosses below the SMA
101  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)  add.rule('faber', 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)
102    
103  # Process the indicators and generate trades  # Process the indicators and generate trades
104  start_t<-Sys.time()  start_t<-Sys.time()
105  out<-try(applyStrategy(strategy=stratFaber , portfolios='faber'))  out<-try(applyStrategy(strategy='faber' , portfolios='faber'))
106  end_t<-Sys.time()  end_t<-Sys.time()
107  print("Strategy Loop:")  print("Strategy Loop:")
108  print(end_t-start_t)  print(end_t-start_t)
# Line 112  Line 112 
112    
113  start_t<-Sys.time()  start_t<-Sys.time()
114  updatePortf(Portfolio='faber',Dates=paste('::',as.Date(Sys.time()),sep=''))  updatePortf(Portfolio='faber',Dates=paste('::',as.Date(Sys.time()),sep=''))
115    updateAcct('faber')
116  end_t<-Sys.time()  end_t<-Sys.time()
117  print("trade blotter portfolio update:")  print("trade blotter portfolio update:")
118  print(end_t-start_t)  print(end_t-start_t)
# Line 120  Line 121 
121  themelist<-chart_theme()  themelist<-chart_theme()
122  themelist$col$up.col<-'lightgreen'  themelist$col$up.col<-'lightgreen'
123  themelist$col$dn.col<-'pink'  themelist$col$dn.col<-'pink'
124  for(symbol in symbols){  
125      dev.new()      dev.new()
126      chart.Posn(Portfolio='faber',Symbol=symbol,theme=themelist)  layout(mat=matrix(1:(length(symbols)+1),ncol=2))
127      plot(add_SMA(n=10,col='darkgreen', on=1))  for(symbol in symbols){
128        chart.Posn(Portfolio='faber',Symbol=symbol,theme=themelist,TA="add_SMA(n=10,col='darkgreen')")
129  }  }
130    
131  ret1 <- PortfReturns('faber')  ret1 <- PortfReturns('faber')

Legend:
Removed from v.1212  
changed lines
  Added in v.1254

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