[Uwgarp-commits] r134 - in pkg/GARPFRM: . R demo man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 26 06:03:07 CET 2014


Author: rossbennett34
Date: 2014-03-26 06:03:05 +0100 (Wed, 26 Mar 2014)
New Revision: 134

Added:
   pkg/GARPFRM/R/generic_forecast.R
   pkg/GARPFRM/man/forecast.uvEWMAvol.Rd
   pkg/GARPFRM/man/forecast.uvGARCH.Rd
Modified:
   pkg/GARPFRM/DESCRIPTION
   pkg/GARPFRM/NAMESPACE
   pkg/GARPFRM/R/garch11.R
   pkg/GARPFRM/demo/00Index.txt
   pkg/GARPFRM/man/forecast.Rd
Log:
Making forecast a generic function for EWMA and GARCH models. Adding script for quantifying vol

Modified: pkg/GARPFRM/DESCRIPTION
===================================================================
--- pkg/GARPFRM/DESCRIPTION	2014-03-26 04:27:50 UTC (rev 133)
+++ pkg/GARPFRM/DESCRIPTION	2014-03-26 05:03:05 UTC (rev 134)
@@ -25,3 +25,4 @@
     'volatility.R'
     'boot.R'
     'utils.R'
+    'generic_forecast.R'

Modified: pkg/GARPFRM/NAMESPACE
===================================================================
--- pkg/GARPFRM/NAMESPACE	2014-03-26 04:27:50 UTC (rev 133)
+++ pkg/GARPFRM/NAMESPACE	2014-03-26 05:03:05 UTC (rev 134)
@@ -48,6 +48,8 @@
 export(tangentPortfolio)
 export(uvGARCH)
 S3method(fcstGarch11,DCCfit)
+S3method(forecast,uvEWMAvol)
+S3method(forecast,uvGARCH)
 S3method(getAlphas,capm_mlm)
 S3method(getAlphas,capm_uv)
 S3method(getBetas,capm_mlm)

Modified: pkg/GARPFRM/R/garch11.R
===================================================================
--- pkg/GARPFRM/R/garch11.R	2014-03-26 04:27:50 UTC (rev 133)
+++ pkg/GARPFRM/R/garch11.R	2014-03-26 05:03:05 UTC (rev 134)
@@ -190,28 +190,4 @@
   plot(getFit(x), which=which, ...=...)
 }
 
-#' Forecast Univariate GARCH Models
-#' 
-#' Forecasting for GARCH models fit via \code{uvGARCH}
-#' 
-#' @note For rolling forecasts specified with the \code{nRoll} argument, the
-#' GARCH model must be fit with \code{outSample} argument greater than or 
-#' equal to \code{nRoll}.
-#' 
-#' @param garch GARCH model fit via \code{uvGARCH}
-#' @param nAhead number of steps ahead to forecast
-#' @param nRoll number of rolling forecasts
-#' @param externalForecasts named list of external regressors in the mean and/or
-#' variance equations
-#' @param \dots additional parameters passed to \code{ugarchforecast}
-#' @return a uGARCHforecast object with the GARCH forecast data
-#' @export
-forecast <- function(garch, nAhead=10, nRoll=0, externalForecasts=NULL, ...){
-  
-  if(is.null(externalForecasts)){
-    externalForecasts <- list(mregfor = NULL, vregfor = NULL)
-  }
-  out <- ugarchforecast(garch$fit, n.ahead=nAhead, n.roll=nRoll, 
-                        external.forecasts=externalForecasts, ...=...)
-  return(out)
-}
+

