<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/volatility-modelling-in-r-exercises-part-1/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/06/26/volatility-modelling-in-r-exercises-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=volatility-modelling-in-r-exercises-part-1"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/06/Rplotex7_5.jpeg" target="_blank"><img alt="" src="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/06/Rplotex7_5.jpeg?resize=150%2C150" class="wp-image-5754" data-recalc-dims="1"></a></p>
<p>Volatility modelling is typically used for high frequency financial data. Asset returns are typically uncorrelated while the variation of asset prices (volatility) tends to be correlated across time.<br>
In this exercise set we will use the <code>rugarch</code> package (package description: <a rel="nofollow" href="https://cran.r-project.org/web/packages/rugarch/rugarch.pdf" target="_blank">here</a>) to implement the ARCH (Autoregressive Conditional Heteroskedasticity) model in R.</p>
<p>Answers to the exercises are available <a rel="nofollow" href="http://r-exercises.com/2017/06/26/volatility-modelling-in-r-part-1-solutions/" target="_blank">here</a>.</p>
<p><strong>Exercise 1</strong><br>
Load the <code>rugarch</code> package and the <code>dmbp</code> dataset (Bollerslev, T. and Ghysels, E. 1996, Periodic Autoregressive Conditional Heteroscedasticity, Journal<br>
of Business and Economic Statistics, 14, 139–151). This dataset has daily logarithmic nominal returns for Deutsche-mark / Pound. There is also a dummy variable to indicate non-trading days.</p>
<p><strong>Exercise 2</strong><br>
Define the daily return as a time series variable and plot the return against time. Notice the unpredictability apparent from the graph.</p>
<p><strong>Exercise 3</strong><br>
Plot the graph of the autocorrelation function of returns. Notice that there is hardly any evidence of autocorrelation of returns.</p>
<p><strong>Exercise 4</strong><br>
Plot the graph of the autocorrelation function of squared returns. Notice the apparent strong serial correlation.</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/06/26/volatility-modelling-in-r-exercises-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=volatility-modelling-in-r-exercises-part-1"></aside>
<div><strong>Learn more</strong> about Model Evaluation in the online course <a rel="nofollow" href="http://www.r-exercises.com/product/regression-machine-learning-with-r/" target="_blank">Regression Machine Learning with R</a>. In this course you will learn how to:
<ul>
<li>Avoid model over-fitting using cross-validation for optimal parameter selection</li>
<li>Explore maximum margin methods such as best penalty of error term support vector machines with linear and non-linear kernels.</li>
<li>And much more</li>
</ul>
</div>
</div>
<p><strong>Exercise 5</strong><br>
We will first simulate and analyze an ARCH process. Use the <code>ugarchspec</code> function to define an ARCH(1) process. The return has a simple mean specification with mean=0. The variance follows as AR-1 process with constant=0.2 and AR-1 coefficient = 0.7.</p>
<p><strong>Exercise 6</strong><br>
Simulate the ARCH process for 500 time periods. Exercises 7 to 9 use this simulated data.</p>
<p><strong>Exercise 7</strong><br>
Plot the returns vs time and note the apparent unpredictability. Plot the path of conditional sigma vs time and note that there is some persistence over time.</p>
<p><strong>Exercise 8</strong><br>
Plot the ACF of returns and squared returns. Note that there is no auto-correlation between returns but squared returns have significant first degree autocorrelation as we defined in exercise-5.</p>
<p><strong>Exercise 9</strong><br>
Test for ARCH effects using the Ljung Box test for the simulated data.</p>
<p><strong>Exercise 10</strong><br>
Test for ARCH effects using the Ljung Box test for the currency returns data.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/05/01/forecasting-multivariate-regression-exercises-part-4/" title="Forecasting: Multivariate Regression Exercises (Part-4)" target="_blank">Forecasting: Multivariate Regression Exercises (Part-4) </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/05/17/introduction-to-copulas-exercises-part-2/" title="Introduction to copulas Exercises (Part-2)" target="_blank">Introduction to copulas Exercises (Part-2) </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2016/01/26/conditional-execution-exercises/" title="Conditional execution exercises" target="_blank">Conditional execution exercises </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/" target="_blank">Explore all our (>1000) R exercises</a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/r-courses/" target="_blank">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.r-exercises.com/2017/06/26/volatility-modelling-in-r-exercises-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=volatility-modelling-in-r-exercises-part-1"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/afGXKi_3i94" height="1"></a></div>