rm(list=ls())
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
load.packages('quantmod')
## Warning: package 'quantmod' was built under R version 3.5.3
## Warning: package 'xts' was built under R version 3.5.3
## Warning: package 'zoo' was built under R version 3.5.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Warning: package 'TTR' was built under R version 3.5.3
## 
## Attaching package: 'TTR'
## The following object is masked _by_ '.GlobalEnv':
## 
##     DVI
## Version 0.4-0 included new data defaults. See ?getSymbols.
bt.simple <- function(data, signal)
{
  # lag serial
  signal <- lag(signal,1)
  # back fill
  signal <- na.locf(signal, na.rm = FALSE)
  signal[is.na(signal)] = 0
  # calculate close-to-close returns
  # ROC() : Calculate the (rate of) change of a series over n periods.
  ret <- ROC(Cl(data), type="discrete")
  ret[1] = 0
  # compute stats
  bt <- list()
  bt$ret <- ret * signal 
  bt$equity <- cumprod(1 + bt$ret)
  return(bt)}
data <- getSymbols('SPY', src = 'yahoo', from = '2000-01-01', to = '2018-12-31', auto.assign = F)
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
## 
## This message is shown once per session and may be disabled by setting 
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
signal <- rep(1, nrow(data))
buy.hold <- bt.simple(data, signal)
buy.hold$equity<-as.xts(buy.hold$equity)
head(buy.hold$equity)
##            SPY.Close
## 2000-01-03 1.0000000
## 2000-01-04 0.9608939
## 2000-01-05 0.9626128
## 2000-01-06 0.9471422
## 2000-01-07 1.0021487
## 2000-01-10 1.0055866
tail(buy.hold$equity)
##            SPY.Close
## 2018-12-20  1.699493
## 2018-12-21  1.655006
## 2018-12-24  1.611276
## 2018-12-26  1.692686
## 2018-12-27  1.705681
## 2018-12-28  1.703481
buy.hold$ret<-as.xts(buy.hold$ret)
head(buy.hold$ret)
##               SPY.Close
## 2000-01-03  0.000000000
## 2000-01-04 -0.039106145
## 2000-01-05  0.001788909
## 2000-01-06 -0.016071429
## 2000-01-07  0.058076225
## 2000-01-10  0.003430532
sma <- SMA(Cl(data), 200)
head(sma, 201)
##                 SMA
## 2000-01-03       NA
## 2000-01-04       NA
## 2000-01-05       NA
## 2000-01-06       NA
## 2000-01-07       NA
## 2000-01-10       NA
## 2000-01-11       NA
## 2000-01-12       NA
## 2000-01-13       NA
## 2000-01-14       NA
## 2000-01-18       NA
## 2000-01-19       NA
## 2000-01-20       NA
## 2000-01-21       NA
## 2000-01-24       NA
## 2000-01-25       NA
## 2000-01-26       NA
## 2000-01-27       NA
## 2000-01-28       NA
## 2000-01-31       NA
## 2000-02-01       NA
## 2000-02-02       NA
## 2000-02-03       NA
## 2000-02-04       NA
## 2000-02-07       NA
## 2000-02-08       NA
## 2000-02-09       NA
## 2000-02-10       NA
## 2000-02-11       NA
## 2000-02-14       NA
## 2000-02-15       NA
## 2000-02-16       NA
## 2000-02-17       NA
## 2000-02-18       NA
## 2000-02-22       NA
## 2000-02-23       NA
## 2000-02-24       NA
## 2000-02-25       NA
## 2000-02-28       NA
## 2000-02-29       NA
## 2000-03-01       NA
## 2000-03-02       NA
## 2000-03-03       NA
## 2000-03-06       NA
## 2000-03-07       NA
## 2000-03-08       NA
## 2000-03-09       NA
## 2000-03-10       NA
## 2000-03-13       NA
## 2000-03-14       NA
## 2000-03-15       NA
## 2000-03-16       NA
## 2000-03-17       NA
## 2000-03-20       NA
## 2000-03-21       NA
## 2000-03-22       NA
## 2000-03-23       NA
## 2000-03-24       NA
## 2000-03-27       NA
## 2000-03-28       NA
## 2000-03-29       NA
## 2000-03-30       NA
## 2000-03-31       NA
## 2000-04-03       NA
## 2000-04-04       NA
## 2000-04-05       NA
## 2000-04-06       NA
## 2000-04-07       NA
## 2000-04-10       NA
## 2000-04-11       NA
## 2000-04-12       NA
## 2000-04-13       NA
## 2000-04-14       NA
## 2000-04-17       NA
## 2000-04-18       NA
## 2000-04-19       NA
## 2000-04-20       NA
## 2000-04-24       NA
## 2000-04-25       NA
## 2000-04-26       NA
## 2000-04-27       NA
## 2000-04-28       NA
## 2000-05-01       NA
## 2000-05-02       NA
## 2000-05-03       NA
## 2000-05-04       NA
## 2000-05-05       NA
## 2000-05-08       NA
## 2000-05-09       NA
## 2000-05-10       NA
## 2000-05-11       NA
## 2000-05-12       NA
## 2000-05-15       NA
## 2000-05-16       NA
## 2000-05-17       NA
## 2000-05-18       NA
## 2000-05-19       NA
## 2000-05-22       NA
## 2000-05-23       NA
## 2000-05-24       NA
## 2000-05-25       NA
## 2000-05-26       NA
## 2000-05-30       NA
## 2000-05-31       NA
## 2000-06-01       NA
## 2000-06-02       NA
## 2000-06-05       NA
## 2000-06-06       NA
## 2000-06-07       NA
## 2000-06-08       NA
## 2000-06-09       NA
## 2000-06-12       NA
## 2000-06-13       NA
## 2000-06-14       NA
## 2000-06-15       NA
## 2000-06-16       NA
## 2000-06-19       NA
## 2000-06-20       NA
## 2000-06-21       NA
## 2000-06-22       NA
## 2000-06-23       NA
## 2000-06-26       NA
## 2000-06-27       NA
## 2000-06-28       NA
## 2000-06-29       NA
## 2000-06-30       NA
## 2000-07-03       NA
## 2000-07-05       NA
## 2000-07-06       NA
## 2000-07-07       NA
## 2000-07-10       NA
## 2000-07-11       NA
## 2000-07-12       NA
## 2000-07-13       NA
## 2000-07-14       NA
## 2000-07-17       NA
## 2000-07-18       NA
## 2000-07-19       NA
## 2000-07-20       NA
## 2000-07-21       NA
## 2000-07-24       NA
## 2000-07-25       NA
## 2000-07-26       NA
## 2000-07-27       NA
## 2000-07-28       NA
## 2000-07-31       NA
## 2000-08-01       NA
## 2000-08-02       NA
## 2000-08-03       NA
## 2000-08-04       NA
## 2000-08-07       NA
## 2000-08-08       NA
## 2000-08-09       NA
## 2000-08-10       NA
## 2000-08-11       NA
## 2000-08-14       NA
## 2000-08-15       NA
## 2000-08-16       NA
## 2000-08-17       NA
## 2000-08-18       NA
## 2000-08-21       NA
## 2000-08-22       NA
## 2000-08-23       NA
## 2000-08-24       NA
## 2000-08-25       NA
## 2000-08-28       NA
## 2000-08-29       NA
## 2000-08-30       NA
## 2000-08-31       NA
## 2000-09-01       NA
## 2000-09-05       NA
## 2000-09-06       NA
## 2000-09-07       NA
## 2000-09-08       NA
## 2000-09-11       NA
## 2000-09-12       NA
## 2000-09-13       NA
## 2000-09-14       NA
## 2000-09-15       NA
## 2000-09-18       NA
## 2000-09-19       NA
## 2000-09-20       NA
## 2000-09-21       NA
## 2000-09-22       NA
## 2000-09-25       NA
## 2000-09-26       NA
## 2000-09-27       NA
## 2000-09-28       NA
## 2000-09-29       NA
## 2000-10-02       NA
## 2000-10-03       NA
## 2000-10-04       NA
## 2000-10-05       NA
## 2000-10-06       NA
## 2000-10-09       NA
## 2000-10-10       NA
## 2000-10-11       NA
## 2000-10-12       NA
## 2000-10-13       NA
## 2000-10-16 144.7205
## 2000-10-17 144.6670
signal <- ifelse(Cl(data) > sma, 1, 0) # if price large than moving mean, buy
head(signal, 201)
##            SPY.Close
## 2000-01-03        NA
## 2000-01-04        NA
## 2000-01-05        NA
## 2000-01-06        NA
## 2000-01-07        NA
## 2000-01-10        NA
## 2000-01-11        NA
## 2000-01-12        NA
## 2000-01-13        NA
## 2000-01-14        NA
## 2000-01-18        NA
## 2000-01-19        NA
## 2000-01-20        NA
## 2000-01-21        NA
## 2000-01-24        NA
## 2000-01-25        NA
## 2000-01-26        NA
## 2000-01-27        NA
## 2000-01-28        NA
## 2000-01-31        NA
## 2000-02-01        NA
## 2000-02-02        NA
## 2000-02-03        NA
## 2000-02-04        NA
## 2000-02-07        NA
## 2000-02-08        NA
## 2000-02-09        NA
## 2000-02-10        NA
## 2000-02-11        NA
## 2000-02-14        NA
## 2000-02-15        NA
## 2000-02-16        NA
## 2000-02-17        NA
## 2000-02-18        NA
## 2000-02-22        NA
## 2000-02-23        NA
## 2000-02-24        NA
## 2000-02-25        NA
## 2000-02-28        NA
## 2000-02-29        NA
## 2000-03-01        NA
## 2000-03-02        NA
## 2000-03-03        NA
## 2000-03-06        NA
## 2000-03-07        NA
## 2000-03-08        NA
## 2000-03-09        NA
## 2000-03-10        NA
## 2000-03-13        NA
## 2000-03-14        NA
## 2000-03-15        NA
## 2000-03-16        NA
## 2000-03-17        NA
## 2000-03-20        NA
## 2000-03-21        NA
## 2000-03-22        NA
## 2000-03-23        NA
## 2000-03-24        NA
## 2000-03-27        NA
## 2000-03-28        NA
## 2000-03-29        NA
## 2000-03-30        NA
## 2000-03-31        NA
## 2000-04-03        NA
## 2000-04-04        NA
## 2000-04-05        NA
## 2000-04-06        NA
## 2000-04-07        NA
## 2000-04-10        NA
## 2000-04-11        NA
## 2000-04-12        NA
## 2000-04-13        NA
## 2000-04-14        NA
## 2000-04-17        NA
## 2000-04-18        NA
## 2000-04-19        NA
## 2000-04-20        NA
## 2000-04-24        NA
## 2000-04-25        NA
## 2000-04-26        NA
## 2000-04-27        NA
## 2000-04-28        NA
## 2000-05-01        NA
## 2000-05-02        NA
## 2000-05-03        NA
## 2000-05-04        NA
## 2000-05-05        NA
## 2000-05-08        NA
## 2000-05-09        NA
## 2000-05-10        NA
## 2000-05-11        NA
## 2000-05-12        NA
## 2000-05-15        NA
## 2000-05-16        NA
## 2000-05-17        NA
## 2000-05-18        NA
## 2000-05-19        NA
## 2000-05-22        NA
## 2000-05-23        NA
## 2000-05-24        NA
## 2000-05-25        NA
## 2000-05-26        NA
## 2000-05-30        NA
## 2000-05-31        NA
## 2000-06-01        NA
## 2000-06-02        NA
## 2000-06-05        NA
## 2000-06-06        NA
## 2000-06-07        NA
## 2000-06-08        NA
## 2000-06-09        NA
## 2000-06-12        NA
## 2000-06-13        NA
## 2000-06-14        NA
## 2000-06-15        NA
## 2000-06-16        NA
## 2000-06-19        NA
## 2000-06-20        NA
## 2000-06-21        NA
## 2000-06-22        NA
## 2000-06-23        NA
## 2000-06-26        NA
## 2000-06-27        NA
## 2000-06-28        NA
## 2000-06-29        NA
## 2000-06-30        NA
## 2000-07-03        NA
## 2000-07-05        NA
## 2000-07-06        NA
## 2000-07-07        NA
## 2000-07-10        NA
## 2000-07-11        NA
## 2000-07-12        NA
## 2000-07-13        NA
## 2000-07-14        NA
## 2000-07-17        NA
## 2000-07-18        NA
## 2000-07-19        NA
## 2000-07-20        NA
## 2000-07-21        NA
## 2000-07-24        NA
## 2000-07-25        NA
## 2000-07-26        NA
## 2000-07-27        NA
## 2000-07-28        NA
## 2000-07-31        NA
## 2000-08-01        NA
## 2000-08-02        NA
## 2000-08-03        NA
## 2000-08-04        NA
## 2000-08-07        NA
## 2000-08-08        NA
## 2000-08-09        NA
## 2000-08-10        NA
## 2000-08-11        NA
## 2000-08-14        NA
## 2000-08-15        NA
## 2000-08-16        NA
## 2000-08-17        NA
## 2000-08-18        NA
## 2000-08-21        NA
## 2000-08-22        NA
## 2000-08-23        NA
## 2000-08-24        NA
## 2000-08-25        NA
## 2000-08-28        NA
## 2000-08-29        NA
## 2000-08-30        NA
## 2000-08-31        NA
## 2000-09-01        NA
## 2000-09-05        NA
## 2000-09-06        NA
## 2000-09-07        NA
## 2000-09-08        NA
## 2000-09-11        NA
## 2000-09-12        NA
## 2000-09-13        NA
## 2000-09-14        NA
## 2000-09-15        NA
## 2000-09-18        NA
## 2000-09-19        NA
## 2000-09-20        NA
## 2000-09-21        NA
## 2000-09-22        NA
## 2000-09-25        NA
## 2000-09-26        NA
## 2000-09-27        NA
## 2000-09-28        NA
## 2000-09-29        NA
## 2000-10-02        NA
## 2000-10-03        NA
## 2000-10-04        NA
## 2000-10-05        NA
## 2000-10-06        NA
## 2000-10-09        NA
## 2000-10-10        NA
## 2000-10-11        NA
## 2000-10-12        NA
## 2000-10-13        NA
## 2000-10-16         0
## 2000-10-17         0
sma.cross <- bt.simple(data, signal)
names(sma.cross)
## [1] "ret"    "equity"
tail(sma.cross$equity)
##            SPY.Close
## 2018-12-20   2.09504
## 2018-12-21   2.09504
## 2018-12-24   2.09504
## 2018-12-26   2.09504
## 2018-12-27   2.09504
## 2018-12-28   2.09504
dates <- '2000::2018'
buy.hold.equity <- buy.hold$equity[dates] / as.double(buy.hold$equity[dates][1])
sma.cross.equity <- sma.cross$equity[dates] / as.double(sma.cross$equity[dates][1])
chartSeries(buy.hold.equity, TA = c(addTA(sma.cross.equity, on=1, col='red')), 
            theme ='white', yrange = range(buy.hold.equity, sma.cross.equity) )

