back.test {matiming}R Documentation

Finds the optimal trading strategies in a back-test (in-sample test)

Description

This function finds the optimal trading strategies in a back-test

Usage

back.test(results, start.date, end.date, n.first=7, include.bh=FALSE, FUN=Sharpe)

Arguments

results

the results of simulation of a trading strategy or multiple trading strategies. Specifically, this is the result returned by function sim.mom.strategy, sim.mac.strategy, sim.cdir.strategy, sim.macd.strategy, or sim.results.merge

start.date

the start of the in-sample period

end.date

the end of the in-sample period

n.first

the (maximum) number of the best performing strategies in the returned object

include.bh

a logical value indicating whether to consider the Buy-and-Hold (bh) strategy in addition to the moving average strategies

FUN

the function that computes the performance of a trading strategy.

Value

An object to be used by other functions

Note

The argument results contains the dates vector that defines the historical period over which the trading strategies are simulated. The function FUN is either Excret, Sharpe, or Sortino.

See Also

Other strategy testing functions: forward.test(), outperformance.test()

Examples

## Not run: 
library(matiming)
library(xtable)
library(zoo)
# access the data
data <- sp500.monthly
dates <- index(data)
data <- coredata(data)
capret <- data[,"CAP"]
totret <- data[,"TOT"]
rfret <- data[,"RF"]
# simulate the trading strategies
tc <- 0.0025
fast <- 1:5
slow <- 2:15
shorts <- F
results <- sim.mac.strategy(totret=totret, rfret=rfret, dates=dates,
                         capret=capret, tc=tc, shorts=shorts, fast=fast, slow=slow, FUN=SMA)
# define the historical period
start.date <- as.Date("1950-01-01", format="%Y-%m-%d")
end.date <- as.Date("2015-12-31", format="%Y-%m-%d")
n.first <- 5
include.bh <- TRUE
res <- back.test(results, start.date=start.date, end.date=end.date,
                       n.first=n.first, include.bh=include.bh, FUN=Sortino)
# print out the ranking of trading strategies
df <- best.is.strategies(res, to.annual=sqrt(12), plot.results=TRUE)
xtab <- xtable(df, digits=3)
print(xtab, include.rownames=FALSE)

## End(Not run)

[Package matiming version 1.0 Index]