Closed alejandro-cermeno closed 3 years ago
Oh, sorry, ARARCH has been implemented.
So you can just estimate the parameter. If you really want to to be between 0 and 1 (usually is is somewhere between 1 and 2), then you could subclass the APARCH process and change the constraints on delta so that it has to be in a particular range.
I'm going to close since there is an obvious answer, but feel free to continue to post if not clear.
from arch.univariate import ConstantMean, APARCH
from arch.data.sp500 import load
data = load()
r = 100 * data["Adj Close"].pct_change().dropna()
mod = ConstantMean(r, volatility=APARCH())
res = mod.fit()
res
Thanks for the help. Excuse me, is it possible to specify an APARCH variance from the High-level arch_model ()
? Given the following structure / logic of my code.
from itertools import product
from arch import arch_model
# Mean
mean_ops = ['Zero', 'Constant', 'AR']
# Variance
arch_params = {'vol': 'ARCH'}
garch_params = {'p':1, 'q':1, 'vol':'GARCH'}
grj_params = {'p':1, 'o':1, 'q':1, 'vol':'GARCH'}
egarch_params = {'p': 1, 'q': 1, 'o': 1, 'vol': 'EGARCH'}
figarch_params= {'p':1, 'q':1, 'power': 2.0, 'vol':'FIGARCH'}
#aparch_params = {'p':1, 'o':1, 'q':1, 'power': 2.0, 'vol':'GARCH'}#
variance_ops = [arch_params, garch_params, grj_params, egarch_params,
aparch_params, figarch_params]
# Distributions
dist_ops = ['normal', 't', 'skewt', 'ged']
for mean, variance, dist in product(mean_ops, variance_ops, dist_ops):
mdl = arch_model(ts, mean = mean, **variance, dist = dist).fit(disp='off')
Otherwise, would a specification with the following structure be correct? I am getting NaN's in str err., conf int, etc. Thanks in advance for the answer
from arch.univariate import ConstantMean, APARCH, GeneralizedError
from arch.data.sp500 import load
data = load()
r = 100 * data["Adj Close"].pct_change().dropna()
mod = ConstantMean(r, volatility=APARCH(p=1, o=1, q=1), distribution = GeneralizedError())
res = mod.fit(disp = 'off')
You are seeing nans because the gamma is on the boundary which leads to stepping a cross when the finite difference hessian operates.
Hello Kevin:
About "_Excuse me, is it possible to specify an APARCH variance from the High-level arch_model()
?_" In current arch_model()
"APARCH" is an "Unknown model type in vol". But with small changes to the code, this volatility model could also be admitted in the High-level function.
Would it be interesting for a PR?
def arch_model(
y: Optional[ArrayLike],
x: Optional[ArrayLike] = None,
mean: str = "Constant",
lags: Optional[Union[int, List[int], NDArray]] = 0,
vol: str = "Garch",
p: Union[int, List[int]] = 1,
o: int = 0,
q: int = 1,
power: float = 2.0,
dist: str = "Normal",
hold_back: Optional[int] = None,
rescale: Optional[bool] = None,
) -> HARX:
"""
Initialization of common ARCH model specifications
Parameters
----------
y : {ndarray, Series, None}
The dependent variable
x : {np.array, DataFrame}, optional
Exogenous regressors. Ignored if model does not permit exogenous
regressors.
mean : str, optional
Name of the mean model. Currently supported options are: 'Constant',
'Zero', 'LS', 'AR', 'ARX', 'HAR' and 'HARX'
lags : int or list (int), optional
Either a scalar integer value indicating lag length or a list of
integers specifying lag locations.
vol : str, optional
Name of the volatility model. Currently supported options are:
'GARCH' (default), 'ARCH', 'EGARCH', 'FIARCH' and 'HARCH'
p : int, optional
Lag order of the symmetric innovation
o : int, optional
Lag order of the asymmetric innovation
q : int, optional
Lag order of lagged volatility or equivalent
power : float, optional
Power to use with GARCH and related models
dist : int, optional
Name of the error distribution. Currently supported options are:
* Normal: 'normal', 'gaussian' (default)
* Students's t: 't', 'studentst'
* Skewed Student's t: 'skewstudent', 'skewt'
* Generalized Error Distribution: 'ged', 'generalized error"
hold_back : int
Number of observations at the start of the sample to exclude when
estimating model parameters. Used when comparing models with different
lag lengths to estimate on the common sample.
rescale : bool
Flag indicating whether to automatically rescale data if the scale
of the data is likely to produce convergence issues when estimating
model parameters. If False, the model is estimated on the data without
transformation. If True, than y is rescaled and the new scale is
reported in the estimation results.
Returns
-------
model : ARCHModel
Configured ARCH model
Examples
--------
>>> import datetime as dt
>>> import pandas_datareader.data as web
>>> djia = web.get_data_fred('DJIA')
>>> returns = 100 * djia['DJIA'].pct_change().dropna()
A basic GARCH(1,1) with a constant mean can be constructed using only
the return data
>>> from arch.univariate import arch_model
>>> am = arch_model(returns)
Alternative mean and volatility processes can be directly specified
>>> am = arch_model(returns, mean='AR', lags=2, vol='harch', p=[1, 5, 22])
This example demonstrates the construction of a zero mean process
with a TARCH volatility process and Student t error distribution
>>> am = arch_model(returns, mean='zero', p=1, o=1, q=1,
... power=1.0, dist='StudentsT')
Notes
-----
Input that are not relevant for a particular specification, such as `lags`
when `mean='zero'`, are silently ignored.
"""
known_mean = ("zero", "constant", "harx", "har", "ar", "arx", "ls")
known_vol = ("arch", "figarch", "garch", "harch", "constant", "egarch",
"aparch")
known_dist = (
"normal",
"gaussian",
"studentst",
"t",
"skewstudent",
"skewt",
"ged",
"generalized error",
)
mean = mean.lower()
vol = vol.lower()
dist = dist.lower()
if mean not in known_mean:
raise ValueError("Unknown model type in mean")
if vol.lower() not in known_vol:
raise ValueError("Unknown model type in vol")
if dist.lower() not in known_dist:
raise ValueError("Unknown model type in dist")
if mean == "harx":
am = HARX(y, x, lags, hold_back=hold_back, rescale=rescale)
elif mean == "har":
am = HARX(y, None, lags, hold_back=hold_back, rescale=rescale)
elif mean == "arx":
am = ARX(y, x, lags, hold_back=hold_back, rescale=rescale)
elif mean == "ar":
am = ARX(y, None, lags, hold_back=hold_back, rescale=rescale)
elif mean == "ls":
am = LS(y, x, hold_back=hold_back, rescale=rescale)
elif mean == "constant":
am = ConstantMean(y, hold_back=hold_back, rescale=rescale)
else: # mean == "zero"
am = ZeroMean(y, hold_back=hold_back, rescale=rescale)
if vol in ("arch", "garch", "figarch", "egarch", "aparch") and not isinstance(p, int):
raise TypeError(
"p must be a scalar int for all volatility processes except HARCH."
)
if vol == "constant":
v: VolatilityProcess = ConstantVariance()
elif vol == "arch":
assert isinstance(p, int)
v = ARCH(p=p)
elif vol == "figarch":
assert isinstance(p, int)
v = FIGARCH(p=p, q=q)
elif vol == "garch":
assert isinstance(p, int)
v = GARCH(p=p, o=o, q=q, power=power)
elif vol == "egarch":
assert isinstance(p, int)
v = EGARCH(p=p, o=o, q=q)
elif vol == "aparch":
assert isinstance(p, int)
v = APARCH(p=p, o=o, q=q)
else: # vol == 'harch'
v = HARCH(lags=p)
if dist in ("skewstudent", "skewt"):
d: Distribution = SkewStudent()
elif dist in ("studentst", "t"):
d = StudentsT()
elif dist in ("ged", "generalized error"):
d = GeneralizedError()
else: # ('gaussian', 'normal')
d = Normal()
am.volatility = v
am.distribution = d
return am
Hello
What would be the most suitable way to obtain the optimal value of power between 0 and 1?
arch.arch_model(ret, mean='Zero', p=1, q=1, power = *¿?*, vol = 'GARCH')
For example, Ding, Granger and Engle (1993) in the paper in which they proposed the model estimated that power = 1.43 was the optimal value to model the volatility of the S&P 500 with an APARCH.
Thanks in advance for the answer