library(magrittr)
## Warning: package 'magrittr' was built under R version 3.5.3
strategy.sma<-merge(buy.hold.equity, sma.cross.equity) %>% 
  set_colnames(c("BH", "SMA"))
head(strategy.sma,30)
##                   BH SMA
## 2000-01-03 1.0000000   1
## 2000-01-04 0.9608939   1
## 2000-01-05 0.9626128   1
## 2000-01-06 0.9471422   1
## 2000-01-07 1.0021487   1
## 2000-01-10 1.0055866   1
## 2000-01-11 0.9935539   1
## 2000-01-12 0.9836700   1
## 2000-01-13 0.9969918   1
## 2000-01-14 1.0105283   1
## 2000-01-18 1.0025784   1
## 2000-01-19 1.0107434   1
## 2000-01-20 0.9952729   1
## 2000-01-21 0.9931242   1
## 2000-01-24 0.9649760   1
## 2000-01-25 0.9759347   1
## 2000-01-26 0.9681994   1
## 2000-01-27 0.9643318   1
## 2000-01-28 0.9342501   1
## 2000-01-31 0.9596046   1
## 2000-02-01 0.9690589   1
## 2000-02-02 0.9699183   1
## 2000-02-03 0.9845294   1
## 2000-02-04 0.9804466   1
## 2000-02-07 0.9789428   1
## 2000-02-08 0.9922647   1
## 2000-02-09 0.9714221   1
## 2000-02-10 0.9733563   1
## 2000-02-11 0.9535883   1
## 2000-02-14 0.9591749   1
tail(strategy.sma)
##                  BH     SMA
## 2018-12-20 1.699493 2.09504
## 2018-12-21 1.655006 2.09504
## 2018-12-24 1.611276 2.09504
## 2018-12-26 1.692686 2.09504
## 2018-12-27 1.705681 2.09504
## 2018-12-28 1.703481 2.09504
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.3
strategy.sma.df<-fortify(strategy.sma, melt=TRUE)
head(strategy.sma.df)
##        Index Series     Value
## 1 2000-01-03     BH 1.0000000
## 2 2000-01-04     BH 0.9608939
## 3 2000-01-05     BH 0.9626128
## 4 2000-01-06     BH 0.9471422
## 5 2000-01-07     BH 1.0021487
## 6 2000-01-10     BH 1.0055866
p<-ggplot(strategy.sma.df, aes(x = Index, y = Value))+
  geom_line(aes(color = Series), size = 0.5) +
  scale_x_date(date_labels = "%Y/%m")  # +
  #geom_hline(yintercept = c(1.0, 0.6)) # +  
  #geom_text(aes( 0, 0.6, label = 0.6, vjust = -1))

