Zero to Hero Bootcamp

Workshop on Time Series Econometrics in R

Author

Dr Christian Engels

Last updated

November 22, 2024

Day 2: Advanced Time Series Econometrics in R

Aims

Day 2 of this workshop builds upon the foundational concepts covered in Day 1, delving deeper into advanced topics in time series econometrics using R. The focus will be on modeling volatility processes, fitting GARCH models to financial data, and applying these techniques to real-world financial datasets.

Indicative Topics:

  1. Simulating Volatility Processes
    • Understanding different types of GARCH models.
    • Simulating time series data using specified GARCH models.
    • Visualizing and analyzing simulated volatility processes.
  2. Fitting Volatility Models
    • Downloading and preparing financial time series data.
    • Performing exploratory data analysis (EDA).
    • Fitting various GARCH models to real-world data.
    • Evaluating model diagnostics and selecting appropriate models.
    • Forecasting future volatility and calculating risk measures like VaR and ES.
  3. Application to S&P 500 Stock Portfolio
    • Constructing a minimum variance portfolio.
    • Applying GARCH models to portfolio returns.
    • Performing rolling forecasts and backtesting.
    • Assessing portfolio risk using advanced econometric techniques.

Learning Outcomes

By the end of the second workshop day, participants will be able to:

  • Simulate and analyze various GARCH models to understand volatility dynamics.
  • Fit GARCH models to financial time series data and interpret the results.
  • Use model diagnostics to evaluate and select appropriate volatility models.
  • Forecast future volatility and calculate risk measures such as Value at Risk (VaR) and Expected Shortfall (ES).
  • Apply volatility modeling techniques to construct and analyze stock portfolios.

Where and When?

What to Bring?

  • Your own laptop
  • Installation of R and RStudio
  • Installation of R packages (details below)

Please prepare — all download and installation steps can take 1 hour, or longer! If you already have an installation, please update to the newest version.

To install the necessary packages, run this code in RStudio:

posit_repo <- 
  "https://packagemanager.posit.co/cran/latest"

workshop_packages <- 
  c(
    "tidyverse",
    "tsibble",
    "feasts",
    "fable",
    "tsgarch",
    "tidyfinance",
    "httr2",
    "fixest",
    "flextable",
    "xts",
    "urca",
    "rugarch",
    "PortfolioAnalytics",
    "ggpubr",
    "forecast",
    "tseries",
    "broom",
    "moments"
  )

install.packages(
    workshop_packages, 
    repos = posit_repo
  )

Agenda

Session 1: Simulating Volatility Processes

In this session, we will:

  • Specify Different GARCH Models: Learn how to define various GARCH models such as sGARCH, GJR-GARCH, eGARCH, and apARCH using the rugarch package.
  • Simulate Time Series Data: Use the specified models to simulate time series data and understand the behavior of different volatility processes.
  • Visualize and Analyze Simulated Data: Plot the simulated series and their corresponding volatilities to observe the characteristics and differences among the models.

Key Activities:

  • Specifying GARCH models using ugarchspec.
  • Simulating data with ugarchpath.
  • Visualizing time series and volatility processes using ggplot2 and tsibble.

Session 2: Fitting Volatility Models

In this session, we will:

  • Download and Prepare Financial Data: Acquire S&P 500 index data and calculate daily returns.
  • Perform Exploratory Data Analysis (EDA): Analyze the statistical properties of the returns, including mean, standard deviation, skewness, and kurtosis.
  • Fit GARCH Models to Real Data: Apply different GARCH models to the returns data using ugarchfit.
  • Evaluate Model Diagnostics: Use criteria such as AIC and BIC to select the best-fitting model.
  • Forecast Future Volatility and Risk Measures: Generate volatility forecasts and calculate Value at Risk (VaR) and Expected Shortfall (ES).

Key Activities:

  • Data manipulation and visualization with tidyverse.
  • Model fitting and diagnostics using rugarch.
  • Risk assessment calculations for VaR and ES.

Session 3: Application to S&P 500 Stock Portfolio

In this session, we will:

  • Construct a Minimum Variance Portfolio: Optimize a portfolio of S&P 500 stocks to minimize risk using the PortfolioAnalytics package.
  • Calculate Portfolio Returns: Compute the daily returns of the optimized portfolio.
  • Fit a GARCH Model to Portfolio Returns: Model the volatility of the portfolio returns with a TGARCH model.
  • Perform Rolling Forecasts and Backtesting: Use ugarchroll to evaluate the model’s performance over time and assess its predictive power.
  • Assess Portfolio Risk: Analyze the Value at Risk (VaR) and backtest the model to ensure its adequacy.

Key Activities:

  • Portfolio optimization and risk management.
  • Time series modeling of portfolio returns.
  • Rolling forecasts and backtesting with rugarch.
  • Visualization and interpretation of results.

Day 1: Fundamentals of Time Series Econometrics in R

Aims

Day 1 of this workshop introduces participants to foundational concepts and techniques in time series analysis using R. It focuses on equipping attendees with practical skills for handling, analyzing, and modeling time series data, with applications relevant to finance and economics.

Indicative Topics:

  1. Analysis with Tidyverse
  2. Exploring Time Series Data
  3. Stationarity and Random Walks
  4. ARIMA Modeling
  5. Preview of Volatility Processes

Learning Outcomes

By the end of the first workshop day, participants will be able to:

  • Use Tidyverse tools for data analysis in R.
  • Explore and visualize time series data effectively.
  • Understand and apply concepts of random walks and stationarity.
  • Develop and interpret ARIMA models for forecasting.
  • Gain insight into volatility processes.

Where and When?

What to Bring?

  • Your own laptop
  • Installation of R and RStudio
  • Installation of R packages (details below)

Please prepare — all download and installation steps can take 1 hour, or longer! If you already have an installation, please update to the newest version.

After installing R, run this command:

R.Version()

And verify that your R version is the following:

"R version 4.4.2 (2024-10-31)"
"Pile of Leaves"

In RStudio, verify that this is your version:

Version 2024.09.1+394 (2024.09.1+394)

To install the necessary packages, run this code in RStudio:

posit_repo <- 
  "https://packagemanager.posit.co/cran/latest"

install.packages(
    "renv", 
    repos = posit_repo,
    ask = FALSE,
    dependencies = TRUE
  )

workshop_packages <- 
    c(
      "tidyverse",
      "tsibble",
      "feasts",
      "fable",
      "tsgarch",
      "tidyfinance",
      "httr2",
      "fixest",
      "flextable",
      "xts",
      "urca"
    )

renv::install(
    workshop_packages, 
    repos = posit_repo, 
    dependencies = "all",
    prompt = FALSE
  )

Useful Resources

Questions?

Two options:

  1. Post on this Padlet (password: ts-workshop). This is the preferred option as there will be a lot of participants at the workshop.
  2. Contact me at christian_engels@outlook.com. I may not be able to respond to all requests, but I will try my best!