Playback starts YouTube’s embedded player (privacy-enhanced mode).
R Tutorial: Analyzing volatility
ChannelDataCampDescription from the creator
Want to learn more? Take the full course at learn.datacamp.com/courses/garch-models-in-r at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Hi, and welcome to the course on GARCH models in R. On Wallstreet "there are old traders, and bold traders, but there are very few old bold traders". That's because the bold traders suffer large losses when ignoring the risk of their investments.
My name is Kris Boudt. My goal is to give you a hands on experience in using GARCH models in R. I have a PhD on forecasting financial risk and use GARCH models to win by not losing much. My favorite R package is the rugarch package of Alexios Ghalanos which will be the workhorse for the entire course.
To get started, you need returns. Take for example the price of a stock and denote this by capital P. Its daily return equals today's price minus yesterday's price, divided by yesterday's price.
The CalculateReturns function in the package PerformanceAnalytics makes it easy to compute those returns. It takes the price series as an input, and provides you the corresponding returns.
In case of the S&P 500 you can see that the average daily return is close to zero, and that its variability changes over time. There are periods with a low variability, and periods with a high variability. You can quantify this variability by computing the return standard deviation. Investors call this the return volatility and denote it by the greek character sigma with the index t to emphasize that its value changes every day.
You need to take those changes into account, since they heavily influence the probability of losing money. The plot shows this by comparing the return distribution on a turbulent day in blue with the distribution on a calm day in red. On a calm day, there is almost no chance of losing more than 5%, but on a turbulent day it becomes likely to lose more than 5%.
Getting the volatility right is thus of utmost importance. You can estimate the return standard deviation in R by applying the function sd() to the return series. For the daily S&P 500 returns this gives you a daily volatility of around 1%.
The underlying formula is that the standard deviation equals the square root of the average squared deviation of the return from its mean.
Financial traders annualize the daily volatility by multiplying it with the square root of the number of trading days in a year, namely 252. This gives you the standard deviation you can expect on yearly returns. For the S&P 500, you get a 17% annualized volatility.
When you compute this annualized standard deviation on subsamples of one year, you get different numbers through time: they vary between a low of 7% and high of 41%.
In a similar fashion, you can compute volatility on rolling estimation samples. You then roll the sample through time by adding the most recent observation and removing the most distant one.
A practical question is then to choose the length of the estimation window. Typically the window length is a multiple of 22, which is the number of trading days in a month.
In R you can do this rolling calculation with the function chart.RollingPerformance. As arguments, it requires the return series, the size of the window, the estimation function and the number of trading days in a year.
You see here the corresponding rolling volatility estimates. Note the switches between periods of low and high volatility.
This rolling approach is too simple in practice. You will later discover that a higher accuracy is achieved when using a GARCH model.
But first, we refresh the basics of estimating standard deviations in R.
#RTutorial #DataCamp #GARCH
---
Hi, and welcome to the course on GARCH models in R. On Wallstreet "there are old traders, and bold traders, but there are very few old bold traders". That's because the bold traders suffer large losses when ignoring the risk of their investments.
My name is Kris Boudt. My goal is to give you a hands on experience in using GARCH models in R. I have a PhD on forecasting financial risk and use GARCH models to win by not losing much. My favorite R package is the rugarch package of Alexios Ghalanos which will be the workhorse for the entire course.
To get started, you need returns. Take for example the price of a stock and denote this by capital P. Its daily return equals today's price minus yesterday's price, divided by yesterday's price.
The CalculateReturns function in the package PerformanceAnalytics makes it easy to compute those returns. It takes the price series as an input, and provides you the corresponding returns.
In case of the S&P 500 you can see that the average daily return is close to zero, and that its variability changes over time. There are periods with a low variability, and periods with a high variability. You can quantify this variability by computing the return standard deviation. Investors call this the return volatility and denote it by the greek character sigma with the index t to emphasize that its value changes every day.
You need to take those changes into account, since they heavily influence the probability of losing money. The plot shows this by comparing the return distribution on a turbulent day in blue with the distribution on a calm day in red. On a calm day, there is almost no chance of losing more than 5%, but on a turbulent day it becomes likely to lose more than 5%.
Getting the volatility right is thus of utmost importance. You can estimate the return standard deviation in R by applying the function sd() to the return series. For the daily S&P 500 returns this gives you a daily volatility of around 1%.
The underlying formula is that the standard deviation equals the square root of the average squared deviation of the return from its mean.
Financial traders annualize the daily volatility by multiplying it with the square root of the number of trading days in a year, namely 252. This gives you the standard deviation you can expect on yearly returns. For the S&P 500, you get a 17% annualized volatility.
When you compute this annualized standard deviation on subsamples of one year, you get different numbers through time: they vary between a low of 7% and high of 41%.
In a similar fashion, you can compute volatility on rolling estimation samples. You then roll the sample through time by adding the most recent observation and removing the most distant one.
A practical question is then to choose the length of the estimation window. Typically the window length is a multiple of 22, which is the number of trading days in a month.
In R you can do this rolling calculation with the function chart.RollingPerformance. As arguments, it requires the return series, the size of the window, the estimation function and the number of trading days in a year.
You see here the corresponding rolling volatility estimates. Note the switches between periods of low and high volatility.
This rolling approach is too simple in practice. You will later discover that a higher accuracy is achieved when using a GARCH model.
But first, we refresh the basics of estimating standard deviations in R.
#RTutorial #DataCamp #GARCH
About this tutorial
DataCamp published this 4:34 video tutorial on March 29, 2020. It has been watched 6,790 times on YouTube.
- Channel
- DataCamp
- Category
- Science & Technology
- Duration
- 4:34
- Published
- March 29, 2020
- Views
- 6,790
- Likes
- 43
Tags
Share
This tutorial in other languages
- FRR Tutoriel: Analyser la volatilité
- ESR Tutorial: Analizar la volatilidad
- PTR Tutorial: volatilidade Analisando
- ITR Tutorial: Analisi della volatilità
- DER Tutorial: Analyzing Volatilität
- NLR Tutorial: Het analyseren van de volatiliteit
- RUR Учебник: летучесть Анализ
- PLR Przewodnik: zmienność Analiza
- JARチュートリアル:分析のボラティリティ
- ARR البرنامج التعليمي: تقلب تحليل
- HIआर ट्यूटोरियल: आपका विश्लेषण अस्थिरता
- IDR Tutorial: volatilitas Menganalisis