[Uwgarp-commits] r83 - in pkg/GARPFRM: . R demo man sandbox
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Feb 14 02:27:01 CET 2014
Author: tfillebeen
Date: 2014-02-14 02:27:00 +0100 (Fri, 14 Feb 2014)
New Revision: 83
Modified:
pkg/GARPFRM/NAMESPACE
pkg/GARPFRM/R/garch11.R
pkg/GARPFRM/demo/demo_EWMA_GARCH11.R
pkg/GARPFRM/man/garch11.Rd
pkg/GARPFRM/sandbox/test_EWMA_GARCH.R
Log:
demo EWMA_GARCH11
Modified: pkg/GARPFRM/NAMESPACE
===================================================================
--- pkg/GARPFRM/NAMESPACE 2014-02-11 04:49:49 UTC (rev 82)
+++ pkg/GARPFRM/NAMESPACE 2014-02-14 01:27:00 UTC (rev 83)
@@ -10,11 +10,6 @@
S3method(getStatistics,capm_uv)
S3method(hypTest,capm_mlm)
S3method(hypTest,capm_uv)
-S3method(plot,EWMACor)
-S3method(plot,EWMACovar)
-S3method(plot,EWMAVar)
-S3method(plot,capm_mlm)
-S3method(plot,capm_uv)
export(CAPM)
export(EWMA)
export(chartSML)
@@ -26,3 +21,8 @@
export(getCov)
export(getStatistics)
export(hypTest)
+export(plot.EWMACor)
+export(plot.EWMACovar)
+export(plot.EWMAVar)
+export(plot.capm_mlm)
+export(plot.capm_uv)
Modified: pkg/GARPFRM/R/garch11.R
===================================================================
--- pkg/GARPFRM/R/garch11.R 2014-02-11 04:49:49 UTC (rev 82)
+++ pkg/GARPFRM/R/garch11.R 2014-02-14 01:27:00 UTC (rev 83)
@@ -7,17 +7,22 @@
#' @param distribution.model. Valid choices are “norm” for the normal distibution, “snorm” for the skew-normal distribution, “std” for the student-t, “sstd” for the skew-student, “ged” for the generalized error distribution, “sged” for the skew-generalized error distribution, “nig” for the normal inverse gaussian distribution, “ghyp” for the Generalized Hyperbolic, and “jsu” for Johnson's SU distribution.
#' @export
# By default we use UV N~GARCH(1,1) and Bollerslev for each series
-garch11 <- function(R, model = "sGarch", distribution.model = "norm"){
+garch11 <- function(R, model = "sGARCH", distribution.model = "norm"){
garch11.spec = ugarchspec(mean.model = list(armaOrder = c(0,0)),
- variance.model = list(garchOrder = c(1,1), model),
+ variance.model = list(garchOrder = c(1,1), model = model),
distribution.model)
# DCC specification: GARCH(1,1) for conditional cor
-dcc.garch11.spec = dccspec(uspec = multispec( replicate(2, garch11.spec) ),
+nbColumns = ncol(R)
+dcc.garch11.spec = dccspec(uspec = multispec( replicate(nbColumns, garch11.spec) ),
dccOrder = c(1,1), distribution = "mvnorm")
dcc.garch11.spec
dcc.fit = dccfit(dcc.garch11.spec, data = R)
+class(dcc.fit)
+slotNames(dcc.fit)
+names(dcc.fit at mfit)
+names(dcc.fit at model)
return(dcc.fit)
}
@@ -37,5 +42,9 @@
fcstGarch11.DCCfit <- function(object, window = 100){
#if ((window > nrow(object))) {stop("Window is too large to forecast")}
result = dccforecast(garch11, n.ahead=window)
+ class(result)
+ slotNames(result)
+ class(result at mforecast)
+ names(result at mforecast)
return(result)
}
\ No newline at end of file
Modified: pkg/GARPFRM/demo/demo_EWMA_GARCH11.R
===================================================================
--- pkg/GARPFRM/demo/demo_EWMA_GARCH11.R 2014-02-11 04:49:49 UTC (rev 82)
+++ pkg/GARPFRM/demo/demo_EWMA_GARCH11.R 2014-02-14 01:27:00 UTC (rev 83)
@@ -6,20 +6,20 @@
R <- largecap.ts[, 1:4]
options(digits=4)
+
# Remember: log-returns for GARCH analysis
temp_1 = R[,1]
-temp_2 = R[,2]
-
+temp_2 = R[,3]
+
# Create combined data series
temp = merge(temp_1,temp_2)
# scatterplot of returns
-plot(coredata(temp_2), coredata(temp_2), xlab=colnames(temp_1), ylab=colnames(temp_2),
+plot(coredata(temp_1), coredata(temp_2), xlab=colnames(temp_1), ylab=colnames(temp_2),
main ="Scatterplot of Returns")
abline(h=0,v=0,lty=3)
# Compute rolling cor
-
cor.fun = function(x){
cor(x)[1,2]
}
@@ -61,45 +61,42 @@
lambda = exp(log(0.5)/halfLife)
covEwma <- EWMA(temp, lambda)
-# Dynamic Conditional Cor
-# Joint is the conditonal corr param w/ cov targeting
-garch11 <- garch11(temp)
+# Garch11 testing
+data(returns)
+tempReturns = cbind(returns[, "SPY"],returns[,"AAPL"])
+# Dynamic Conditional Cor/Cov
+garch11 <- garch11(tempReturns)
-class(garch11)
-slotNames(garch11)
-names(garch11 at mfit)
-names(garch11 at model)
-
# many extractor functions - see help on DCCfit object
# coef, likelihood, rshape, rskew, fitted, sigma, residuals, plot, infocriteria, rcor, rcov show, nisurface
# show dcc fit
garch11
-# conditional sd of each series
+# Conditional sd of each series
plot(garch11, which=2)
-# conditional covar of each series
+# Conditional covar of each series
plot(garch11, which=3)
-# conditional cor
+# Conditional cor
plot(garch11, which=4)
-# plot mutiple time series: extracting cor series
+# extracting correlation series
ts.plot(rcor(garch11)[1,2,])
-# Forecasting conditional vol and cor, default wd = 100
-fcstGarch11 = fcstGarch11(garch11)
+# # Forecasting conditional vol and cor, default wd = 100
+# fcstGarch11 = fcstGarch11(garch11,100)
-class(fcstGarch11)
-slotNames(fcstGarch11)
-class(fcstGarch11 at mforecast)
-names(fcstGarch11 at mforecast)
-
-# many method functions - see help on DCCforecast class
-# rshape, rskew, fitted, sigma, plot, rcor, rcov, show
-
-# Show forecasts
-fcstGarch11
-
-# plot(garch11, which=3)
-plot(fcstGarch11, which=3)
\ No newline at end of file
+# class(fcstGarch11)
+# slotNames(fcstGarch11)
+# class(fcstGarch11 at mforecast)
+# names(fcstGarch11 at mforecast)
+#
+# # many method functions - see help on DCCforecast class
+# # rshape, rskew, fitted, sigma, plot, rcor, rcov, show
+#
+# # Show forecasts
+# fcstGarch11
+#
+# # plot(garch11, which=3)
+# plot(fcstGarch11, which=3)
\ No newline at end of file
Modified: pkg/GARPFRM/man/garch11.Rd
===================================================================
--- pkg/GARPFRM/man/garch11.Rd 2014-02-11 04:49:49 UTC (rev 82)
+++ pkg/GARPFRM/man/garch11.Rd 2014-02-14 01:27:00 UTC (rev 83)
@@ -2,7 +2,7 @@
\alias{garch11}
\title{GARCH(1,1)}
\usage{
-garch11(R, model = "sGarch", distribution.model = "norm")
+garch11(R, model = "sGARCH", distribution.model = "norm")
}
\arguments{
\item{R}{GARCH(1,1)}
Modified: pkg/GARPFRM/sandbox/test_EWMA_GARCH.R
===================================================================
--- pkg/GARPFRM/sandbox/test_EWMA_GARCH.R 2014-02-11 04:49:49 UTC (rev 82)
+++ pkg/GARPFRM/sandbox/test_EWMA_GARCH.R 2014-02-14 01:27:00 UTC (rev 83)
@@ -6,20 +6,20 @@
R <- largecap.ts[, 1:4]
options(digits=4)
+
# Remember: log-returns for GARCH analysis
temp_1 = R[,1]
-temp_2 = R[,2]
+temp_2 = R[,3]
# Create combined data series
temp = merge(temp_1,temp_2)
# scatterplot of returns
-plot(coredata(temp_2), coredata(temp_2), xlab=colnames(temp_1), ylab=colnames(temp_2),
+plot(coredata(temp_1), coredata(temp_2), xlab=colnames(temp_1), ylab=colnames(temp_2),
main ="Scatterplot of Returns")
abline(h=0,v=0,lty=3)
# Compute rolling cor
-
cor.fun = function(x){
cor(x)[1,2]
}
@@ -61,45 +61,42 @@
lambda = exp(log(0.5)/halfLife)
covEwma <- EWMA(temp, lambda)
-# Dynamic Conditional Cor
-# Joint is the conditonal corr param w/ cov targeting
-garch11 <- garch11(temp)
+# Garch11 testing
+data(returns)
+tempReturns = cbind(returns[, "SPY"],returns[,"AAPL"])
+# Dynamic Conditional Cor/Cov
+garch11 <- garch11(tempReturns)
-class(garch11)
-slotNames(garch11)
-names(garch11 at mfit)
-names(garch11 at model)
-
# many extractor functions - see help on DCCfit object
# coef, likelihood, rshape, rskew, fitted, sigma, residuals, plot, infocriteria, rcor, rcov show, nisurface
# show dcc fit
garch11
-# conditional sd of each series
+# Conditional sd of each series
plot(garch11, which=2)
-# conditional covar of each series
+# Conditional covar of each series
plot(garch11, which=3)
-# conditional cor
+# Conditional cor
plot(garch11, which=4)
-# plot mutiple time series: extracting cor series
+# extracting correlation series
ts.plot(rcor(garch11)[1,2,])
-# Forecasting conditional vol and cor, default wd = 100
-fcstGarch11 = fcstGarch11(garch11)
+# # Forecasting conditional vol and cor, default wd = 100
+# fcstGarch11 = fcstGarch11(garch11,100)
-class(fcstGarch11)
-slotNames(fcstGarch11)
-class(fcstGarch11 at mforecast)
-names(fcstGarch11 at mforecast)
-
-# many method functions - see help on DCCforecast class
-# rshape, rskew, fitted, sigma, plot, rcor, rcov, show
-
-# Show forecasts
-fcstGarch11
-
-# plot(garch11, which=3)
-plot(fcstGarch11, which=3)
\ No newline at end of file
+# class(fcstGarch11)
+# slotNames(fcstGarch11)
+# class(fcstGarch11 at mforecast)
+# names(fcstGarch11 at mforecast)
+#
+# # many method functions - see help on DCCforecast class
+# # rshape, rskew, fitted, sigma, plot, rcor, rcov, show
+#
+# # Show forecasts
+# fcstGarch11
+#
+# # plot(garch11, which=3)
+# plot(fcstGarch11, which=3)
\ No newline at end of file
More information about the Uwgarp-commits
mailing list