给群友的R语言教学分享-经管之家官网!

人大经济论坛-经管之家 收藏本站
您当前的位置> 考研考博>>

考研

>>

给群友的R语言教学分享

给群友的R语言教学分享

发布:tulipsliu | 分类:考研

关于本站

人大经济论坛-经管之家:分享大学、考研、论文、会计、留学、数据、经济学、金融学、管理学、统计学、博弈论、统计年鉴、行业分析包括等相关资源。
经管之家是国内活跃的在线教育咨询平台!

经管之家新媒体交易平台

提供"微信号、微博、抖音、快手、头条、小红书、百家号、企鹅号、UC号、一点资讯"等虚拟账号交易,真正实现买卖双方的共赢。【请点击这里访问】

提供微信号、微博、抖音、快手、头条、小红书、百家号、企鹅号、UC号、一点资讯等虚拟账号交易,真正实现买卖双方的共赢。【请点击这里访问】

我的教学R工具包名字rugarch工具包的www.github.com网址https://github.com/cran/rugarch工具包PDF手册网址https://cran.r-project.org/web/packages/rugarch/rugarch.pdf模型数学公式InGARCHmodels,thedensityfunct ...
扫码加入金融交流群


我的教学

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 (丹尼尔·郁金香·刘)

「经管之家」APP:经管人学习、答疑、交友,就上经管之家!
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
本文关键词:

本文论坛网址:https://bbs.pinggu.org/thread-9857351-1-1.html

人气文章

1.凡人大经济论坛-经管之家转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
经管之家 人大经济论坛 大学 专业 手机版