Added: pkg/GARPFRM/R/generic_forecast.R
===================================================================
--- pkg/GARPFRM/R/generic_forecast.R	                        (rev 0)
+++ pkg/GARPFRM/R/generic_forecast.R	2014-03-26 05:03:05 UTC (rev 134)
@@ -0,0 +1,72 @@
+
+#' Model Forecasting
+#' 
+#' Generic method for forecasting from EWMA and GARCH models
+#' @param model a model object
+#' @param nAhead number of periods ahead to forecast
+#' @param \dots any other passthrough parameters
+#' @return forecasted value from model
+#' @author Ross Bennett
+#' @export
+forecast <- function(model, nAhead, ...){
+  UseMethod("forecast")
+}
+
+#' Forecast Univariate GARCH Models
+#' 
+#' Forecasting for GARCH models fit via \code{\link{uvGARCH}}
+#' 
+#' @note For rolling forecasts specified with the \code{nRoll} argument, the
+#' GARCH model must be fit with \code{outSample} argument greater than or 
+#' equal to \code{nRoll}.
+#' 
+#' @param model GARCH model fit via \code{\link{uvGARCH}}
+#' @param nAhead number of steps ahead to forecast
+#' @param \dots additional parameters passed to \code{ugarchforecast}
+#' @param nRoll number of rolling forecasts
+#' @param externalForecasts named list of external regressors in the mean and/or
+#' variance equations
+#' @return a uGARCHforecast object with the GARCH forecast data
+#' @method forecast uvGARCH
+#' @S3method forecast uvGARCH
+forecast.uvGARCH <- function(model, nAhead=10, ..., nRoll=0, externalForecasts=NULL){
+  
+  if(is.null(externalForecasts)){
+    externalForecasts <- list(mregfor = NULL, vregfor = NULL)
+  }
+  out <- ugarchforecast(model$fit, n.ahead=nAhead, n.roll=nRoll, 
+                        external.forecasts=externalForecasts, ...=...)
+  return(out)
+}
+
+#' Forecast Univariate EWMA Volatility Model
+#' 
+#' Forecasting for EWMA Volatility models fit via \code{\link{EWMA}}
+#' 
+#' @param model EWMA model fit via \code{\link{EWMA}}
+#' @param nAhead number of steps ahead to forecast. (nAhead = 1 only supported)
+#' @param \dots additional passthrough parameters
+#' @param nRoll number of rolling forecasts
+#' @param externalForecasts named list of external regressors in the mean and/or
+#' variance equations
+#' @return one period ahead EWMA volatility forecast
+#' @method forecast uvEWMAvol
+#' @S3method forecast uvEWMAvol
+forecast.uvEWMAvol <- function(model, nAhead=1, ...){
+  # 1 step ahead EWMA forecast
+  lambda <- model$model$lambda
+  sigma_hat <- last(model$estimate)
+  r <- last(model$data$R)
+  T0 <- last(index(r))
+  tmp <- as.numeric(sqrt(lambda * sigma_hat^2 + (1 - lambda) * r^2))
+  
+  df <- data.frame(tmp, row.names="T+1")
+  colnames(df) <- model$model$type
+  df
+}
+
+# forecast for
+# uvEWMAcov
+# uvEWMAcor
+# mvEWMAcov
+# mvEWMAcor

Modified: pkg/GARPFRM/demo/00Index.txt
===================================================================
--- pkg/GARPFRM/demo/00Index.txt	2014-03-26 04:27:50 UTC (rev 133)
+++ pkg/GARPFRM/demo/00Index.txt	2014-03-26 05:03:05 UTC (rev 134)
@@ -4,4 +4,4 @@
 EWMA.R demonstrate exponentially weighted moving average model
 monte_carlo.R demonstrate monte carlo method to simulate asset price paths
 univariate_GARCH.R demonstrate fitting a GARCH model to a univariate data set
-backtest_VaR.R demonstrate Value at Risk backtesting
\ No newline at end of file
+backtest_VaR.R demonstrate Value at Risk backtesting

Modified: pkg/GARPFRM/man/forecast.Rd
===================================================================
--- pkg/GARPFRM/man/forecast.Rd	2014-03-26 04:27:50 UTC (rev 133)
+++ pkg/GARPFRM/man/forecast.Rd	2014-03-26 05:03:05 UTC (rev 134)
@@ -1,33 +1,23 @@
 \name{forecast}
 \alias{forecast}
