sim.macd.strategy {matiming}R Documentation

Simulates the returns to the Moving Average Convergence Divergence (MACD) strategy

Description

This function simulates the returns to the MACD strategy

Usage

sim.macd.strategy(totret, rfret, dates, capret=NULL, tc=0, shorts = FALSE,
                         fast=12, slow=26, final=9, FUN=EMA)

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

final

a vector or a scalar that determines the size of the window for final smoothing

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, the size of the window for final smoothing)

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, slow or final is a vector, then the function simulates a number of trading strategies for all combinations of fast, slow and final such that fast < slow and final >1.

See Also

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

Examples

## Not run: 
data <- djia.daily # use the daily 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:15 # define the sizes of the fast (shorter) averaging window
slow <- 2:45 # define the sizes of the slow (longer) averaging window
final <- 2:20 # defines the sizes of the window for final smoothing
shorts <- FALSE
results <- sim.macd.strategy(totret=totret, rfret=rfret, dates=dates,
 capret=capret, tc=tc, shorts=shorts, fast=fast, slow=slow,
 final=final, FUN=EMA)

## End(Not run)

[Package matiming version 1.0 Index]