#########################################################################
## Monte-Carlo test for randomness On PC with Single CPU ##
#########################################################################
data("DEXCAUS")
returns <- log(DEXCAUS[-1]/DEXCAUS[-length(DEXCAUS)])
portest(returns)
#########################################################################
## Monte-Carlo test for usual residuals using "snow" ##
#########################################################################
ans <- arima(Nile, order=c(1,0,1))
portest(ans, nslaves = 8)
##
IBMSP500 <- monthibmspln
Fit3 <- ar.ols(IBMSP500, aic=TRUE,intercept=F, order.max=3)
portest(Fit3,test="gvtest",nslaves=8)
portest(Fit3,test="Hosking",nslaves=8)
## Use VAR function in the R package "vars"
##
library(vars)
Fit3 <- VAR(IBMSP500,p=3)
portest(Fit3,test="gvtest",nslaves=8)
#########################################################################
## Monte-Carlo test for squared residuals: ARCH effects using "snow" ##
#########################################################################
data("monthintel")
returns <- as.ts(monthintel)
lags <- c(5, 10, 40)
portest(returns, lags = lags, nslaves = 8, SquaredQ = TRUE)
#########################################################################
## Monte-Carlo test on residuals with infinite variances using "snow" ##
#########################################################################
data("CRSP")
CRSP.AR5<- arima(CRSP, c(5, 0, 0))
NREP<- 1000
lags=c(10, 20, 30)
portest(CRSP.AR5,lags=lags,nslaves=8,NREP=NREP,InfiniteVarianceQ=TRUE)
#########################################################################
## Monte-Carlo test for FGN using "snow" ##
#########################################################################
library("FGN")
data("NileMin")
NILE.FGN <- FitFGN(NileMin)
lags <- c(5, 10, 20)
portest(NILE.FGN, lags = lags, nslaves = 8)
#########################################################################
## Simulate a VARMA process with innovations that have finite variance ##
#########################################################################
## Example 1
## Data from VARMA (1,1) with mean zero vector without drift or trend.
#
n <- 300
phi <- array(c(0.5, 0.4, 0.1, 0.5),dim = c(2, 2, 1))
theta <- array(c(0, 0.25, 0, 0),dim = c(2, 2, 1))
d <- NA
sigma <- matrix(c(1, 0.71, 0.71, 2), 2, 2)
Z <- varima.sim(phi, theta, d, sigma, n)
plot(Z)
#
## Example 2
## Mean = c(10,20), drift equation a + b * t, a = c(2,3), and b = c(0,0.06).
#
n <- 300
phi <- array(c(0.5, 0.4, 0.1, 0.5),dim = c(2, 2, 1))
theta <- array(c(0, 0.25, 0, 0),dim = c(2, 2, 1))
d <- c(0,0)
sigma <- matrix(c(1, 0.71, 0.71, 2), 2, 2)
constant <- c(2,3)
trend <- c(0,0.06)
demean <- c(10,20)
Z <- varima.sim(phi, theta, d, sigma, n, constant, trend, demean)
plot(Z)
#########################################################################
## Simulate from VARIMA process with innovations of infinite variance ##
#########################################################################
n <- 500
phi <- array(c(0.5, 0.4, 0.1, 0.5),dim = c(2, 2, 1))
theta <- array(c(0, 0.25, 0, 0),dim = c(2, 2, 1))
d <- c(1,0)
sigma <- matrix(c(1, 0.71, 0.71, 2), 2, 2)
ALPHA <- c(1.3, 1.6)
BETA <- c(0, 0.2)
GAMMA <- c(1, 1)
DELTA <- c(0, 0.2)
StableParameters <- c(ALPHA, BETA, GAMMA, DELTA)
varima.sim(phi, theta, d, sigma, n, StableParameters = StableParameters)
Run the code above in your browser using DataLab