[Uwgarp-commits] r109 - pkg/GARPFRM/sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 7 22:54:03 CET 2014


Author: rossbennett34
Date: 2014-03-07 22:54:02 +0100 (Fri, 07 Mar 2014)
New Revision: 109

Added:
   pkg/GARPFRM/sandbox/crsp_weekly_data.R
   pkg/GARPFRM/sandbox/garch_models.R
Log:
Adding file for crsp weekly returns and garch file to sandbox

Added: pkg/GARPFRM/sandbox/crsp_weekly_data.R
===================================================================
--- pkg/GARPFRM/sandbox/crsp_weekly_data.R	                        (rev 0)
+++ pkg/GARPFRM/sandbox/crsp_weekly_data.R	2014-03-07 21:54:02 UTC (rev 109)
@@ -0,0 +1,16 @@
+
+# load the crsp weekly data sets and save to the data/ folder for the GARMPFRM package
+
+library(xts)
+
+# wherever the data folder is saved
+dir <- "~/Downloads/crsp data weekly 1997-2010/"
+file <- c("largecap_weekly.csv", "midcap_weekly.csv", "smallcap_weekly.csv", "microcap_weekly.csv")
+
+
+largecap_weekly <- as.xts(read.zoo(paste(dir, file[1], sep=""), format="%m/%d/%Y", header=TRUE, sep=","))
+midcap_weekly <- as.xts(read.zoo(paste(dir, file[2], sep=""), format="%m/%d/%Y", header=TRUE, sep=","))
+smallcap_weekly <- as.xts(read.zoo(paste(dir, file[3], sep=""), format="%m/%d/%Y", header=TRUE, sep=","))
+microcap_weekly <- as.xts(read.zoo(paste(dir, file[4], sep=""), format="%m/%d/%Y", header=TRUE, sep=","))
+
+save(largecap_weekly, midcap_weekly, smallcap_weekly, microcap_weekly, file="data/crsp_weekly.rda")

Added: pkg/GARPFRM/sandbox/garch_models.R
===================================================================
--- pkg/GARPFRM/sandbox/garch_models.R	                        (rev 0)
+++ pkg/GARPFRM/sandbox/garch_models.R	2014-03-07 21:54:02 UTC (rev 109)
@@ -0,0 +1,76 @@
+
+# examples from rugarch package
+
+# http://www.unstarched.net/r-examples/rugarch/a-short-introduction-to-the-rugarch-package/
+
+# The rugarch package aims to provide for a comprehensive set of methods for 
+# modelling uni-variate GARCH processes, including fitting, filtering, 
+# forecasting, simulation as well as diagnostic tools including plots and 
+# various tests.
+
+library(rugarch)
+library(rmgarch)
+
+#' GARCH forecast
+#' 
+#' Forecasting from a GARCH model
+#' 
+#' @param object 
+#' @param nAhead number of periods ahead to forecast
+#' @param nRoll number of rolling forecasts. The rolling forecast specified by 
+#' \code{n.roll} depends on the out of sample data available in the fitted 
+#' GARCH model.
+#' @return a \code{uGARCHforecast} object
+forecast <- function(object, nAhead=10, nRoll=0){
+  out <- ugarchforecast(fitORspec=object$fit, n.ahead=nAhead, n.roll=nRoll)
+  return(out)
+}
+
+data(sp500ret)
+
+model <- foo(R=sp500ret)
+
+# Model specification
+args(ugarchspec)
+?ugarchspec
+
+# Model fitting
+args(ugarchfit)
+?ugarchfit
+
+# Forecasting
+# there are 2 methods
+# A rolling method, whereby consecutive 1-ahead forecasts are created based 
+# on the out.sample option set in the fitting routine
+
+# an unconditional method for n > 1 ahead forecasts
+
+args(ugarchboot)
+?ugarchboot
+
+# simulation
+args(ugarchsim)
+?ugarchsim
+
+# rolling estimation
+args(ugarchroll)
+?ugarchroll
+
+# multivariate GARCH specification models
+# Copula-GARCH
+# DCC-GARCH
+# GO-GARCH
+
+# Copula-GARCH specification and fit
+?cgarchspec
+?cgarchfit
+
+# DCC-GARCH specification and fit
+?dccspec
+?dccfit
+
+#GO-GARCH specification and fit
+?gogarchspec
+?gogarchfit
+
+# Also filter, forecast, roll, and sim methods



More information about the Uwgarp-commits mailing list