sim.mac.strategy {matiming}R Documentation

Simulates the returns to the Moving Average Crossover (MAC) strategy

Description

This function simulates the returns to the MAC strategy

Usage

sim.mac.strategy(totret, rfret, dates, capret=NULL, tc=0, shorts = FALSE,
                        fast=50, slow=200, FUN=SMA)

Arguments

totret

the vector of total returns

rfret

the vector of risk-free returns

dates

the vector of dates

capret

the vector of capital gain returns

tc

the amount of one-way transaction costs (a scalar)

shorts

a logical value indicating the type of the strategy when a Sell signal is generated. If shorts=FALSE, money is just invested in cash; otherwise, the asset is sold short

fast

a vector or a scalar that determines the size of the shorter averaging window

slow

a vector or a scalar that determines the size of the longer averaging window

FUN

a function that determines the type of a moving average

Value

An object to be used by other functions. This object contains the returns to the simulated strategies and the description of each strategy (the type of a moving average, the sizes of the shorter and the longer windows)

Note

The function FUN is either SMA, LMA, EMA, DMA, HMA or ZMA. The trading signal is computed using the vector of capital gain returns capret. If capret=NULL, then the trading signal is computed using the vector of total returns totret. If one of the arguments fast or slow is a vector, then the function simulates a number of trading strategies for all combinations of fast and slow such that fast < slow

See Also

Other strategy simulation functions: sim.cdir.strategy(), sim.macd.strategy(), sim.mae.strategy(), sim.mom.strategy()

Examples

## Not run: 
data <- djia.monthly # use the monthly data for DJIA index
dates <- index(data)
data <- coredata(data)
capret <- data[,"CAP"]
totret <- data[,"TOT"]
rfret <- data[,"RF"]
tc <- 0.0025 # this defines 0.25% one-way transaction costs
fast <- 1:8  # define the sizes of the fast (shorter) averaging window
slow <- 2:15 # define the sizes of the slow (longer) averaging window
shorts <- FALSE
results <- sim.mac.strategy(totret=totret, rfret=rfret, dates=dates,
                            capret=capret, tc=tc, shorts=shorts, fast=fast, slow=slow, FUN=EMA)

## End(Not run)

[Package matiming version 1.0 Index]