-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathREADME.Rmd
145 lines (109 loc) · 4.46 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
output:
md_document:
variant: markdown_github
---
```{r global_options, include=FALSE}
library(ragtop)
library(futile.logger)
library(ggplot2)
flog.threshold(ERROR)
flog.threshold(ERROR, name='ragtop.implicit.timestep.construct_tridiagonals')
flog.threshold(ERROR, name='ragtop.calibration.implied_volatility.lowprice')
flog.threshold(ERROR, name='ragtop.calibration.implied_volatility_with_term_struct')
flog.threshold(ERROR, name='ragtop.implicit.setup.width')
knitr::opts_chunk$set(fig.width=6.5, fig.height=4, fig.path='Figs/',
echo=FALSE, warning=FALSE, message=FALSE, comment=FALSE)
```
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# Description And Installation
**ragtop** prices equity derivatives using variants of the famous Black-Scholes model, with special attention paid to the case of American and European exercise options and to convertible bonds. To install the development version, use the command
```{r, echo=TRUE}
devtools::install_github('brianboonstra/ragtop')
```
# Usage
## Basic Usage
You can price american and european exercise options, either individually, or in groups. In the simplest case that looks like this for European exercise
```{r bs, echo=TRUE}
blackscholes(c(CALL, PUT), S0=100, K=c(100,110), time=0.77, r = 0.06, vola=0.20)
```
and like this for American exercise
```{r bsa, echo=TRUE}
american(PUT, S0=100, K=c(100,110), time=0.77, const_short_rate = 0.06, const_volatility=0.20)
```
### Including Term Structures
There are zillions of implementations of the Black-Scholes formula out there, and quite a few simple trees as well. One thing that makes **ragtop** a bit more useful than most other packages is that it treats dividends and term structures without too much pain. Assume we have some nontrivial term structures and dividends
```{r ts_fcns, echo=TRUE, comment=""}
## Dividends
divs = data.frame(time=seq(from=0.11, to=2, by=0.25),
fixed=seq(1.5, 1, length.out=8),
proportional = seq(1, 1.5, length.out=8))
## Interest rates
disct_fcn = ragtop::spot_to_df_fcn(data.frame(time=c(1, 5, 10),
rate=c(0.01, 0.02, 0.035)))
## Default intensity
disc_factor_fcn = function(T, t, ...) {
exp(-0.03 * (T - t)) }
surv_prob_fcn = function(T, t, ...) {
exp(-0.07 * (T - t)) }
## Variance cumulation / volatility term structure
vc = variance_cumulation_from_vols(
data.frame(time=c(0.1,2,3),
volatility=c(0.2,0.5,1.2)))
paste0("Cumulated variance to 18 months is ", vc(1.5, 0))
```
then we can price vanilla options
```{r blackscholes_ts, comment="", echo=TRUE}
black_scholes_on_term_structures(
callput=TSLAMarket$options[500,'callput'],
S0=TSLAMarket$S0,
K=TSLAMarket$options[500,'K'],
discount_factor_fcn=disct_fcn,
time=TSLAMarket$options[500,'time'],
variance_cumulation_fcn=vc,
dividends=divs)
```
American exercise options
```{r amer_ts, echo=TRUE, comment=""}
american(
callput = TSLAMarket$options[400,'callput'],
S0 = TSLAMarket$S0,
K=TSLAMarket$options[400,'K'],
discount_factor_fcn=disct_fcn,
time = TSLAMarket$options[400,'time'],
survival_probability_fcn=surv_prob_fcn,
variance_cumulation_fcn=vc,
dividends=divs)
```
We can also find volatilities of European exercise options
```{r implied_bs_volatility_def_ts, comment="", echo =T}
implied_volatility_with_term_struct(
option_price=19, callput = PUT,
S0 = 185.17,K=182.50,
discount_factor_fcn=disct_fcn,
time = 1.12,
survival_probability_fcn=surv_prob_fcn,
dividends=divs)
```
as well as American exercise options
```{r amer_ts_iv, echo=TRUE, comment=""}
american_implied_volatility(
option_price=19, callput = PUT,
S0 = 185.17,K=182.50,
discount_factor_fcn=disct_fcn,
time = 1.12,
survival_probability_fcn=surv_prob_fcn,
dividends=divs)
```
## More Sophisticated Calibration
You can also find more complete calibration routines in **ragtop**. See the vignette or the documentation for *fit_variance_cumulation* and *fit_to_option_market*.
# Technical Documentation
The source for the technical paper is in this repository. You can also find the pdf [here](http://thureoscapital.com/ragtop.pdf)
[](https://travis-ci.org/brianboonstra/ragtop)