[R-SIG-Finance] rugarchsim / garchsim with a user-defined time series matrix of standardized i.i.d. disturbances
alexios ghalanos
alexios at 4dscape.com
Fri May 25 00:35:57 CEST 2012
1. if you want 30 paths with each path of length 1000 then set
n.sim=1000, m.sim=30.
2. Yes.
# Example:
library(rugarch)
data(sp500ret)
spec=ugarchspec()
z = matrix(rnorm(1000*30), ncol = 30)
Data = sp500ret[,1]
fit = ugarchfit(spec, Data)
sim1<- ugarchsim(fit, n.sim = 1000, m.sim = 30, startMethod = "sample",
custom.dist = list(name = "sample", distfit = z, type = "z"))
sim2<- ugarchsim(fit, n.sim = 1000, m.sim = 30, presigma =
fit at fit$sigma[length(Data)], prereturns = Data[length(Data)],
preresiduals = fit at fit$residuals[length(Data)],
custom.dist = list(name = "sample", distfit = z, type = "z"))
all.equal(sim1 at simulation$seriesSim[1:10,1:10],sim2 at simulation$seriesSim[1:10,1:10])
[1] TRUE
3. name="sample" simply indicates that you are passing a sample matrix.
You could have also passed, as per the documentation, the name of a
distribution function (whose random number function precedes the name
with the letter "r" as is the practice) and an object containing the
parameters of the distribution:
# Example:
obj = list(mu = 0, sd=1)
# assume the distribution is called "f" so that "rf" denotes
# the random number function of "f"
rf = function(n, obj){
rnorm(n, mean = obj$mu, sd = obj$sd)
}
sim3<- ugarchsim(fit, n.sim = 1000, m.sim = 30, presigma =
fit at fit$sigma[length(Data)],
prereturns = Data[length(Data)], preresiduals =
fit at fit$residuals[length(Data)],
custom.dist = list(name = "f", distfit = obj))
sim3 at simulation$seriesSim[1:10,1:10]
At present there seems to be a problem with the function passing the
"rseed" argument to the generator (so that you have reproducible
results). However, if you set the seed before calling the function each
time it will work:
set.seed(2)
sim3<- ugarchsim(fit, n.sim = 1000, m.sim = 30, presigma =
fit at fit$sigma[length(Data)],
prereturns = Data[length(Data)], preresiduals =
fit at fit$residuals[length(Data)],
custom.dist = list(name = "f", distfit = obj))
set.seed(2)
sim4<- ugarchsim(fit, n.sim = 1000, m.sim = 30, presigma =
fit at fit$sigma[length(Data)],
prereturns = Data[length(Data)], preresiduals =
fit at fit$residuals[length(Data)],
custom.dist = list(name = "f", distfit = obj))
all.equal(sim3 at simulation$seriesSim[1:10,1:10],
sim3 at simulation$seriesSim[1:10,1:10])
[1] TRUE
-Alexios
On 24/05/2012 23:01, Alex Fei wrote:
> Thank you.
>
> I have a 30*1000 dim iid standardized time series, saved as Z, and I want to
> simulate 30 paths with 1000 simulations each path. I am a bit confused with
> the below two:
>
> sim1<- ugarchsim(fit.sged, n.sim = 30, m.sim = 1000, *startMethod =
> "sample"*, custom.dist = list(name = "sample", distfit = Z, type = "z"))
>
> sim2<- ugarchsim(fit.sged, n.sim = 30, m.sim = 1000, presigma =
> fit at fit.sigma[length(Data)], prereturns = Data[length(Data)], preresiduals
> = fit at fit.residuals[length(Data)], custom.dist = list(name = "sample",
> distfit = Z, type = "z"))
>
> In help doc, it says that if startMethod = "sample", the starting values for
> the simulation will be the ending values of the actual data from the fit
> object. So, does it means the starting value of sim1 and sim2 are same? What
> is the meaning of name = "sample" in sim2?
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/rugarchsim-garchsim-with-a-user-defined-time-series-matrix-of-standardized-i-i-d-disturbances-tp4631206p4631257.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
More information about the R-SIG-Finance
mailing list