全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1850 2
2020-10-07

我的教学

R工具包名字 rugarch

工具包的www.github.com网址
https://github.com/cran/rugarch

工具包PDF手册网址
https://cran.r-project.org/web/packages/rugarch/rugarch.pdf

模型数学公式

In GARCH models, the density function is usually written in terms of the
location and scale parameters, normalized to give zero mean and unit variance,
αt=(μt,σt,ω),{\alpha _t} = ({\mu_t},{\sigma_t},{\omega}),

where the conditional mean is given by
μt=μ(θ,xt)=E(ytxt),{\mu _t} = \mu (\theta ,{x_t}) = E({y_t}|{x_t}),

and the conditional variance is,
σt2=σ2(θ,xt)=E((ytμt)2xt),\sigma _t^2 = {\sigma ^2}(\theta ,{x_t}) = E({({y_t} - {\mu _t})^2}|{x_t}),
with ω=ω(θ,xt){\omega} = \omega (\theta ,{x_t}) denoting the remaining parameters of
the distribution, perhaps a shape and skew parameter. The conditional mean and
variance are used to scale the innovations,
zt(θ)=ytμ(θ,xt)σ(θ,xt),{z_t}(\theta ) = \frac{{{y_t} - \mu (\theta ,{x_t})}}{{\sigma (\theta ,{x_t})}},
having conditional density which may be written as,
g(zω)=ddzP(zt<zω),g(z|{\omega}) = \frac{d}{{dz}}P({z_t} < z|{\omega}),
and related to f(yα)f(y|\alpha) by,
f(ytμt,σt2,ω)=1σtg(ztω).f({y_t}|{\mu _t},\sigma _t^2,{\omega}) = \frac{1}{{{\sigma_t}}}g({z_t}|{\omega}).

The rest of this section discusses the various flavors of GARCH implemented in
the package, while Section \ref{section:distributions} discusses the
distributions implemented and their standardization for use in GARCH processes.

\subsubsection{The standard GARCH model (‘sGARCH’)}\label{section:sgarch}
The standard GARCH model (\cite{Bollerslev1986}) may be written as:
σt2=(ω+j=1mζjvjt)+j=1qαjεtj2+j=1pβjσtj2,\sigma _t^2 = \left( {\omega + \sum\limits_{j = 1}^m {{\zeta _j}{v_{jt}}} } \right) + \sum\limits_{j = 1}^q {{\alpha _j}\varepsilon _{t - j}^2 + } \sum\limits_{j = 1}^p {{\beta _j}\sigma _{t - j}^2},
with σt2\sigma_t^2 denoting the conditional variance, ω\omega the intercept
and εt2\varepsilon_t^2 the residuals from the mean filtration process discussed
previously. The GARCH order is defined by (q,p)(q, p) (ARCH, GARCH), with possibly
\verb@m@ external regressors vjv_j which are passed \emph{pre-lagged}.
If variance targeting is used, then ω\omega is replaced by,
σˉ2(1P^)j=1mζjvˉj{{\bar \sigma }^2}\left( {1 - \hat P} \right) - \sum\limits_{j = 1}^m {{\zeta _j}{{\bar v}_j}}
where σˉ2{\bar \sigma}^2 is the unconditional variance of ε2\varepsilon^2 which
is consistently estimated by its sample counterpart at every iteration of the
solver following the mean equation filtration, and vˉj{\bar v}_j represents the
sample mean of the jthj^{th} external regressors in the variance equation
(assuming stationarity), and P^\hat P is the persistence and defined below. If a
numeric value was provided to the \emph{variance.targeting} option in the specification
(instead of logical), this will be used instead of σˉ2{\bar \sigma }^2 for the
calculation.\footnote{Note that this should represent a value related to the variance
in the plain vanilla GARCH model. In more general models such as the APARCH, this is
a value related to σδ\sigma^{\delta}, which may not be obvious since δ\delta is not
known prior to estimation, and therefore care should be taken in those cases.
Finally, if scaling is used in the estimation (via the fit.control option), this value will
also be automatically scale adjusted by the routine.}
One of the key features of the observed behavior of financial data which GARCH
models capture is volatility clustering which may be quantified in the
persistence parameter P^\hat P. For the ‘sGARCH’ model this may be calculated as,
P^=j=1qαj+j=1pβj.\hat P = \sum\limits_{j = 1}^q {{\alpha _j}} + \sum\limits_{j = 1}^p {{\beta _j}}.
Related to this measure is the ‘half-life’ (call it h2lh2l) defined as the number
of days it takes for half of the expected reversion back
towards E(σ2)E\left( {{\sigma ^2}} \right) to occur,
h2l=loge2logeP^.h2l = \frac{{ - {{\log }_e}2}}{{{{\log }_e}\hat P}}.
Finally, the unconditional variance of the model σ^2{\hat \sigma }^2, and related
to its persistence, is,
σ^2=ω^1P^,{{\hat \sigma }^2} = \frac{{\hat \omega }}{{1 - \hat P}},
where ω^\hat \omega is the estimated value of the intercept from the GARCH model.
The naming conventions for passing fixed or starting parameters for this model
are:
\begin{itemize}
\item ARCH(q) parameters are ‘alpha1’, ‘alpha2’, …,
\item GARCH§ parameters are ‘beta1’, ‘beta2’, …,
\item variance intercept parameter is ‘omega’
\item the external regressor parameters are ‘vxreg1’, ‘vxreg2’, …,
\end{itemize}

