knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The objective of the the vixr package is the replication of the volatility index (VIX) on a daily basis. Thereby, it features four primary functions
The VIX is one of the premier benchmarks for (US) market volatility. Based on the S&P 500 Index, the volatility is estimated by aggregating the weighted prices of S&P 500 calls and puts over a range of strike prices.
In contrast to other indixes, VIX is comprised of options rather than stocks. Thereby, the price of each option is assumed to reflect the expaction of future volatility by market participants.
The VIX is composed of near- and next-term call and put options with more than 23 and less than 37 days to expiration. Thus the user has to define the near and the next term for calculating VIX quotes for a particular day.
The formular for calculating the VIX is given by
$$VIX = 100 \sqrt{\bigg{ T_1 \sigma_1^2\bigg[\frac{N_{T_2}-N_{30} }{N_{T_2}-N_{T_1}}\bigg] + T_2 \sigma_2^2\bigg[\frac{N_{30}-N_{T_1} }{N_{T_2}-N_{T_1}}\bigg] \bigg} \frac{N_{365}}{N_{30}}} $$
With
$$T = {M_{Current-Day} + M_{Settlement-day} + M_{Other-days}} / {\text{Minutes in a year}}$$
With
These calculations have to be done for the near-Term and the next-term options, i.e. you will have $T_1$ and $T_2$.
The forward index level F can be calculated as follows $$F_1 = \text{Strike Price} + e^{RT} (\text{Call Price - Put Price}) $$
$$\ \sigma^2 = \frac{2}{T}\sum_i \frac{\Delta K_i}{K_i^2}e^{RT} Q(K_i) - \frac{1}{T}\bigg[\frac{F}{K_0}-1\bigg]^2\$$
With
This calculation has to be done for the near- and the next term, resulting in $\sigma^2_1$ and $\sigma^2_2$.
For more detailed desciption of the procdure, see the "CBOE White Paper".
The vix_cal() function calculates the VIX quotes. The function takes as an input a data frame featuring option quotes of one particular day with various expiration dates. It requires to set the near- and next term. Furthermore, you can specific the risk free rate for the two time intervals. Compare the function documentation for a detailed list of column naming.
library(vixr) #Package includes a sample dataset data("VIX_SampleData") #calculating the VIX vix = vix_calc(VIX_SampleData,nearT=28,nextT=35, rf_near = 0.002, rf_next = 0.002)
The plotvix() function provides a clean plot of the VIX quotes for the particular day in minutes, using ggplot2. It also allows to include smoother functions
#Ploting VIX quotes plotvix(vix, smoother="loess", type='l')
The fitVIX function applies basic statistical models on the VIX quotes (linear regression ['lm'], loess ['loess'], smoothing spline ['smooth.spline]).
#Fitting a smoothing spline model fitVIX(vix,fit_type = "smooth.spline")
Finally, the package features a shiny app that allows you to interactively visualize the calculated vix quotes. You can include various smoothing functions to the data and features a zooming functionality.
#Starting Shiny app #letVixShiny(vix)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.