-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathREADME.Rmd
165 lines (130 loc) · 6.67 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
output:
md_document:
variant: markdown_github
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
ustreasuries [![DOI](https://zenodo.org/badge/5738/grfiv/ustreasuries.svg)](https://zenodo.org/badge/latestdoi/5738/grfiv/ustreasuries)
===============
### US Treasury Bond Data
* Real-Time downloads of
* daily Constant-Maturity Treasury (CMT) yields from 1962 to the most-recently completed business day
* daily prices for 400 Treasury securities (FedInvest) from 2010 to the most-recently completed business day
### Bond Analysis
Several models such as Nelson Seigel and Svensson are provided
**Veronesi** <sup>[Veronesi](#Veronesi)</sup> examples derived with code and live bond data
### Derivative Analysis
Drawing primarily on **Hull, 7th edition** <sup>[Hull](#Hull)</sup> *ustreasuries* includes many options-pricing models, all the Greeks and a number of utility functions, all of which have examples from Hull which demonstrate that they work correctly.
--------------------------------------------------------------------------------
### Wiki
See the [GitHub Wiki](https://github.com/grfiv/ustreasuries/wiki) for examples of the use of all the functions.
### Functions
* **Treasury Rate Data**
* **CMTrates** downloads real-time daily CMT data from 1962
* **PrintYieldCurves** prints one or more CMT yield curves
* **APY** converts Constant-Maturity Treasury (CMT) yields to Annualized
Percentage Yields (APY)
* **FedInvestData** downloads real-time treasury bond price data from 2010
* **CoerceFedInvest_xts** Turn FedInvest data into a time series
* **Black-Scholes-Merton**
* **EuroCall** Calculate the price of a European call option with or without dividends
* **EuroPut** Calculate the price of a European put option with or without dividends
* **EuroCallVol** Implied Volatility for a European Call option
* **EuroPutlVol** Implied Volatility for a European Put option
* **Greeks**
* **DeltaCall** Amount call-option price changes given a change in asset price
* **DeltaPut** Amount put-option price changes given a change in asset price
* **ThetaCall** the decay in the value of a call or a portfolio of calls as time passes
* **ThetaPut** the decay in the value of a put or a portfolio of puts as time passes
* **Gamma** the change in Delta with respect to asset price
* **Vega** the sensitivity to changes in the volatility of the underlying
* **RhoCall** the sensitivity to changes in the risk-free rate of return
* **RhoPut** the sensitivity to changes in the risk-free rate of return
* **Utility Functions**
* **Bonds**
* **NSzeros** Convert Nelson Seigel and Svensson rates to Z(0, T)
* **Zbootstrap** Derive Z(0, T_i) using the bootstrap method
* **spot_rate** Derive spot rate from Z(0, T) and T
* **CAGR**
* **CAGR** Calculate Compound Annual Growth Rate; geometric or continuous
* **r_continuous** Convert from discrete to continuous
* **r_discrete** Convert from continuous to discrete
* **Discount Factors**
* **discount_factor** Calculate discount factor Z(t, T)
* **interest_rate** Calculate annualized interest rate r(t, T) from a discount factor Z(t, T)
* **Put/Call Parity**
* **CallParity** Convert from a put-option price using put/call parity
* **PutParity** Convert from a call-option price using put/call parity
* **Risk Neutral/Forwards**
* **RiskNeutralProb** Binomial tree risk-neutral probability
* **ForwardPrice** Forward price with or without income or yield
* **ForwardRate** Forward rate from Time1 to Time2 (discrete compounding)
* **Options**
* **IntrinsicValueCall** / **IntrinsicValuePut** the in-the-money portion of an option's premium
* **TimeValueCall** / **TimeValuePut** Price = Intrinsic + Time
* **InTheMoneyCall** / **InTheMoneyPut** Is an option in the money?
* **Equities**
* **SP500** Daily S&P 500 data from 1950
* **SP500TR** Daily S&P 500 Total Return data from 1988
* **Installed but not yet tested or documented**
* Digital
* **CashCall**
* **CashPut**
* **AssetCall**
* **AssetPut**
* Greeks
* **RhoFuturesCall**
* **RhoFuturesPut**
* **RhoFXCall**
* **RhoFXPut**
* American
* **American_Put_Binomial**
* **American_Call_Dividend**
#### All of the derivatives functions have examples drawn from **Hull, 7th edition** <sup>[Hull](#Hull)</sup> to demonstrate their correctness.
See https://github.com/grfiv/BlackScholesMerton for these functions written in Python and Excel VBA
See also http://www.philadelphia-reflections.com/topic/230.htm
## Installation
We're not on CRAN yet; get the development version from GitHub:
```R
# see https://github.com/hadley/devtools for the
# best procedure to install *devtools* on your
# system; Windows in particular has somewhat
# complicated requirements
devtools::install_github("grfiv/treasuries")
# Notes:
# 1. Add 'build_vignettes=TRUE' to include vignettes
# (recommended, but a current version of pandoc is required)
# 2. add 'auth_token="..."' if you get a 404
# contact the author for this
# 3. if you receive a message about corrupt databases or fetch(key),
# restarting R will fix the problem;
# these appear to be issues with devtools 1.10.0.9000
```
## References
<a name="Back">[Back]</a>:
Back, K., *A Course in Derivative Securities* 2005 Springer Finance ISBN 9783540253734
<a name="Consiglio">[Consiglio]</a>:
Consiglio A. and Guirreri S.S. *Simulating the Term Structure of Interest Rates with
arbitrary marginals*. International Journal of Risk Assessment and Management, 15(4),
September 2011.
<a name="Hull">[Hull]</a>:
Hull, J., *Options, Futures and Other Derivatives Seventh Edition* 2008 Pearson/Prentice Hall ISBN 9780136015864
<a name="CMT">[CMT]</a>:
US Dept. of Treasury Daily Treasury Yield Curve Rates
https://www.treasury.gov/resource-center/data-chart-center/interest-rates/Pages/TextView.aspx?data=yield
<a name="H15">[H15]</a>:
US Federal Reserve Board Data Download Program
http://www.federalreserve.gov/datadownload/Choose.aspx?rel=H15
<a name="Varma">[Varma]</a>:
Varma, J. *jrvFinance* v1.03 (https://github.com/jrvarma/jrvFinance)
<a name="Veronesi">[Veronesi]</a>:
Veronesi P., *Fixed Income Securities* 2010 John Wiley & Sons ISBN 9780470109106
<a name="MDC">[MDC]</a>:
Wall Street Journal Market Data Center
http://online.wsj.com/mdc/public/page/mdc_bonds.html?mod=mdc_topnav_2_3010