[Uwgarp-commits] r124 - in pkg/GARPFRM: sandbox vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Mar 22 21:49:28 CET 2014


Author: rossbennett34
Date: 2014-03-22 21:49:28 +0100 (Sat, 22 Mar 2014)
New Revision: 124

Added:
   pkg/GARPFRM/sandbox/Correlation_Volatility_TF.Rnw
Removed:
   pkg/GARPFRM/vignettes/CAPM_TF.tex
   pkg/GARPFRM/vignettes/Correlation_Volatility_TF.Rnw
   pkg/GARPFRM/vignettes/Correlation_Volatility_TF.pdf
   pkg/GARPFRM/vignettes/Correlation_Volatility_TF.tex
   pkg/GARPFRM/vignettes/EWMA_GARCH11_TF-concordance.tex
   pkg/GARPFRM/vignettes/EWMA_GARCH11_TF.tex
   pkg/GARPFRM/vignettes/RB.pdf
   pkg/GARPFRM/vignettes/RB.tex
Log:
Cleaning up vignettes folder

Copied: pkg/GARPFRM/sandbox/Correlation_Volatility_TF.Rnw (from rev 115, pkg/GARPFRM/vignettes/Correlation_Volatility_TF.Rnw)
===================================================================
--- pkg/GARPFRM/sandbox/Correlation_Volatility_TF.Rnw	                        (rev 0)
+++ pkg/GARPFRM/sandbox/Correlation_Volatility_TF.Rnw	2014-03-22 20:49:28 UTC (rev 124)
@@ -0,0 +1,130 @@
+\documentclass[a4paper]{article}
+\usepackage[OT1]{fontenc}
+\usepackage{Sweave}
+\usepackage{Rd}
+\usepackage{amsmath}
+\usepackage{hyperref}
+\usepackage{url}
+\usepackage[round]{natbib}
+\usepackage{bm}
+\usepackage{verbatim}
+\usepackage[latin1]{inputenc}
+\bibliographystyle{abbrvnat}
+
+\let\proglang=\textsf
+%\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}}
+%\newcommand{\R}[1]{{\fontseries{b}\selectfont #1}}
+%\newcommand{\email}[1]{\href{mailto:#1}{\normalfont\texttt{#1}}}
+%\newcommand{\E}{\mathsf{E}}
+%\newcommand{\VAR}{\mathsf{VAR}}
+%\newcommand{\COV}{\mathsf{COV}}
+%\newcommand{\Prob}{\mathsf{P}}
+
+\renewcommand{\topfraction}{0.85}
+\renewcommand{\textfraction}{0.1}
+\renewcommand{\baselinestretch}{1.5}
+\setlength{\textwidth}{15cm} \setlength{\textheight}{22cm} \topmargin-1cm \evensidemargin0.5cm \oddsidemargin0.5cm
+
+\usepackage[latin1]{inputenc}
+% or whatever
+
+\usepackage{lmodern}
+\usepackage[T1]{fontenc}
+% Or whatever. Note that the encoding and the font should match. If T1
+% does not look nice, try deleting the line with the fontenc.
+
+\begin{document}
+
+\title{Estimating Volatilities and Correlations}
+\author{Thomas Fillebeen}
+
+\maketitle
+
+\begin{abstract}
+Using historical CRSP data to produce estimates of current and future levels of volatilies and correlations. The vignette explores exponentially weighted moving average (EWMA), and generealized autoregressive conditional heteroscedasticity (GARCH(1,1)). These models recognize that volatilities and correlations are not constant. The models attempt to track variations in volatilities or correlation and forecast them into the future.
+\end{abstract}
+
+\tableofcontents
+
+\section{EWMA Covariance and Correlation}
+\subsection{Selected Returns Time Series}
+<<ex1>>=
+# 'Load the GARPFRM package and CRSP dataset for analysis.
+suppressMessages(library(GARPFRM))
+suppressMessages(library(rugarch))
+suppressMessages(library(rmgarch))
+options(digits=4)
+
+data(crsp.short)
+R <- largecap.ts[, 1:4]
+@
+\subsection{Estimating Correlation and Volatility}
+<<ex2>>=
+# Remember: log-returns for GARCH analysis
+asset1 = R[,1] 
+asset2 = R[,3]
+   
+# Create combined data series
+cAssets = cbind(asset1,asset2)
+
+# Scatterplot of returns
+plot(coredata(asset1), coredata(asset2), xlab=colnames(asset1), 
+     ylab=colnames(asset2), main ="Scatterplot of Returns")
+abline(h=0,v=0,lty=3)
+@
+\subsection{EWMA Correlation and Volatility}
+<<ex3>>=
+# Calculate EWMA cov and cor, applying default lambda - 0.94
+cAssetsEWMACov <- EWMA(cAssets,lambda=0.94, initialWindow=50, cor=FALSE)
+cAssetsEWMACor <- EWMA(cAssets,lambda=0.94, initialWindow=50, cor=TRUE)
+
+# Plots
+par(mfrow=c(2,1))
+plot(cAssetsEWMACov,asset1=1,asset2=2)
+plot(cAssetsEWMACor, asset1=1,asset2=2)
+par(mfrow=c(1,1))
+
+# Compute EWMA cov and cor for longer half-life of 
+halfLife = log(0.5)/log(0.94) + 5
+lambda = exp(log(0.5)/halfLife)
+covEwma <- EWMA(cAssets, lambda)
+@
+
+\section{GARCH(1,1) Conditional Correlation and Variance}
+\subsection{GARCH(1,1) Estimation and Plotting}
+<<ex4>>=
+# Garch11 testing: need 100 plus data points to forecast. 
+# Load lengthier dataset.
+data(returns)
+cAssetsReturns = cbind(returns[, "SPY"],returns[,"AAPL"])
+# Dynamic Conditional Cor/Cov
+garch11 <- garch11(cAssetsReturns)
+
+# garch11 is a dcc.fit object. There are multiple extraction functions to be exploited.
+# Illustrate garch11, dcc.fit object.
+
+# Conditional Sigma (vs Realized Absolute Returns)
+plot(garch11, which=2)
+
+# Conditional covar of each series
+plot(garch11, which=3)
+
+# Conditional cor
+plot(garch11, which=4)
+@
+\subsection{Forecasting GARCH(1,1) Plotting}
+<<ex5>>=
+# Forecasting conditional vol and cor, default wd = 100
+fcstGarch11 = fcstGarch11(garch11,100)
+
+# Many method functions - see help on DCCforecast class
+# rshape, rskew, fitted, sigma, plot, rcor, rcov, show
+
+# Show forecasts
+fcstGarch11
+
+# Plot Conditional Covar Forecast 
+plot(fcstGarch11, which=3)
+@
+
+\end{document}
\ No newline at end of file

Deleted: pkg/GARPFRM/vignettes/CAPM_TF.tex
===================================================================
--- pkg/GARPFRM/vignettes/CAPM_TF.tex	2014-03-22 20:19:01 UTC (rev 123)
+++ pkg/GARPFRM/vignettes/CAPM_TF.tex	2014-03-22 20:49:28 UTC (rev 124)
@@ -1,330 +0,0 @@
-\documentclass[a4paper]{article}\usepackage[]{graphicx}\usepackage[]{color}
-%% maxwidth is the original width if it is less than linewidth
-%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
-\makeatletter
-\def\maxwidth{ %
-  \ifdim\Gin at nat@width>\linewidth
-    \linewidth
-  \else
-    \Gin at nat@width
-  \fi
-}
-\makeatother
-
-\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
-\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
-\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
-\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
-\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
-\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
-\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
-\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
-\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
-\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
-
-\usepackage{framed}
-\makeatletter
-\newenvironment{kframe}{%
- \def\at at end@of at kframe{}%
- \ifinner\ifhmode%
-  \def\at at end@of at kframe{\end{minipage}}%
-  \begin{minipage}{\columnwidth}%
- \fi\fi%
- \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
- \colorbox{shadecolor}{##1}\hskip-\fboxsep
-     % There is no \\@totalrightmargin, so:
-     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
- \MakeFramed {\advance\hsize-\width
-   \@totalleftmargin\z@ \linewidth\hsize
-   \@setminipage}}%
- {\par\unskip\endMakeFramed%
- \at at end@of at kframe}
-\makeatother
-
-\definecolor{shadecolor}{rgb}{.97, .97, .97}
-\definecolor{messagecolor}{rgb}{0, 0, 0}
-\definecolor{warningcolor}{rgb}{1, 0, 1}
-\definecolor{errorcolor}{rgb}{1, 0, 0}
-\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
-
-\usepackage{alltt}
-\usepackage[OT1]{fontenc}
-\usepackage{Sweave}
-\usepackage{Rd}
-\usepackage{amsmath}
-\usepackage{hyperref}
-\usepackage{url}
-\usepackage[round]{natbib}
-\usepackage{bm}
-\usepackage{verbatim}
-\usepackage[latin1]{inputenc}
-\bibliographystyle{abbrvnat}
-
-\let\proglang=\textsf
-%\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}}
-%\newcommand{\R}[1]{{\fontseries{b}\selectfont #1}}
-%\newcommand{\email}[1]{\href{mailto:#1}{\normalfont\texttt{#1}}}
-%\newcommand{\E}{\mathsf{E}}
-%\newcommand{\VAR}{\mathsf{VAR}}
-%\newcommand{\COV}{\mathsf{COV}}
-%\newcommand{\Prob}{\mathsf{P}}
-
-\renewcommand{\topfraction}{0.85}
-\renewcommand{\textfraction}{0.1}
-\renewcommand{\baselinestretch}{1.5}
-\setlength{\textwidth}{15cm} \setlength{\textheight}{22cm} \topmargin-1cm \evensidemargin0.5cm \oddsidemargin0.5cm
-
-\usepackage[latin1]{inputenc}
-% or whatever
-
-\usepackage{lmodern}
-\usepackage[T1]{fontenc}
-% Or whatever. Note that the encoding and the font should match. If T1
-% does not look nice, try deleting the line with the fontenc.
-\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
-
-\begin{document}
-
-\title{CAPM Fitting and Testing}
-\author{Thomas Fillebeen}
-
-\maketitle
-
-\begin{abstract}
-Standard Capital Asset Pricing Model (CAPM) fitting and testing using Quandl data.
-
-CAPM Assumptions
-1. Identical investors who are price takers;
-2. Investment over the same time horizon; 
-3. No transaction costs or taxes;
-4. Can borrow and lend at risk-free rate;
-5. Investors only care about portfolio expected return and variance;
-6. Market consists of all publicly traded assets.
-
-The Consumption-Oriented CAPM is analogous to the simple form of the CAPM. Except that the growth rate of per capita consumption has replaced the rate of return on the market porfolio as the influence effecting returns.
-\end{abstract}
-
-\tableofcontents
-
-\section{Fitting CAPM}
-\subsection{Selected Returns Time Series}
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# 'Load the GARPFRM package and CRSP dataset for CAPM analysis.}
-\hlkwd{suppressMessages}\hlstd{(}\hlkwd{library}\hlstd{(GARPFRM))}
-\hlkwd{options}\hlstd{(}\hlkwc{digits} \hlstd{=} \hlnum{3}\hlstd{)}
-\hlkwd{data}\hlstd{(crsp.short)}
-
-\hlstd{stock.df} \hlkwb{<-} \hlstd{largecap.ts[,} \hlnum{1}\hlopt{:}\hlnum{20}\hlstd{]}
-\hlstd{mrkt} \hlkwb{<-} \hlstd{largecap.ts[,} \hlstr{"market"}\hlstd{]}
-\hlstd{rfr} \hlkwb{<-} \hlstd{largecap.ts[,} \hlstr{"t90"}\hlstd{]}
-
-\hlcom{# Plot first four stocks from}
-\hlkwd{plot.zoo}\hlstd{(stock.df[,} \hlnum{1}\hlopt{:}\hlnum{4}\hlstd{],} \hlkwc{main} \hlstd{=} \hlstr{"First Four Large Cap Returns"}\hlstd{)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex1} 
-
-\end{knitrout}
-
-
-
-Summarize the start and end dates corresponding to the first 4 large cap returns.
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# Illustrate the type of data being analzyed: start-end dates.}
-\hlkwd{start}\hlstd{(stock.df[,} \hlnum{1}\hlopt{:}\hlnum{4}\hlstd{])}
-\end{alltt}
-\begin{verbatim}
-## [1] "1997-01-31"
-\end{verbatim}
-\begin{alltt}
-\hlkwd{end}\hlstd{(stock.df[,} \hlnum{1}\hlopt{:}\hlnum{4}\hlstd{])}
-\end{alltt}
-\begin{verbatim}
-## [1] "2001-12-31"
-\end{verbatim}
-\begin{alltt}
-\hlcom{# Count the number of rows: sample size.}
-\hlkwd{nrow}\hlstd{(stock.df)}
-\end{alltt}
-\begin{verbatim}
-## [1] 60
-\end{verbatim}
-\end{kframe}
-\end{knitrout}
-
-\subsection{Estimate Excess Returns}
-Estimate excess returns: subtracting off risk-free rate.
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# Excess Returns initialized before utilizing in CAPM}
-\hlstd{exReturns} \hlkwb{<-} \hlkwd{Return.excess}\hlstd{(stock.df, rfr)}
-\hlkwd{colnames}\hlstd{(exReturns)} \hlkwb{=} \hlkwd{c}\hlstd{(}\hlkwd{colnames}\hlstd{(stock.df))}
-\end{alltt}
-\end{kframe}
-\end{knitrout}
-
-
-\subsection{Fitting CAPM Model: Univariate}
-Run CAPM regression for AMAT and estimate CAPM with $\alpha=0$ \& $\beta=1$ for asset.
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# Univariate CAPM}
-\hlstd{uv} \hlkwb{<-} \hlkwd{CAPM}\hlstd{(exReturns[,} \hlnum{1}\hlstd{], mrkt)}
-\hlkwd{getStatistics}\hlstd{(uv)}
-\end{alltt}
-\begin{verbatim}
-##             Estimate Std. Error t value Pr(>|t|)
-## alpha. AMAT   0.0158     0.0174   0.909 0.366872
-## beta.  AMAT   2.2611     0.3192   3.951 0.000213
-\end{verbatim}
-\begin{alltt}
-\hlcom{# Plot data with regression line}
-\hlkwd{plot}\hlstd{(uv)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex4} 
-
-\end{knitrout}
-
-\subsection{CAPM Model: Multiple Asset Analysis}
-Run CAPM regression
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# MLM CAPM for AMAT, AMGN, and CAT}
-\hlstd{mlm} \hlkwb{<-} \hlkwd{CAPM}\hlstd{(exReturns[,} \hlnum{1}\hlopt{:}\hlnum{3}\hlstd{], mrkt)}
-\hlkwd{getStatistics}\hlstd{(mlm)}
-\end{alltt}
-\begin{verbatim}
-##             Estimate Std. Error t value Pr(>|t|)
-## alpha. AMAT  0.01580     0.0174   0.909 0.366872
-## beta.  AMAT  2.26113     0.3192   3.951 0.000213
-## alpha. AMGN  0.01887     0.0150   1.256 0.214198
-## beta.  AMGN  0.86859     0.2760  -0.476 0.635765
-## alpha. CAT   0.00231     0.0122   0.190 0.850330
-## beta.  CAT   0.60218     0.2241  -1.775 0.081064
-\end{verbatim}
-\begin{alltt}
-\hlcom{# Plot data with regression line}
-\hlkwd{plot}\hlstd{(mlm)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex5} 
-
-\end{knitrout}
-
-\section{Testing CAPM}
-\subsection{Retrieve $\alpha$ \& $\beta$ and Estimate Result Significance}
-Retrieve $\alpha$ \& $\beta$ from CAPM object for one or multiple assets and run hypothesis test.
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# For uv}
-\hlkwd{getBetas}\hlstd{(uv)}
-\end{alltt}
-\begin{verbatim}
-## beta.  AMAT 
-##        2.26
-\end{verbatim}
-\begin{alltt}
-\hlkwd{getAlphas}\hlstd{(uv)}
-\end{alltt}
-\begin{verbatim}
-## alpha. AMAT 
-##      0.0158
-\end{verbatim}
-\begin{alltt}
-\hlkwd{hypTest}\hlstd{(uv,} \hlkwc{CI} \hlstd{=} \hlnum{0.05}\hlstd{)}
-\end{alltt}
-\begin{verbatim}
-## $alpha
-## [1] FALSE
-## 
-## $beta
-## [1] TRUE
-\end{verbatim}
-\begin{alltt}
-\hlcom{# For mlm}
-\hlkwd{getBetas}\hlstd{(mlm)}
-\end{alltt}
-\begin{verbatim}
-## beta.  AMAT beta.  AMGN  beta.  CAT 
-##       2.261       0.869       0.602
-\end{verbatim}
-\begin{alltt}
-\hlkwd{getAlphas}\hlstd{(mlm)}
-\end{alltt}
-\begin{verbatim}
-## alpha. AMAT alpha. AMGN  alpha. CAT 
-##     0.01580     0.01887     0.00231
-\end{verbatim}
-\begin{alltt}
-\hlkwd{hypTest}\hlstd{(mlm,} \hlkwc{CI} \hlstd{=} \hlnum{0.05}\hlstd{)}
-\end{alltt}
-\begin{verbatim}
-## $alpha
-## alpha. AMAT alpha. AMGN  alpha. CAT 
-##       FALSE       FALSE       FALSE 
-## 
-## $beta
-## beta.  AMAT beta.  AMGN  beta.  CAT 
-##        TRUE       FALSE       FALSE
-\end{verbatim}
-\end{kframe}
-\end{knitrout}
-
-
-\subsection{Estimate Expected Returns and Plot}
-Plot expected return versus beta.
-Estimate expected returns
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# MLM CAPM}
-\hlstd{mlm} \hlkwb{<-} \hlkwd{CAPM}\hlstd{(exReturns[, ], mrkt)}
-
-\hlcom{# Plot expected returns versus betas}
-\hlkwd{chartSML}\hlstd{(mlm)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex7} 
-
-\end{knitrout}
-
-
-\section{Consumption-Oriented CAPM}
-\subsection{Fitting C-CAPM}
-Run C-CAPM regression for CONS (Consumption).
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# Load FED consumption data: CONS}
-\hlkwd{data}\hlstd{(cons)}
-\hlstd{cons} \hlkwb{<-} \hlkwd{xts}\hlstd{(cons[,} \hlnum{2}\hlstd{],} \hlkwd{index}\hlstd{(largecap.ts))}
-\hlkwd{colnames}\hlstd{(cons)} \hlkwb{=} \hlkwd{c}\hlstd{(}\hlstr{"CONS"}\hlstd{)}
-
-\hlstd{capm.cons} \hlkwb{=} \hlkwd{CAPM}\hlstd{(cons, mrkt)}
-\hlkwd{coef}\hlstd{(}\hlkwd{summary}\hlstd{(capm.cons))}
-\end{alltt}
-\begin{verbatim}
-##             Estimate Std. Error t value Pr(>|t|)
-## (Intercept)    0.174      0.025    6.94 3.64e-09
-## Rmkt           0.481      0.460    1.04 3.01e-01
-\end{verbatim}
-\begin{alltt}
-\hlcom{# Plot data with regression line}
-\hlkwd{plot}\hlstd{(capm.cons)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex8} 
-
-\end{knitrout}
-
-NOTE: Specific problems with CCAPM is that it suffers from two puzzles: the equity premium puzzle (EPP) and the risk-free rate puzzle (RFRP). EPP implies that investors are extremely risk averse to explain the existence of a market risk premium. While RFRP stipulates that investors save in TBills despite the low rate of return.
-\end{document}

Deleted: pkg/GARPFRM/vignettes/Correlation_Volatility_TF.Rnw
===================================================================
--- pkg/GARPFRM/vignettes/Correlation_Volatility_TF.Rnw	2014-03-22 20:19:01 UTC (rev 123)
+++ pkg/GARPFRM/vignettes/Correlation_Volatility_TF.Rnw	2014-03-22 20:49:28 UTC (rev 124)
@@ -1,130 +0,0 @@
-\documentclass[a4paper]{article}
-\usepackage[OT1]{fontenc}
-\usepackage{Sweave}
-\usepackage{Rd}
-\usepackage{amsmath}
-\usepackage{hyperref}
-\usepackage{url}
-\usepackage[round]{natbib}
-\usepackage{bm}
-\usepackage{verbatim}
-\usepackage[latin1]{inputenc}
-\bibliographystyle{abbrvnat}
-
-\let\proglang=\textsf
-%\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}}
-%\newcommand{\R}[1]{{\fontseries{b}\selectfont #1}}
-%\newcommand{\email}[1]{\href{mailto:#1}{\normalfont\texttt{#1}}}
-%\newcommand{\E}{\mathsf{E}}
-%\newcommand{\VAR}{\mathsf{VAR}}
-%\newcommand{\COV}{\mathsf{COV}}
-%\newcommand{\Prob}{\mathsf{P}}
-
-\renewcommand{\topfraction}{0.85}
-\renewcommand{\textfraction}{0.1}
-\renewcommand{\baselinestretch}{1.5}
-\setlength{\textwidth}{15cm} \setlength{\textheight}{22cm} \topmargin-1cm \evensidemargin0.5cm \oddsidemargin0.5cm
-
-\usepackage[latin1]{inputenc}
-% or whatever
-
-\usepackage{lmodern}
-\usepackage[T1]{fontenc}
-% Or whatever. Note that the encoding and the font should match. If T1
-% does not look nice, try deleting the line with the fontenc.
-
-\begin{document}
-
-\title{Estimating Volatilities and Correlations}
-\author{Thomas Fillebeen}
-
-\maketitle
-
-\begin{abstract}
-Using historical CRSP data to produce estimates of current and future levels of volatilies and correlations. The vignette explores exponentially weighted moving average (EWMA), and generealized autoregressive conditional heteroscedasticity (GARCH(1,1)). These models recognize that volatilities and correlations are not constant. The models attempt to track variations in volatilities or correlation and forecast them into the future.
-\end{abstract}
-
-\tableofcontents
-
-\section{EWMA Covariance and Correlation}
-\subsection{Selected Returns Time Series}
-<<ex1>>=
-# 'Load the GARPFRM package and CRSP dataset for analysis.
-suppressMessages(library(GARPFRM))
-suppressMessages(library(rugarch))
-suppressMessages(library(rmgarch))
-options(digits=4)
-
-data(crsp.short)
-R <- largecap.ts[, 1:4]
-@
-\subsection{Estimating Correlation and Volatility}
-<<ex2>>=
-# Remember: log-returns for GARCH analysis
-asset1 = R[,1] 
-asset2 = R[,3]
-   
-# Create combined data series
-cAssets = cbind(asset1,asset2)
-
-# Scatterplot of returns
-plot(coredata(asset1), coredata(asset2), xlab=colnames(asset1), 
-     ylab=colnames(asset2), main ="Scatterplot of Returns")
-abline(h=0,v=0,lty=3)
-@
-\subsection{EWMA Correlation and Volatility}
-<<ex3>>=
-# Calculate EWMA cov and cor, applying default lambda - 0.94
-cAssetsEWMACov <- EWMA(cAssets,lambda=0.94, initialWindow=50, cor=FALSE)
-cAssetsEWMACor <- EWMA(cAssets,lambda=0.94, initialWindow=50, cor=TRUE)
-
-# Plots
-par(mfrow=c(2,1))
-plot(cAssetsEWMACov,asset1=1,asset2=2)
-plot(cAssetsEWMACor, asset1=1,asset2=2)
-par(mfrow=c(1,1))
-
-# Compute EWMA cov and cor for longer half-life of 
-halfLife = log(0.5)/log(0.94) + 5
-lambda = exp(log(0.5)/halfLife)
-covEwma <- EWMA(cAssets, lambda)
-@
-
-\section{GARCH(1,1) Conditional Correlation and Variance}
-\subsection{GARCH(1,1) Estimation and Plotting}
-<<ex4>>=
-# Garch11 testing: need 100 plus data points to forecast. 
-# Load lengthier dataset.
-data(returns)
-cAssetsReturns = cbind(returns[, "SPY"],returns[,"AAPL"])
-# Dynamic Conditional Cor/Cov
-garch11 <- garch11(cAssetsReturns)
-
-# garch11 is a dcc.fit object. There are multiple extraction functions to be exploited.
-# Illustrate garch11, dcc.fit object.
-
-# Conditional Sigma (vs Realized Absolute Returns)
-plot(garch11, which=2)
-
-# Conditional covar of each series
-plot(garch11, which=3)
-
-# Conditional cor
-plot(garch11, which=4)
-@
-\subsection{Forecasting GARCH(1,1) Plotting}
-<<ex5>>=
-# Forecasting conditional vol and cor, default wd = 100
-fcstGarch11 = fcstGarch11(garch11,100)
-
-# Many method functions - see help on DCCforecast class
-# rshape, rskew, fitted, sigma, plot, rcor, rcov, show
-
-# Show forecasts
-fcstGarch11
-
-# Plot Conditional Covar Forecast 
-plot(fcstGarch11, which=3)
-@
-
-\end{document}
\ No newline at end of file

Deleted: pkg/GARPFRM/vignettes/Correlation_Volatility_TF.pdf
===================================================================
(Binary files differ)

Deleted: pkg/GARPFRM/vignettes/Correlation_Volatility_TF.tex
===================================================================
--- pkg/GARPFRM/vignettes/Correlation_Volatility_TF.tex	2014-03-22 20:19:01 UTC (rev 123)
+++ pkg/GARPFRM/vignettes/Correlation_Volatility_TF.tex	2014-03-22 20:49:28 UTC (rev 124)
@@ -1,265 +0,0 @@
-\documentclass[a4paper]{article}\usepackage[]{graphicx}\usepackage[]{color}
-%% maxwidth is the original width if it is less than linewidth
-%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
-\makeatletter
-\def\maxwidth{ %
-  \ifdim\Gin at nat@width>\linewidth
-    \linewidth
-  \else
-    \Gin at nat@width
-  \fi
-}
-\makeatother
-
-\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
-\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
-\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
-\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
-\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
-\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
-\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
-\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
-\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
-\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
-
-\usepackage{framed}
-\makeatletter
-\newenvironment{kframe}{%
- \def\at at end@of at kframe{}%
- \ifinner\ifhmode%
-  \def\at at end@of at kframe{\end{minipage}}%
-  \begin{minipage}{\columnwidth}%
- \fi\fi%
- \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
- \colorbox{shadecolor}{##1}\hskip-\fboxsep
-     % There is no \\@totalrightmargin, so:
-     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
- \MakeFramed {\advance\hsize-\width
-   \@totalleftmargin\z@ \linewidth\hsize
-   \@setminipage}}%
- {\par\unskip\endMakeFramed%
- \at at end@of at kframe}
-\makeatother
-
-\definecolor{shadecolor}{rgb}{.97, .97, .97}
-\definecolor{messagecolor}{rgb}{0, 0, 0}
-\definecolor{warningcolor}{rgb}{1, 0, 1}
-\definecolor{errorcolor}{rgb}{1, 0, 0}
-\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
-
-\usepackage{alltt}
-\usepackage[OT1]{fontenc}
-\usepackage{Sweave}
-\usepackage{Rd}
-\usepackage{amsmath}
-\usepackage{hyperref}
-\usepackage{url}
-\usepackage[round]{natbib}
-\usepackage{bm}
-\usepackage{verbatim}
-\usepackage[latin1]{inputenc}
-\bibliographystyle{abbrvnat}
-
-\let\proglang=\textsf
-%\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}}
-%\newcommand{\R}[1]{{\fontseries{b}\selectfont #1}}
-%\newcommand{\email}[1]{\href{mailto:#1}{\normalfont\texttt{#1}}}
-%\newcommand{\E}{\mathsf{E}}
-%\newcommand{\VAR}{\mathsf{VAR}}
-%\newcommand{\COV}{\mathsf{COV}}
-%\newcommand{\Prob}{\mathsf{P}}
-
-\renewcommand{\topfraction}{0.85}
-\renewcommand{\textfraction}{0.1}
-\renewcommand{\baselinestretch}{1.5}
-\setlength{\textwidth}{15cm} \setlength{\textheight}{22cm} \topmargin-1cm \evensidemargin0.5cm \oddsidemargin0.5cm
-
-\usepackage[latin1]{inputenc}
-% or whatever
-
-\usepackage{lmodern}
-\usepackage[T1]{fontenc}
-% Or whatever. Note that the encoding and the font should match. If T1
-% does not look nice, try deleting the line with the fontenc.
-\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
-
-\begin{document}
-
-\title{Estimating Volatilities and Correlations}
-\author{Thomas Fillebeen}
-
-\maketitle
-
-\begin{abstract}
-Using historical CRSP data to produce estimates of current and future levels of volatilies and correlations. The vignette explores exponentially weighted moving average (EWMA), and generealized autoregressive conditional heteroscedasticity (GARCH(1,1)). These models recognize that volatilities and correlations are not constant. The models attempt to track variations in volatilities or correlation and forecast them into the future.
-\end{abstract}
-
-\tableofcontents
-
-\section{EWMA Covariance and Correlation}
-\subsection{Selected Returns Time Series}
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# 'Load the GARPFRM package and CRSP dataset for analysis.}
-\hlkwd{suppressMessages}\hlstd{(}\hlkwd{library}\hlstd{(GARPFRM))}
-\hlkwd{suppressMessages}\hlstd{(}\hlkwd{library}\hlstd{(rugarch))}
-\hlkwd{suppressMessages}\hlstd{(}\hlkwd{library}\hlstd{(rmgarch))}
-\hlkwd{options}\hlstd{(}\hlkwc{digits} \hlstd{=} \hlnum{4}\hlstd{)}
-
-\hlkwd{data}\hlstd{(crsp.short)}
-\hlstd{R} \hlkwb{<-} \hlstd{largecap.ts[,} \hlnum{1}\hlopt{:}\hlnum{4}\hlstd{]}
-\end{alltt}
-\end{kframe}
-\end{knitrout}
-
-\subsection{Estimating Correlation and Volatility}
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# Remember: log-returns for GARCH analysis}
-\hlstd{asset1} \hlkwb{=} \hlstd{R[,} \hlnum{1}\hlstd{]}
-\hlstd{asset2} \hlkwb{=} \hlstd{R[,} \hlnum{3}\hlstd{]}
-
-\hlcom{# Create combined data series}
-\hlstd{cAssets} \hlkwb{=} \hlkwd{cbind}\hlstd{(asset1, asset2)}
-
-\hlcom{# Scatterplot of returns}
-\hlkwd{plot}\hlstd{(}\hlkwd{coredata}\hlstd{(asset1),} \hlkwd{coredata}\hlstd{(asset2),} \hlkwc{xlab} \hlstd{=} \hlkwd{colnames}\hlstd{(asset1),} \hlkwc{ylab} \hlstd{=} \hlkwd{colnames}\hlstd{(asset2),}
-    \hlkwc{main} \hlstd{=} \hlstr{"Scatterplot of Returns"}\hlstd{)}
-\hlkwd{abline}\hlstd{(}\hlkwc{h} \hlstd{=} \hlnum{0}\hlstd{,} \hlkwc{v} \hlstd{=} \hlnum{0}\hlstd{,} \hlkwc{lty} \hlstd{=} \hlnum{3}\hlstd{)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex2} 
-
-\end{knitrout}
-
-\subsection{EWMA Correlation and Volatility}
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# Calculate EWMA cov and cor, applying default lambda - 0.94}
-\hlstd{cAssetsEWMACov} \hlkwb{<-} \hlkwd{EWMA}\hlstd{(cAssets,} \hlkwc{lambda} \hlstd{=} \hlnum{0.94}\hlstd{,} \hlkwc{initialWindow} \hlstd{=} \hlnum{50}\hlstd{,} \hlkwc{cor} \hlstd{=} \hlnum{FALSE}\hlstd{)}
-\hlstd{cAssetsEWMACor} \hlkwb{<-} \hlkwd{EWMA}\hlstd{(cAssets,} \hlkwc{lambda} \hlstd{=} \hlnum{0.94}\hlstd{,} \hlkwc{initialWindow} \hlstd{=} \hlnum{50}\hlstd{,} \hlkwc{cor} \hlstd{=} \hlnum{TRUE}\hlstd{)}
-
-\hlcom{# Plots}
-\hlkwd{par}\hlstd{(}\hlkwc{mfrow} \hlstd{=} \hlkwd{c}\hlstd{(}\hlnum{2}\hlstd{,} \hlnum{1}\hlstd{))}
-\hlkwd{plot}\hlstd{(cAssetsEWMACov,} \hlkwc{asset1} \hlstd{=} \hlnum{1}\hlstd{,} \hlkwc{asset2} \hlstd{=} \hlnum{2}\hlstd{)}
-\hlkwd{plot}\hlstd{(cAssetsEWMACor,} \hlkwc{asset1} \hlstd{=} \hlnum{1}\hlstd{,} \hlkwc{asset2} \hlstd{=} \hlnum{2}\hlstd{)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex3} 
-\begin{kframe}\begin{alltt}
-\hlkwd{par}\hlstd{(}\hlkwc{mfrow} \hlstd{=} \hlkwd{c}\hlstd{(}\hlnum{1}\hlstd{,} \hlnum{1}\hlstd{))}
-
-\hlcom{# Compute EWMA cov and cor for longer half-life of}
-\hlstd{halfLife} \hlkwb{=} \hlkwd{log}\hlstd{(}\hlnum{0.5}\hlstd{)}\hlopt{/}\hlkwd{log}\hlstd{(}\hlnum{0.94}\hlstd{)} \hlopt{+} \hlnum{5}
-\hlstd{lambda} \hlkwb{=} \hlkwd{exp}\hlstd{(}\hlkwd{log}\hlstd{(}\hlnum{0.5}\hlstd{)}\hlopt{/}\hlstd{halfLife)}
-\hlstd{covEwma} \hlkwb{<-} \hlkwd{EWMA}\hlstd{(cAssets, lambda)}
-\end{alltt}
-\end{kframe}
-\end{knitrout}
-
-
-\section{GARCH(1,1) Conditional Correlation and Variance}
-\subsection{GARCH(1,1) Estimation and Plotting}
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# Garch11 testing: need 100 plus data points to forecast.  Load lengthier}
-\hlcom{# dataset.}
-\hlkwd{data}\hlstd{(returns)}
-\hlstd{cAssetsReturns} \hlkwb{=} \hlkwd{cbind}\hlstd{(returns[,} \hlstr{"SPY"}\hlstd{], returns[,} \hlstr{"AAPL"}\hlstd{])}
-\hlcom{# Dynamic Conditional Cor/Cov}
-\hlstd{garch11} \hlkwb{<-} \hlkwd{garch11}\hlstd{(cAssetsReturns)}
-
-\hlcom{# garch11 is a dcc.fit object. There are multiple extraction functions to be}
-\hlcom{# exploited.  Illustrate garch11, dcc.fit object.}
-
-\hlcom{# Conditional Sigma (vs Realized Absolute Returns)}
-\hlkwd{plot}\hlstd{(garch11,} \hlkwc{which} \hlstd{=} \hlnum{2}\hlstd{)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex41} 
-\begin{kframe}\begin{alltt}
-\hlcom{# Conditional covar of each series}
-\hlkwd{plot}\hlstd{(garch11,} \hlkwc{which} \hlstd{=} \hlnum{3}\hlstd{)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex42} 
-\begin{kframe}\begin{alltt}
-\hlcom{# Conditional cor}
-\hlkwd{plot}\hlstd{(garch11,} \hlkwc{which} \hlstd{=} \hlnum{4}\hlstd{)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex43} 
-
-\end{knitrout}
-
-\subsection{Forecasting GARCH(1,1) Plotting}
-\begin{knitrout}
-\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
-\begin{alltt}
-\hlcom{# Forecasting conditional vol and cor, default wd = 100}
-\hlstd{fcstGarch11} \hlkwb{=} \hlkwd{fcstGarch11}\hlstd{(garch11,} \hlnum{100}\hlstd{)}
-
-\hlcom{# Many method functions - see help on DCCforecast class rshape, rskew,}
-\hlcom{# fitted, sigma, plot, rcor, rcov, show}
-
-\hlcom{# Show forecasts}
-\hlstd{fcstGarch11}
-\end{alltt}
-\begin{verbatim}
-## 
-## *---------------------------------*
-## *       DCC GARCH Forecast        *
-## *---------------------------------*
-## 
-## Distribution         :  mvnorm
-## Model                :  DCC(1,1)
-## Horizon              :  100
-## Roll Steps           :  0
-## -----------------------------------
-## 
-## 0-roll forecast: 
-## 
-## First 2 Correlation Forecasts
-## , , 1
-## 
-##        [,1]   [,2]
-## [1,] 1.0000 0.3425
-## [2,] 0.3425 1.0000
-## 
-## , , 2
-## 
-##        [,1]   [,2]
-## [1,] 1.0000 0.3433
-## [2,] 0.3433 1.0000
-## 
-## . .
-## . .
-## 
-## Last 2 Correlation Forecasts
-## , , 1
-## 
-##        [,1]   [,2]
-## [1,] 1.0000 0.4041
-## [2,] 0.4041 1.0000
-## 
-## , , 2
-## 
-##        [,1]   [,2]
-## [1,] 1.0000 0.4046
-## [2,] 0.4046 1.0000
-\end{verbatim}
-\begin{alltt}
-\hlcom{# Plot Conditional Covar Forecast}
-\hlkwd{plot}\hlstd{(fcstGarch11,} \hlkwc{which} \hlstd{=} \hlnum{3}\hlstd{)}
-\end{alltt}
-\end{kframe}
-\includegraphics[width=\maxwidth]{figure/ex5} 
-
-\end{knitrout}
-
-
-\end{document}

Deleted: pkg/GARPFRM/vignettes/EWMA_GARCH11_TF-concordance.tex
===================================================================
--- pkg/GARPFRM/vignettes/EWMA_GARCH11_TF-concordance.tex	2014-03-22 20:19:01 UTC (rev 123)
+++ pkg/GARPFRM/vignettes/EWMA_GARCH11_TF-concordance.tex	2014-03-22 20:49:28 UTC (rev 124)
@@ -1,2 +0,0 @@
-\Sconcordance{concordance:EWMA_GARCH11_TF.tex:EWMA_GARCH11_TF.Rnw:%
-1 8 1 50 0}

Deleted: pkg/GARPFRM/vignettes/EWMA_GARCH11_TF.tex
===================================================================
--- pkg/GARPFRM/vignettes/EWMA_GARCH11_TF.tex	2014-03-22 20:19:01 UTC (rev 123)
+++ pkg/GARPFRM/vignettes/EWMA_GARCH11_TF.tex	2014-03-22 20:49:28 UTC (rev 124)
@@ -1,58 +0,0 @@
-\documentclass{article}\usepackage[]{graphicx}\usepackage[]{color}
-%% maxwidth is the original width if it is less than linewidth
-%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
-\makeatletter
-\def\maxwidth{ %
-  \ifdim\Gin at nat@width>\linewidth
-    \linewidth
-  \else
-    \Gin at nat@width
-  \fi
-}
-\makeatother
-
-\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
-\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
-\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
-\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
-\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
-\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
-\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
-\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
-\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
-\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
-
-\usepackage{framed}
-\makeatletter
-\newenvironment{kframe}{%
- \def\at at end@of at kframe{}%
- \ifinner\ifhmode%
-  \def\at at end@of at kframe{\end{minipage}}%
-  \begin{minipage}{\columnwidth}%
- \fi\fi%
- \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
- \colorbox{shadecolor}{##1}\hskip-\fboxsep
-     % There is no \\@totalrightmargin, so:
-     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
- \MakeFramed {\advance\hsize-\width
-   \@totalleftmargin\z@ \linewidth\hsize
-   \@setminipage}}%
- {\par\unskip\endMakeFramed%
- \at at end@of at kframe}
-\makeatother
-
-\definecolor{shadecolor}{rgb}{.97, .97, .97}
-\definecolor{messagecolor}{rgb}{0, 0, 0}
-\definecolor{warningcolor}{rgb}{1, 0, 1}
-\definecolor{errorcolor}{rgb}{1, 0, 0}
-\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
-
-\usepackage{alltt}
-\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
-
-\begin{document}
-
-
-
-
-\end{document}

Deleted: pkg/GARPFRM/vignettes/RB.pdf
===================================================================
(Binary files differ)

Deleted: pkg/GARPFRM/vignettes/RB.tex
===================================================================
--- pkg/GARPFRM/vignettes/RB.tex	2014-03-22 20:19:01 UTC (rev 123)
+++ pkg/GARPFRM/vignettes/RB.tex	2014-03-22 20:49:28 UTC (rev 124)
@@ -1,1221 +0,0 @@
-\documentclass[a4paper]{article}\usepackage[]{graphicx}\usepackage[]{color}
-%% maxwidth is the original width if it is less than linewidth
-%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
-\makeatletter
-\def\maxwidth{ %
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/uwgarp -r 124


More information about the Uwgarp-commits mailing list