R/rdcc-startpars.R

#################################################################################
##
##   R package rgarch by Alexios Ghalanos Copyright (C) 2008, 2009, 2010, 2011
##   This file is part of the R package rgarch.
##
##   The R package rgarch is free software: you can redistribute it and/or modify
##   it under the terms of the GNU General Public License as published by
##   the Free Software Foundation, either version 3 of the License, or
##   (at your option) any later version.
##
##   The R package rgarch is distributed in the hope that it will be useful,
##   but WITHOUT ANY WARRANTY; without even the implied warranty of
##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##   GNU General Public License for more details.
##
#################################################################################

.dccstart = function(data, garchenv)
{
	# extract required sets
	omodel = get("omodel", garchenv)
	start.pars = omodel$start.pars
	opt.pars = omodel$opt.pars
	fixed.pars = omodel$fixed.pars
	pos = omodel$pos.matrix
	opt.names = names(opt.pars)
	fixed.names = names(fixed.pars)
	start.names = names(start.pars)
	mspec = get("mspec", garchenv)
	dccp = mspec$dccOrder[1]
	dccq = mspec$dccOrder[2]
	pars = opt.pars
	LB = rep(0, length(opt.pars))
	UB = rep(0, length(opt.pars))
	names(LB) = names(UB) = opt.names
	if(pos[1,3]){
		gpnames = paste("dcca", 1:dccp, sep = "")
		LB[gpnames] = 0
		UB[gpnames] = 0.9998
		pars[gpnames] = rep(0.05/dccp, dccp)
		if(any(substr(start.names, 1, 4) == "dcca")){
			j = which(substr(start.names, 1, 4) == "dcca")
			gpmatch = charmatch(start.names[j], gpnames)
			pars[gpnames[gpmatch]] = as.numeric(start.pars[j])
		}
		if(any(substr(fixed.names, 1, 4) == "dcca")){
			j = which(substr(fixed.names, 1, 4) == "dcca")
			gpmatch = charmatch(fixed.names[j], gpnames)
			pars[gpnames[gpmatch]] = as.numeric(fixed.pars[j])
			LB[gpnames[gpmatch]] = as.numeric(fixed.pars[j])
			UB[gpnames[gpmatch]] = as.numeric(fixed.pars[j])
		}
	}
	
	if(pos[2,3]){
		gpnames = paste("dccb", 1:dccq, sep = "")
		LB[gpnames] = 0
		UB[gpnames] = 0.9998
		pars[gpnames] = rep(0.9/dccq, dccq)
		if(any(substr(start.names, 1, 4) == "dccb")){
			j = which(substr(start.names, 1, 4) == "dccb")
			gpmatch = charmatch(start.names[j], gpnames)
			pars[gpnames[gpmatch]] = as.numeric(start.pars[j])
		}
		if(any(substr(fixed.names, 1, 4) == "dccb")){
			j = which(substr(fixed.names, 1, 4) == "dccb")
			gpmatch = charmatch(fixed.names[j], gpnames)
			pars[gpnames[gpmatch]] = as.numeric(fixed.pars[j])
			LB[gpnames[gpmatch]] = as.numeric(fixed.pars[j])
			UB[gpnames[gpmatch]] = as.numeric(fixed.pars[j])
		}
	}
	
	dbounds = .mDistributionBounds(distribution = mspec$distribution)
	# skew

	if(pos[3,3]){
		LB["skew"] = dbounds$skew.LB
		UB["skew"] = dbounds$skew.UB
		if(is.null(start.pars$skew)) pars["skew"] = dbounds$skew else pars["skew"] = start.pars$skew[1]
		if(any(substr(fixed.names, 1, 4) == "skew")){
			pars["skew"] = as.numeric(fixed.pars$skew)
			LB["skew"] = fixed.pars$skew
			UB["skew"] = fixed.pars$skew
		}
	}
	
	# shape
	if(pos[4,3]){
		if(is.null(start.pars$shape)) pars["shape"] = dbounds$shape else pars["shape"] = start.pars$shape[1]
		LB["shape"] = dbounds$shape.LB
		UB["shape"] = dbounds$shape.UB
		if(any(substr(fixed.names, 1, 5) == "shape")){
			pars["shape"] = as.numeric(fixed.pars$shape)
			LB["shape"] = fixed.pars$shape
			UB["shape"] = fixed.pars$shape
		}
	}
	
	modelLB = LB
	modelUB = UB
	return(list(pars = pars, modelLB = modelLB, modelUB = modelUB))
}

Try the rgarch package in your browser

Any scripts or data that you put into this service are public.

rgarch documentation built on May 2, 2019, 5:22 p.m.