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 370, Thu Aug 12 13:52:05 2010 UTC revision 450, Sat Nov 13 18:30:40 2010 UTC
# Line 85  Line 85 
85  stratFaber <- strategy("faber")  stratFaber <- strategy("faber")
86    
87  # Add an indicator  # Add an indicator
88  stratFaber <- add.indicator(strategy = s, name = "SMA", arguments = list(x = quote(Cl(mktdata)), n=10), label="SMA10")  stratFaber <- add.indicator(strategy = stratFaber, name = "SMA", arguments = list(x = quote(Cl(mktdata)), n=10), label="SMA10")
89    
90  # There are two signals:  # There are two signals:
91  # The first is when monthly price crosses over the 10-month SMA  # The first is when monthly price crosses over the 10-month SMA
92  stratFaber <- add.signal(s,name="sigCrossover",arguments = list(columns=c("Close","SMA10"),relationship="gt"),label="Cl.gt.SMA")  stratFaber <- add.signal(stratFaber,name="sigCrossover",arguments = list(columns=c("Close","SMA10"),relationship="gt"),label="Cl.gt.SMA")
93  # 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
94  stratFaber <- add.signal(s,name="sigCrossover",arguments = list(columns=c("Close","SMA10"),relationship="lt"),label="Cl.lt.SMA")  stratFaber <- add.signal(stratFaber,name="sigCrossover",arguments = list(columns=c("Close","SMA10"),relationship="lt"),label="Cl.lt.SMA")
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(s, 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'), 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(s, 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'), 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 117  Line 117 
117    
118  # hack for new quantmod graphics, remove later  # hack for new quantmod graphics, remove later
119  themelist<-chart_theme()  themelist<-chart_theme()
120  themelist$up.col<-'lightgreen'  themelist$col$up.col<-'lightgreen'
121  themelist$down.col<-'pink'  themelist$col$dn.col<-'pink'
122  for(symbol in symbols){  for(symbol in symbols){
123      dev.new()      dev.new()
124      chart.Posn(Portfolio='faber',Symbol=symbol,theme=themelist)      chart.Posn(Portfolio='faber',Symbol=symbol,theme=themelist)

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

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