-\title{Forecast Univariate GARCH Models}
+\title{Model Forecasting}
 \usage{
-  forecast(garch, nAhead = 10, nRoll = 0,
-    externalForecasts = NULL, ...)
+  forecast(model, nAhead, ...)
 }
 \arguments{
-  \item{garch}{GARCH model fit via \code{uvGARCH}}
+  \item{model}{a model object}
 
-  \item{nAhead}{number of steps ahead to forecast}
+  \item{nAhead}{number of periods ahead to forecast}
 
-  \item{nRoll}{number of rolling forecasts}
-
-  \item{externalForecasts}{named list of external
-  regressors in the mean and/or variance equations}
-
-  \item{\dots}{additional parameters passed to
-  \code{ugarchforecast}}
+  \item{\dots}{any other passthrough parameters}
 }
 \value{
-  a uGARCHforecast object with the GARCH forecast data
+  forecasted value from model
 }
 \description{
-  Forecasting for GARCH models fit via \code{uvGARCH}
+  Generic method for forecasting from EWMA and GARCH models
 }
-\note{
-  For rolling forecasts specified with the \code{nRoll}
-  argument, the GARCH model must be fit with
-  \code{outSample} argument greater than or equal to
-  \code{nRoll}.
+\author{
+  Ross Bennett
 }
 

Added: pkg/GARPFRM/man/forecast.uvEWMAvol.Rd
===================================================================
--- pkg/GARPFRM/man/forecast.uvEWMAvol.Rd	                        (rev 0)
+++ pkg/GARPFRM/man/forecast.uvEWMAvol.Rd	2014-03-26 05:03:05 UTC (rev 134)
@@ -0,0 +1,27 @@
+\name{forecast.uvEWMAvol}
+\alias{forecast.uvEWMAvol}
+\title{Forecast Univariate EWMA Volatility Model}
+\usage{
+  \method{forecast}{uvEWMAvol} (model, nAhead = 1, ...)
+}
+\arguments{
+  \item{model}{EWMA model fit via \code{\link{EWMA}}}
+
+  \item{nAhead}{number of steps ahead to forecast. (nAhead
+  = 1 only supported)}
+
+  \item{\dots}{additional passthrough parameters}
+
+  \item{nRoll}{number of rolling forecasts}
+
+  \item{externalForecasts}{named list of external
+  regressors in the mean and/or variance equations}
+}
+\value{
+  one period ahead EWMA volatility forecast
+}
+\description{
+  Forecasting for EWMA Volatility models fit via
+  \code{\link{EWMA}}
+}
+

Added: pkg/GARPFRM/man/forecast.uvGARCH.Rd
===================================================================
--- pkg/GARPFRM/man/forecast.uvGARCH.Rd	                        (rev 0)
+++ pkg/GARPFRM/man/forecast.uvGARCH.Rd	2014-03-26 05:03:05 UTC (rev 134)
@@ -0,0 +1,34 @@
+\name{forecast.uvGARCH}
+\alias{forecast.uvGARCH}
+\title{Forecast Univariate GARCH Models}
+\usage{
+  \method{forecast}{uvGARCH} (model, nAhead = 10, ...,
+    nRoll = 0, externalForecasts = NULL)
+}
+\arguments{
+  \item{model}{GARCH model fit via \code{\link{uvGARCH}}}
+
+  \item{nAhead}{number of steps ahead to forecast}
+
+  \item{\dots}{additional parameters passed to
+  \code{ugarchforecast}}
+
+  \item{nRoll}{number of rolling forecasts}
+
+  \item{externalForecasts}{named list of external
+  regressors in the mean and/or variance equations}
+}
+\value{
+  a uGARCHforecast object with the GARCH forecast data
+}
+\description{
+  Forecasting for GARCH models fit via
+  \code{\link{uvGARCH}}
+}
+\note{
+  For rolling forecasts specified with the \code{nRoll}
+  argument, the GARCH model must be fit with
+  \code{outSample} argument greater than or equal to
+  \code{nRoll}.
+}
+



More information about the Uwgarp-commits mailing list