sim.cdir.strategy {matiming} | R Documentation |
This function simulates the returns to the CDIR strategy
sim.cdir.strategy(totret, rfret, dates, capret=NULL, tc=0, shorts = FALSE, winsize=200, FUN=SMA)
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 |
winsize |
a vector or a scalar that determines the size of the window used to compute a moving average |
FUN |
a function that determines the type of a moving average |
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 and the sizes of the windows)
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 winsize
is a vector, then the function simulates a number
of trading strategies for all window sizes such that winsize
>1
Other strategy simulation functions:
sim.mac.strategy()
,
sim.macd.strategy()
,
sim.mae.strategy()
,
sim.mom.strategy()
## 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 winsize <- 2:15 shorts <- FALSE results <- sim.cdir.strategy(totret=totret, rfret=rfret, dates=dates, capret=capret, tc=tc, shorts=shorts, winsize=winsize, FUN=LMA) ## End(Not run)