简单的代码

library(rugarch) # load rugarch package to evn 
## Not run:
 require(xts) 
 require(parallel) 
 data(sp500ret)
  spx = as.xts(sp500ret) 
  nn = nrow(spx)
   nx = nn-round(0.9*nn,0) 
   if(nx h = (nx/50)-1
    indexin = lapply(1:h, function(j){ tail(seq(1,(nn-nx)+j*50, by=1),250) }) indexout = lapply(indexin, function(x){ (tail(x,1)+1):(tail(x,1)+50) })
     cl = makePSOCKcluster(5) 
     mod = arfimacv(spx, indexin, indexout, ar.max = 2, ma.max = 2, criterion = c("rmse","mae","berkowitzp")[1], berkowitz.significance = 0.05, arfima = FALSE, include.mean = NULL, distribution.model = "norm", cluster = cl, external.regressors = NULL, solver = "solnp")
 stopCluster(cl) ## End(Not run)

展望

其一 前几天论坛有朋友留言,希望我多在统计学板块发帖,所以今天来发帖一文;
其二 今天在《中国青年金融学者基地》群(去年发到论坛的群名字和群号码的,去年的中国数量金融群)做一个R源代码工具包开发的教学;同时给大家提到怎么把国际上作者提供的 /Vignettes 文件夹里的 .tex 文件(LATEX 格式的数学公式排版文件)里的数学公式提取到论坛的 markdown 发文模式。

首先, latex 的数学公式是
\begin
\sigma^2=\beta
\end{equantion}
来输入的,下面我用一个程序源代码的模式,输入markdown 的数学公式源代码。这里我也是上面那样的;
σ2=β\sigma^2=\beta

LATE 代码

$\sigma^2=\beta$

教学结束,论坛朋友的要约我会明年写帖子发。 因为今年后面三个月还有好几篇朋友的博士论文的代码。实在没时间,明年会把很多R的有趣代码和MATLAB 国际上最顶级的代码发出来,以及配合MARKDOWN 格式写出数学公式教学。

Yours : Daniel tulips liu (丹尼尔·郁金香·刘)

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2020-10-9 08:39:02
感谢分享!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2020-10-13 13:28:55
\[\hat{a}=\beta^2_t+\gamma\]


                                                              $\lgroup\sum a \sigma\rgroup$


\[\lgroup\vdots \ddots\xi=\tau_{t+}*\delta\rgroup\]
\[\hat{a}=\beta^2_t+\gamma
\eta_{t=0}=\theta^{\pi}*\sum \ddot{\beta}
\]




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群