This tutorial on derivatives with R provides a conceptual and practical guide to analyzing derivatives instruments such as Futures Contracts and Options using the R programming language. The tutorial has a well balanced structure between theoretical concepts and practical examples and aims to show important properties of derivatives instruments using R.
The first part of the tutorial describes the fundamental properties of futures contracts. We then perform some data exploration tasks on futures contract prices that explore specific properties of these assets using important R packages such as ggplot, dplyr and the apply family functions from R. The different datasets that are used in this tutorial come from public APIs such as Quandl and CSV files.
Going forward, using the futures contracts data, we provide various examples about how to convert a dataset into tidy data in order to extract meaningful features about datasets, make elegant plots using the ggplot library, build R functions from scratch and use R built-in functions to clean data.
The tutorial tries to demonstrate with examples and visualization tools important properties and concepts of futures contracts such as the Term Structures of future contracts and the high volatility of futures contracts.
In the next section of the tutorial, we provide tools to guide readers in understanding how options instruments are valued using two popular models, namely, the Black Scholes model and the Binomial model. Both models are implemented using R functions to understand from scratch the valuation process and their intermediate steps.
The last section has a description of the Option Greeks and their importance to understand option price movements. Finally, there is a section which uses R language to simulate options strategies such as the Bull Call Spread, Long Straddle, Iron Condor, and Butterfly Spread. To have a better understanding about how these strategies work and the different payoff scenarios of each strategy, they are plotted using ggplot package.
Readers will have the opportunity to observe with real world examples relevant properties of derivatives while learning R programming capabilities to manipulate data and show data insights.