p

load.packages('quantmod')
tickers <- spl('SPY')

data1 <- new.env() # data is a environment
getSymbols(tickers, src = 'yahoo', from = '2000-01-01', to = '2018-12-31', env = data1, auto.assign = T)
## [1] "SPY"
bt.prep(data1, align='keep.all')
names(data1)
## [1] "prices"          "dates"           "weight"          ".getSymbols"    
## [5] "symbolnames"     "execution.price" "SPY"
head(data1$prices)
##                 SPY
## 2000-01-03 145.4375
## 2000-01-04 139.7500
## 2000-01-05 140.0000
## 2000-01-06 137.7500
## 2000-01-07 145.7500
## 2000-01-10 146.2500
tail(data1$prices)
##               SPY
## 2018-12-20 247.17
## 2018-12-21 240.70
## 2018-12-24 234.34
## 2018-12-26 246.18
## 2018-12-27 248.07
## 2018-12-28 247.75
data1$weight[] <- 1
buy.hold <- bt.run.share(data1, clean.signal=F, trade.summary = TRUE)
## Latest weights :
##            SPY
## 2018-12-28 100
## 
## Performance summary :
##  CAGR    Best    Worst   
##  2.8 14.5    -9.8    
buy.hold <- bt.run(data1)
## Latest weights :
##            SPY
## 2018-12-28 100
## 
## Performance summary :
##  CAGR    Best    Worst   
##  2.8 14.5    -9.8    
prices<-data1$prices
sma.1 <- bt.apply(data1, function(x) { SMA(Cl(x), 200) } ) 
head(sma.1, 201)
##                 SPY
## 2000-01-03       NA
## 2000-01-04       NA
## 2000-01-05       NA
## 2000-01-06       NA
## 2000-01-07       NA
## 2000-01-10       NA
## 2000-01-11       NA
## 2000-01-12       NA
## 2000-01-13       NA
## 2000-01-14       NA
## 2000-01-18       NA
## 2000-01-19       NA
## 2000-01-20       NA
## 2000-01-21       NA
## 2000-01-24       NA
## 2000-01-25       NA
## 2000-01-26       NA
## 2000-01-27       NA
## 2000-01-28       NA
## 2000-01-31       NA
## 2000-02-01       NA
## 2000-02-02       NA
## 2000-02-03       NA
## 2000-02-04       NA
## 2000-02-07       NA
## 2000-02-08       NA
## 2000-02-09       NA
## 2000-02-10       NA
## 2000-02-11       NA
## 2000-02-14       NA
## 2000-02-15       NA
## 2000-02-16       NA
## 2000-02-17       NA
## 2000-02-18       NA
## 2000-02-22       NA
## 2000-02-23       NA
## 2000-02-24       NA
## 2000-02-25       NA
## 2000-02-28       NA
## 2000-02-29       NA
## 2000-03-01       NA
## 2000-03-02       NA
## 2000-03-03       NA
## 2000-03-06       NA
## 2000-03-07       NA
## 2000-03-08       NA
## 2000-03-09       NA
## 2000-03-10       NA
## 2000-03-13       NA
## 2000-03-14       NA
## 2000-03-15       NA
## 2000-03-16       NA
## 2000-03-17       NA
## 2000-03-20       NA
## 2000-03-21       NA
## 2000-03-22       NA
## 2000-03-23       NA
## 2000-03-24       NA
## 2000-03-27       NA
## 2000-03-28       NA
## 2000-03-29       NA
## 2000-03-30       NA
## 2000-03-31       NA
## 2000-04-03       NA
## 2000-04-04       NA
## 2000-04-05       NA
## 2000-04-06       NA
## 2000-04-07       NA
## 2000-04-10       NA
## 2000-04-11       NA
## 2000-04-12       NA
## 2000-04-13       NA
## 2000-04-14       NA
## 2000-04-17       NA
## 2000-04-18       NA
## 2000-04-19       NA
## 2000-04-20       NA
## 2000-04-24       NA
## 2000-04-25       NA
## 2000-04-26       NA
## 2000-04-27       NA
## 2000-04-28       NA
## 2000-05-01       NA
## 2000-05-02       NA
## 2000-05-03       NA
## 2000-05-04       NA
## 2000-05-05       NA
## 2000-05-08       NA
## 2000-05-09       NA
## 2000-05-10       NA
## 2000-05-11       NA
## 2000-05-12       NA
## 2000-05-15       NA
## 2000-05-16       NA
## 2000-05-17       NA
## 2000-05-18       NA
## 2000-05-19       NA
## 2000-05-22       NA
## 2000-05-23       NA
## 2000-05-24       NA
## 2000-05-25       NA
## 2000-05-26       NA
## 2000-05-30       NA
## 2000-05-31       NA
## 2000-06-01       NA
## 2000-06-02       NA
## 2000-06-05       NA
## 2000-06-06       NA
## 2000-06-07       NA
## 2000-06-08       NA
## 2000-06-09       NA
## 2000-06-12       NA
## 2000-06-13       NA
## 2000-06-14       NA
## 2000-06-15       NA
## 2000-06-16       NA
## 2000-06-19       NA
## 2000-06-20       NA
## 2000-06-21       NA
## 2000-06-22       NA
## 2000-06-23       NA
## 2000-06-26       NA
## 2000-06-27       NA
## 2000-06-28       NA
## 2000-06-29       NA
## 2000-06-30       NA
## 2000-07-03       NA
## 2000-07-05       NA
## 2000-07-06       NA
## 2000-07-07       NA
## 2000-07-10       NA
## 2000-07-11       NA
## 2000-07-12       NA
## 2000-07-13       NA
## 2000-07-14       NA
## 2000-07-17       NA
## 2000-07-18       NA
## 2000-07-19       NA
## 2000-07-20       NA
## 2000-07-21       NA
## 2000-07-24       NA
## 2000-07-25       NA
## 2000-07-26       NA
## 2000-07-27       NA
## 2000-07-28       NA
## 2000-07-31       NA
## 2000-08-01       NA
## 2000-08-02       NA
## 2000-08-03       NA
## 2000-08-04       NA
## 2000-08-07       NA
## 2000-08-08       NA
## 2000-08-09       NA
## 2000-08-10       NA
## 2000-08-11       NA
## 2000-08-14       NA
## 2000-08-15       NA
## 2000-08-16       NA
## 2000-08-17       NA
## 2000-08-18       NA
## 2000-08-21       NA
## 2000-08-22       NA
## 2000-08-23       NA
## 2000-08-24       NA
## 2000-08-25       NA
## 2000-08-28       NA
## 2000-08-29       NA
## 2000-08-30       NA
## 2000-08-31       NA
## 2000-09-01       NA
## 2000-09-05       NA
## 2000-09-06       NA
## 2000-09-07       NA
## 2000-09-08       NA
## 2000-09-11       NA
## 2000-09-12       NA
## 2000-09-13       NA
## 2000-09-14       NA
## 2000-09-15       NA
## 2000-09-18       NA
## 2000-09-19       NA
## 2000-09-20       NA
## 2000-09-21       NA
## 2000-09-22       NA
## 2000-09-25       NA
## 2000-09-26       NA
## 2000-09-27       NA
## 2000-09-28       NA
## 2000-09-29       NA
## 2000-10-02       NA
## 2000-10-03       NA
## 2000-10-04       NA
## 2000-10-05       NA
## 2000-10-06       NA
## 2000-10-09       NA
## 2000-10-10       NA
## 2000-10-11       NA
## 2000-10-12       NA
## 2000-10-13       NA
## 2000-10-16 144.7205
## 2000-10-17 144.6670
data1$weight[] <- NA # update weights matirx
data1$weight[] <- iif(prices >= sma.1, 1, 0)
sma.1.cross <- bt.run(data1, trade.summary=T)
## Latest weights :
##            SPY
## 2018-12-28   0
## 
## Performance summary :
##  CAGR    Best    Worst   
##  4   4.4 -4.2    
plotbt.custom.report(sma.1.cross, buy.hold)

models<-list("SMA"= sma.1.cross, "BH" = buy.hold)
strategy.performance.snapshoot(sma.1.cross, T) 

## NULL
strategy.performance.snapshoot(buy.hold, T) 

## NULL
strategy.performance.snapshoot(models, T)