https://github.com/imanuelcostigan/fmbasics
Financial Market Building Blocks
https://github.com/imanuelcostigan/fmbasics
derivatives finance r
Last synced: 18 days ago
JSON representation
Financial Market Building Blocks
- Host: GitHub
- URL: https://github.com/imanuelcostigan/fmbasics
- Owner: imanuelcostigan
- Created: 2017-01-15T00:48:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-02-01T07:44:45.000Z (about 3 years ago)
- Last Synced: 2024-11-15T11:36:25.541Z (5 months ago)
- Topics: derivatives, finance, r
- Language: R
- Homepage: https://imanuelcostigan.github.io/fmbasics
- Size: 532 KB
- Stars: 12
- Watchers: 3
- Forks: 12
- Open Issues: 7
-
Metadata Files:
- Readme: README.Rmd
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
- awesome-quant - fmbasics - Financial Market Building Blocks. (R / Financial Instruments and Pricing)
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "inst/README-"
)
```# fmbasics - Financial Market Building Blocks
[](https://CRAN.R-project.org/package=fmbasics) [](https://github.com/imanuelcostigan/fmbasics/actions?workflow=R-CMD-check) [](https://codecov.io/github/imanuelcostigan/fmbasics?branch=master)
Implements basic financial market objects like currencies, currency pairs,
interest rates and interest rate indices. You will be able to use Benchmark
instances of these objects which have been defined using their most common
conventions or those defined by International Swap Dealer Association (ISDA,
https://www.isda.org) legal documentation.## Basic objects
You can create instances of key currencies and currency pairs (and of course create your own implementations):
```{r}
library("fmdates")
library("fmbasics")
AUD()
AUDUSD()
```These come with implementations of handy methods:
```{r, message = FALSE}
library("lubridate")
to_fx_value(dates = ymd(20171230), tenor = "spot", x = AUDUSD())
to_fx_value(ymd(20171230), months(3), AUDUSD())
```You can create instances of key IBOR or ONIA interest rate indices:
```{r}
USDLIBOR(months(3))
EONIA()
```These also come with implementations of handy methods:
```{r}
to_reset(dates = as.Date("2017-01-20"), index = USDLIBOR(months(3)))
to_value(as.Date("2017-01-20"), USDLIBOR(months(3)))
to_maturity(as.Date("2017-01-20"), USDLIBOR(months(3)))
```## Interest rates and discount factors
You can create and perform basic manipulation of interest rates and discount factors:
```{r}
rr <- InterestRate(value = 0.01, compounding = Inf, day_basis = "act/365")
as_DiscountFactor(rr, d1 = ymd(20170120), d2 = ymd(20210120))
# Convert to different rate basis
as_InterestRate(rr, day_basis = "act/360")
as_InterestRate(rr, compounding = 2, day_basis = "act/360")
dd <- DiscountFactor(0.75, d1 = ymd(20170120), d2 = ymd(20210120))
as_InterestRate(dd, compounding = Inf, day_basis = "act/360")
```## Pricing objects
It is also possible to create and interpolate on zero coupon interest rate curves:
```{r}
zc <- build_zero_curve()
plot(zc$pillar_times, zc$pillar_zeros, xlab = 'Years', ylab = 'Zero')
interpolate(zc, year_frac(zc$reference_date, ymd(20170331), "act/365"))
interpolate_zeros(zc, ymd(20170331))
interpolate_fwds(zc, ymd(20170331), ymd(20170630))
interpolate_dfs(zc, ymd(20170331), ymd(20170630))
```Basic support for creating and interpolating volatility surfaces is possible:
```{r}
# vs <- build_vol_surface()
# at <- tibble::tibble(
# maturity = as.Date(c("2020-03-31", "2021-03-31")),
# smile = c(0.40, 0.80)
# )
# interpolate(vs, at)
```Further details can be found in this package's help pages and vignettes (`vignette(package = "fmbasics")`)