Title: | Financial Market Building Blocks |
---|---|
Description: | 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. |
Authors: | Imanuel Costigan [aut, cre], Sayf Hamada [ctb] |
Maintainer: | Imanuel Costigan <[email protected]> |
License: | GPL-2 |
Version: | 0.3.99 |
Built: | 2024-06-19 04:02:30 UTC |
Source: | https://github.com/imanuelcostigan/fmbasics |
You can coerce objects to the DiscountFactor
class using this method.
as_DiscountFactor(x, ...) ## S3 method for class 'InterestRate' as_DiscountFactor(x, d1, d2, ...)
as_DiscountFactor(x, ...) ## S3 method for class 'InterestRate' as_DiscountFactor(x, d1, d2, ...)
x |
object to coerce |
... |
other parameters passed to methods |
d1 |
a |
d2 |
a |
a DiscountFactor
object
library("lubridate") as_DiscountFactor(InterestRate(c(0.04, 0.05), c(2, 4), 'act/365'), ymd(20140101), ymd(20150101))
library("lubridate") as_DiscountFactor(InterestRate(c(0.04, 0.05), c(2, 4), 'act/365'), ymd(20140101), ymd(20150101))
You can coerce objects to the InterestRate
class using this method.
as_InterestRate(x, ...) ## S3 method for class 'DiscountFactor' as_InterestRate(x, compounding, day_basis, ...) ## S3 method for class 'InterestRate' as_InterestRate(x, compounding = NULL, day_basis = NULL, ...)
as_InterestRate(x, ...) ## S3 method for class 'DiscountFactor' as_InterestRate(x, compounding, day_basis, ...) ## S3 method for class 'InterestRate' as_InterestRate(x, compounding = NULL, day_basis = NULL, ...)
x |
object to coerce |
... |
other parameters passed to methods |
compounding |
a numeric vector representing the compounding frequency. |
day_basis |
a character vector representing the day basis associated
with the interest rate (see |
an InterestRate
object
library("lubridate") as_InterestRate(DiscountFactor(0.95, ymd(20130101), ymd(20140101)), compounding = 2, day_basis = "act/365") as_InterestRate(InterestRate(c(0.04, 0.05), c(2, 4), 'act/365'), compounding = 4, day_basis = 'act/365')
library("lubridate") as_InterestRate(DiscountFactor(0.95, ymd(20130101), ymd(20140101)), compounding = 2, day_basis = "act/365") as_InterestRate(InterestRate(c(0.04, 0.05), c(2, 4), 'act/365'), compounding = 4, day_basis = 'act/365')
You can coerce objects to the SurvivalProbabilities
class using this method.
as_SurvivalProbabilities(x, ...) ## S3 method for class 'ZeroHazardRate' as_SurvivalProbabilities(x, d1, d2, ...)
as_SurvivalProbabilities(x, ...) ## S3 method for class 'ZeroHazardRate' as_SurvivalProbabilities(x, d1, d2, ...)
x |
object to coerce |
... |
other parameters passed to methods |
d1 |
a |
d2 |
a |
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) HR <- ZeroHazardRate(values = c(0.04, 0.05), compounding = c(2, 4), day_basis = 'act/365', specs = curve_specs) as_SurvivalProbabilities(HR, lubridate::ymd(20160202), lubridate::ymd(20160302))
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) HR <- ZeroHazardRate(values = c(0.04, 0.05), compounding = c(2, 4), day_basis = 'act/365', specs = curve_specs) as_SurvivalProbabilities(HR, lubridate::ymd(20160202), lubridate::ymd(20160302))
Bootstraps Survival Probabilitie from a CDS curve Using credule package. The output of bootstrapping is a vector of cumulative survival probabilities.
## S3 method for class 'CDSCurve' as_SurvivalProbabilities(x, zero_curve, num_timesteps_pa = 12, accrued_premium = TRUE, ...)
## S3 method for class 'CDSCurve' as_SurvivalProbabilities(x, zero_curve, num_timesteps_pa = 12, accrued_premium = TRUE, ...)
x |
An object of type |
zero_curve |
An object of type |
num_timesteps_pa |
It represents the number of timesteps used to perform the numerical integral required while computing the default leg value. It is shown that a monthly discretisation usually gives a good approximation (Ref. Valuation of Credit Default Swaps, Dominic O Kane and Stuart Turnbull) |
accrued_premium |
If set to TRUE, the accrued premium will be taken into account in the calculation of the premium leg value. |
... |
other parameters passed to methods |
An object of type SurvivalProbabilitiesCurve
an SurvivalProbabilities
object
Create a tibble
that contains the pillar point maturities in years (using
the act/365
convention) and the corresponding continuously compounded zero
rates.
## S3 method for class 'CreditCurve' as_tibble(x, ...)
## S3 method for class 'CreditCurve' as_tibble(x, ...)
x |
a |
... |
other parameters that are not used by this methods |
a tibble
with two columns named Years
and Zero Hazard Rates
.
Create a tibble
that contains the pillar point maturities in years (using
the act/365
convention) and the corresponding continuously compounded zero
rates.
## S3 method for class 'ZeroCurve' as_tibble(x, ...)
## S3 method for class 'ZeroCurve' as_tibble(x, ...)
x |
a |
... |
other parameters that are not used by this methods |
a tibble
with two columns named Years
and Zeros
.
library(tibble) zc <- build_zero_curve() as_tibble(zc)
library(tibble) zc <- build_zero_curve() as_tibble(zc)
You can coerce objects to the ZeroHazardRate
class using this method.
as_ZeroHazardRate(x, ...) ## S3 method for class 'SurvivalProbabilities' as_ZeroHazardRate(x, compounding, day_basis, ...) ## S3 method for class 'ZeroHazardRate' as_ZeroHazardRate(x, compounding = NULL, day_basis = NULL, ...)
as_ZeroHazardRate(x, ...) ## S3 method for class 'SurvivalProbabilities' as_ZeroHazardRate(x, compounding, day_basis, ...) ## S3 method for class 'ZeroHazardRate' as_ZeroHazardRate(x, compounding = NULL, day_basis = NULL, ...)
x |
object to coerce |
... |
other parameters passed to methods |
compounding |
a numeric vector representing the compounding frequency. |
day_basis |
a character vector representing the day basis associated
with the interest rate and hazard rate(see |
an ZeroHazardRate
object
library("lubridate") as_ZeroHazardRate(SurvivalProbabilities(0.95, ymd(20130101), ymd(20140101), CDSSpec("Empty")), compounding = 2, day_basis = "act/365")
library("lubridate") as_ZeroHazardRate(SurvivalProbabilities(0.95, ymd(20130101), ymd(20140101), CDSSpec("Empty")), compounding = 2, day_basis = "act/365")
VolQuotes
object from an example data setThis creates an object of class VolQuotes
from the example data set
volsurface.csv
.
build_vol_quotes()
build_vol_quotes()
a VolQuotes
object from package built-in data
Other build vol object helpers: build_vol_surface
build_vol_quotes()
build_vol_quotes()
VolSurface
from an example date setThis creates a VolSurface
object from the example data set
volsurface.csv
.
build_vol_surface()
build_vol_surface()
a VolSurface
object using data from volsurface.csv
Other build vol object helpers: build_vol_quotes
build_vol_surface()
build_vol_surface()
ZeroCurve
from example data setThis creates a ZeroCurve
object from the example data set
zerocurve.csv
.
build_zero_curve(interpolation = NULL)
build_zero_curve(interpolation = NULL)
interpolation |
an |
a ZeroCurve
object using data from zerocurve.csv
build_zero_curve(LogDFInterpolation())
build_zero_curve(LogDFInterpolation())
This allows you to create a CashFlow
object.
CashFlow(dates, monies)
CashFlow(dates, monies)
dates |
a Date vector with either the same length as |
monies |
a MultiCurrencyMoney object |
a CashFlow
object that extends tibble::tibble()
Other money functions: MultiCurrencyMoney
,
SingleCurrencyMoney
,
is.CashFlow
,
is.MultiCurrencyMoney
,
is.SingleCurrencyMoney
CashFlow(as.Date("2017-11-15"), MultiCurrencyMoney(list(SingleCurrencyMoney(1, AUD()))) )
CashFlow(as.Date("2017-11-15"), MultiCurrencyMoney(list(SingleCurrencyMoney(1, AUD()))) )
This can be used to represent ONIA like indices (e.g. AONIA, FedFunds)
and extends the InterestRateIndex
class.
CashIndex(name, currency, spot_lag, calendar, day_basis, day_convention)
CashIndex(name, currency, spot_lag, calendar, day_basis, day_convention)
name |
the name of the index as a string |
currency |
the currency associated with the index as a Currency object |
spot_lag |
the period between the index's fixing and the start of the index's term |
calendar |
the calendar used to determine whether the index fixes on a given date as a Calendar |
day_basis |
the day basis associated with the index (e.g. "act/365") |
day_convention |
the day convention associated with the index (e.g. "mf") |
an object of class CashIndex
that inherits from Index
library(lubridate) library(fmdates) # RBA cash overnight rate CashIndex("AONIA", AUD(), days(0), c(AUSYCalendar()), "act/365", "f")
library(lubridate) library(fmdates) # RBA cash overnight rate CashIndex("AONIA", AUD(), days(0), c(AUSYCalendar()), "act/365", "f")
CDSCurve
This will allow you to create an instance of a CDS curve.
CDSCurve(reference_date, tenors, spreads, lgd, premium_frequency, specs)
CDSCurve(reference_date, tenors, spreads, lgd, premium_frequency, specs)
reference_date |
the curve's reference date as a base::Date |
tenors |
a numeric vector of pillar points time steps expressed in years |
spreads |
a numeric vector of creadit default spreads expressed in
decimals. Must be the same length as |
lgd |
the loss given default associated with the curve as supplied by Markit and expressed as a decimal value |
premium_frequency |
represents the number of premiums payments per annum expressed as an integer. Must be one of 1, 2, 4 or 12. |
specs |
CDS curve specifications that inherits from |
An object of type CDSCurve
Other CDS curve helpers: CDSMarkitSpec
,
CDSSingleNameSpec
, CDSSpec
,
SurvivalProbabilities
,
ZeroHazardRate
, is.CDSCurve
,
is.CDSSpec
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) CDSCurve( as.Date("2019-06-29"), tenors = c(1, 3, 5, 7), spreads = c(0.0050, 0.0070, 0.0090, 0.0110), lgd = 0.6, premium_frequency = 4, specs = curve_specs )
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) CDSCurve( as.Date("2019-06-29"), tenors = c(1, 3, 5, 7), spreads = c(0.0050, 0.0070, 0.0090, 0.0110), lgd = 0.6, premium_frequency = 4, specs = curve_specs )
CDSMarkitSpec
A subclass of CDSSpec()
, only for Markit sector curves. Note that the
paramter rank
is fixed to be "SNR", as per Markit's methodology documents
CDSMarkitSpec(rating, region, sector)
CDSMarkitSpec(rating, region, sector)
rating |
valid options are "AAA", "AA", "A", "BBB", "BB", "B", "CCC" |
region |
valid options are "AsiaExJapan", "EastEurope", "Europe", "Japan", "LatinAmerica", "NorthAmerica", "MiddleEast", "Oceania" |
sector |
valid options are "BasicMaterials", "ConsumerGoods", "ConsumerServices", "Energy", "Financials", "Government", "Healtcare", "Technology", "TeleCom", "Utilities" |
An object of type CDSMarkitSpec
Other CDS curve helpers: CDSCurve
,
CDSSingleNameSpec
, CDSSpec
,
SurvivalProbabilities
,
ZeroHazardRate
, is.CDSCurve
,
is.CDSSpec
CDSMarkitSpec(rating = "AAA", region = "Japan", sector = "Utilities")
CDSMarkitSpec(rating = "AAA", region = "Japan", sector = "Utilities")
CDSSingleNameSpec
A subclass of CDSSpec()
, that implements specifications for single name
CDS curves
CDSSingleNameSpec(rank, name)
CDSSingleNameSpec(rank, name)
rank |
Seniority of the reference debt. Must be one of the following options: "SNR" for Senior, "SubTier3" for Subordinate Tier 3, "SubUpperTier2" for Subordinate Upper Tier 2, "SubLowerTier2" for Subordinate Lower Tier 2 "SubTier1" for Subordinate Tier 1. "Empty" rank can be used for a generic instance of the class. |
name |
Reference debt issuer. Must be a string. |
An object of type CDSSingleNameSpec
Other CDS curve helpers: CDSCurve
,
CDSMarkitSpec
, CDSSpec
,
SurvivalProbabilities
,
ZeroHazardRate
, is.CDSCurve
,
is.CDSSpec
CDSSingleNameSpec(rank = "SNR", name = "Westpac")
CDSSingleNameSpec(rank = "SNR", name = "Westpac")
CDSSpec
This class will enable you to specify CDS curves. It is used by
SurvivalProbabilities()
and ZeroHazardRate()
.
CDSSpec(rank, ..., subclass = NULL)
CDSSpec(rank, ..., subclass = NULL)
rank |
Seniority of the reference debt. Must be one of the following options: "SNR" for Senior, "SubTier3" for Subordinate Tier 3, "SubUpperTier2" for Subordinate Upper Tier 2, "SubLowerTier2" for Subordinate Lower Tier 2 "SubTier1" for Subordinate Tier 1. "Empty" rank can be used for a generic instance of the class. |
... |
parameters passed to other |
subclass |
the name of a |
Object of type CDSSpec
Other CDS curve helpers: CDSCurve
,
CDSMarkitSpec
,
CDSSingleNameSpec
,
SurvivalProbabilities
,
ZeroHazardRate
, is.CDSCurve
,
is.CDSSpec
CDSSpec(rank = "SubTier3")
CDSSpec(rank = "SubTier3")
A class that defines the bare bones of a credit curve pricing structure.
CreditCurve(survival_probabilities, reference_date, interpolation, specs)
CreditCurve(survival_probabilities, reference_date, interpolation, specs)
survival_probabilities |
a |
reference_date |
a |
interpolation |
an |
specs |
CDS curve specifications that inherits from |
A term structure of credit spread is a curve showing several credit spreads across different contract lengths (2 month, 2 year, 20 year, etc...) for a similar debt contract. The curve shows the relation between the (level of) crdit spread and the time to maturity, known as the "term", of the debt for a given borrower in a given currency. When the effect of coupons on spreads are stripped away, one has a zero-coupon credit curve.
The following interpolation schemes are supported by ZeroCurve
:
ConstantInterpolation
, LinearInterpolation
, LogDFInterpolation
and
CubicInterpolation
. Points outside the calibration region use constant
extrapolation on the zero hazard rate.
a CreditCurve
object
curve_specs <- CDSMarkitSpec(rating = "AAA", region = "Japan", sector = "Utilities")
zero_curve <- build_zero_curve()
ref_date <- zero_curve$reference_date
specs <- CDSMarkitSpec(rating = "AAA", region = "Japan", sector = "Utilities")
cds_curve <- CDSCurve(reference_date = ref_date, tenors = c(1, 3, 5, 7),
spreads = c(0.0050, 0.0070, 0.0090, 0.0110), lgd = .6, premium_frequency = 4,
specs = curve_specs)
sp <- as_SurvivalProbabilities(x = cds_curve, zero_curve = zero_curve)
CreditCurve(survival_probabilities = sp, reference_date =ref_date,
interpolation = CubicInterpolation(), specs = curve_specs)
A currency refers to money in any form when in actual use or circulation, as a medium of exchange, especially circulating paper money. This package includes handy constructors for common currencies.
Currency(iso, calendar)
Currency(iso, calendar)
iso |
a three letter code representing the currency (see ISO 4217) |
calendar |
an object of class Currency
Currency. (2014, March 3). In Wikipedia
library("fmdates") Currency("AUD", c(AUSYCalendar()))
library("fmdates") Currency("AUD", c(AUSYCalendar()))
These constructors use the following conventions:
AUD() EUR() GBP() JPY() NZD() USD() CHF() HKD() NOK()
AUD() EUR() GBP() JPY() NZD() USD() CHF() HKD() NOK()
Creator | Joint calendars |
AUD() |
AUSYCalendar |
EUR() |
EUTACalendar |
GBP() |
GBLOCalendar |
JPY() |
JPTOCalendar |
NZD() |
NZAUCalendar , NZWECalendar |
USD() |
USNYCalendar |
CHF() |
CHZHCalendar |
HKD() |
HKHKCalendar |
NOK() |
NOOSCalendar
|
Other constructors: CurrencyPairConstructors
,
iborindices
, oniaindices
AUD()
AUD()
Create an object of class CurrencyPair
CurrencyPair(base_ccy, quote_ccy, calendar = NULL)
CurrencyPair(base_ccy, quote_ccy, calendar = NULL)
base_ccy |
a Currency object |
quote_ccy |
a Currency object |
calendar |
a JointCalendar object. Defaults to
|
a CurrencyPair
object
CurrencyPair(AUD(), USD())
CurrencyPair(AUD(), USD())
These handy CurrencyPair
constructors use their single currency counterparts in the obvious fashion.
AUDUSD() EURUSD() NZDUSD() GBPUSD() USDJPY() GBPJPY() EURGBP() AUDNZD() EURCHF() USDCHF() USDHKD() EURNOK() USDNOK()
AUDUSD() EURUSD() NZDUSD() GBPUSD() USDJPY() GBPJPY() EURGBP() AUDNZD() EURCHF() USDCHF() USDHKD() EURNOK() USDNOK()
Other constructors: CurrencyConstructors
,
iborindices
, oniaindices
AUDUSD()
AUDUSD()
A collection of methods related to currency pairs.
is_t1(x) to_spot(dates, x) to_spot_next(dates, x) to_forward(dates, tenor, x) to_today(dates, x) to_tomorrow(dates, x) to_fx_value(dates, tenor, x) invert(x)
is_t1(x) to_spot(dates, x) to_spot_next(dates, x) to_forward(dates, tenor, x) to_today(dates, x) to_tomorrow(dates, x) to_fx_value(dates, tenor, x) invert(x)
x |
a |
dates |
a vector of dates from which forward dates are calculated |
tenor |
the tenor of the value date which can be one of the following:
"spot", "spot_next", "today", "tomorrow" and the usual "forward" dates (e.g.
|
The methods are summarised as follows:
is_t1
: Returns TRUE
if the currency pair settles one good day after
trade. This includes the following currencies crossed with the USD: CAD, TRY,
PHP, RUB, KZT and PKR
to_spot
: The spot dates are usually two non-NY good day after today.
is_t1()
identifies the pairs whose spot dates are conventionally one good
non-NYC day after today. In both cases, if those dates are not a good NYC
day, they are rolled to good NYC and non-NYC days using the Following
convention.
to_spot_next
: The spot next dates are one good NYC and non-NYC day after
spot rolled using the Following convention if necessary.
to_forward
: Forward dates are determined using the calendar's shift()
method rolling bad NYC and non-NYC days using the Following convention. The
end-to-end convention applies.
to_today
: Today is simply dates which are good NYC and non-NYC days.
Otherwise today is undefined and returns NA
.
to_tomorrow
: Tomorrow is one good NYC and non-NYC day except where that
is on or after spot. In that case, is is undefined and returns NA
.
to_value
: Determine common value dates. The supported value date tenors
are: "spot", "spot_next", "today", "tomorrow" and the usual
"forward" dates (e.g. lubridate::months(3)
).
invert
: Inverts the currency pair and returns new CurrencyPair
object.
is.CurrencyPair
: Returns TRUE
if x
inherits from the CurrencyPair
class; otherwise FALSE
library(lubridate) is_t1(AUDUSD()) dts <- lubridate::ymd(20170101) + lubridate::days(0:30) to_spot(dts, AUDUSD()) to_spot_next(dts, AUDUSD()) to_today(dts, AUDUSD()) to_tomorrow(dts, AUDUSD()) to_fx_value(dts, months(3), AUDUSD())
library(lubridate) is_t1(AUDUSD()) dts <- lubridate::ymd(20170101) + lubridate::days(0:30) to_spot(dts, AUDUSD()) to_spot_next(dts, AUDUSD()) to_today(dts, AUDUSD()) to_tomorrow(dts, AUDUSD()) to_fx_value(dts, months(3), AUDUSD())
The DiscountFactor
class is designed to represent discount factors. Checks
whether: d1
is less than d2
, elementwise, and that both are Date
vectors; and value
is greater than zero and is a numeric vector. An error
is thrown if any of these are not true. The elements of each argument are
recycled such that each resulting vectors have equivalent lengths.
DiscountFactor(value, d1, d2)
DiscountFactor(value, d1, d2)
value |
a numeric vector containing discount factor values. Must be greater than zero |
d1 |
a |
d2 |
a |
a (vectorised) DiscountFactor
object
library("lubridate") df <- DiscountFactor(c(0.95, 0.94, 0.93), ymd(20130101), ymd(20140101, 20150101)) as_InterestRate(df, 2, "act/365")
library("lubridate") df <- DiscountFactor(c(0.95, 0.94, 0.93), ymd(20130101), ymd(20140101, 20150101)) as_InterestRate(df, 2, "act/365")
DiscountFactor
operationsA number of different operations can be performed on or with
DiscountFactor
objects. Methods have been defined for base
package generic operations including arithmetic and comparison.
The operations are:
c
: concatenates a vector of DiscountFactor
objects
[
: extract parts of a DiscountFactor
vector
[<-
: replace parts of a DiscountFactor
vector
rep
: repeat a DiscountFactor
object
length
: determines the length of a DiscountFactor
vector
*
: multiplication of DiscountFactor
objects. The end
date of the first discount factor object must be equivalent to the start
date of the second (or vice versa). Arguments are recycled as necessary.
/
: division of DiscountFactor
objects. The start date
date of both arguments must be the same. Arguments are recycled as necessary.
<, >, <=, >=, ==, !=
: these operate in the standard way on the
discount_factor
field.
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 legal documentation.
This can be used to represent IBOR like indices (e.g. LIBOR, BBSW, CDOR)
and extends the Index
class.
IborIndex(name, currency, tenor, spot_lag, calendar, day_basis, day_convention, is_eom)
IborIndex(name, currency, tenor, spot_lag, calendar, day_basis, day_convention, is_eom)
name |
the name of the index as a string |
currency |
the currency associated with the index as a Currency object |
tenor |
the term of the index as a period |
spot_lag |
the period between the index's fixing and the start of the index's term |
calendar |
the calendar used to determine whether the index fixes on a given date as a Calendar |
day_basis |
the day basis associated with the index (e.g. "act/365") |
day_convention |
the day convention associated with the index (e.g. "mf") |
is_eom |
a flag indicating whether or not the maturity date of the index is subject to the end-to-end convention. |
an object of class IborIndex
that inherits from Index
library(lubridate) library(fmdates) # 3m AUD BBSW IborIndex("BBSW", AUD(), months(3), days(0), c(AUSYCalendar()), "act/365", "ms", FALSE)
library(lubridate) library(fmdates) # 3m AUD BBSW IborIndex("BBSW", AUD(), months(3), days(0), c(AUSYCalendar()), "act/365", "ms", FALSE)
These functions create commonly used IBOR indices with standard market conventions.
AUDBBSW(tenor) AUDBBSW1b(tenor) EURIBOR(tenor) GBPLIBOR(tenor) JPYLIBOR(tenor) JPYTIBOR(tenor) NZDBKBM(tenor) USDLIBOR(tenor) CHFLIBOR(tenor) HKDHIBOR(tenor) NOKNIBOR(tenor)
AUDBBSW(tenor) AUDBBSW1b(tenor) EURIBOR(tenor) GBPLIBOR(tenor) JPYLIBOR(tenor) JPYTIBOR(tenor) NZDBKBM(tenor) USDLIBOR(tenor) CHFLIBOR(tenor) HKDHIBOR(tenor) NOKNIBOR(tenor)
tenor |
the tenor of the IBOR index (e.g. |
The key conventions are tabulated below.
Creator | Spot lag (days) | Fixing calendars | Day basis | Day convention | EOM |
AUDBBSW() | 0 | AUSYCalendar | act/365 | ms | FALSE |
EURIBOR() | 2 | EUTACalendar | act/360 | mf | TRUE |
GBPLIBOR() | 0 | GBLOCalendar | act/365 | mf | TRUE |
JPYLIBOR() | 2 | GBLOCalendar | act/360 | mf | TRUE |
JPYTIBOR() | 2 | JPTOCalendar | act/365 | mf | FALSE |
NZDBKBM() | 0 | NZWECalendar, NZAUCalendar | act/365 | mf | FALSE |
USDLIBOR() | 2 | USNYCalendar, GBLOCalendar | act/360 | mf | TRUE |
CHFLIBOR() | 2 | GBLOCalendar | act/360 | mf | TRUE |
HKDHIBOR() | 0 | HKHKCalendar | act/365 | mf | FALSE |
NOKNIBOR() | 2 | NOOSCalendar | act/360 | mf | FALSE |
There are some nuances to this. Sub-1m LIBOR and TIBOR spot lags are zero days (excepting spot-next rates) and use the following day convention and the overnight USDLIBOR index uses both USNYCalendar and GBLOCalendar calendars.
BBSW EURIBOR ICE LIBOR BBA LIBOR TIBOR NZD BKBM OpenGamma Interest Rate Instruments and Market Conventions Guide HKD HIBOR
Other constructors: CurrencyConstructors
,
CurrencyPairConstructors
,
oniaindices
Index class checkers
is.Index(x) is.IborIndex(x) is.CashIndex(x)
is.Index(x) is.IborIndex(x) is.CashIndex(x)
x |
an object |
TRUE
if object inherits from tested class
is.Index(AONIA()) is.CashIndex(AONIA()) is.IborIndex(AONIA())
is.Index(AONIA()) is.CashIndex(AONIA()) is.IborIndex(AONIA())
A collection of methods that shift dates according to index conventions.
to_reset(dates, index) to_value(dates, index) to_maturity(dates, index) ## Default S3 method: to_reset(dates, index) ## Default S3 method: to_value(dates, index) ## Default S3 method: to_maturity(dates, index)
to_reset(dates, index) to_value(dates, index) to_maturity(dates, index) ## Default S3 method: to_reset(dates, index) ## Default S3 method: to_value(dates, index) ## Default S3 method: to_maturity(dates, index)
dates |
a vector of dates to shift |
index |
an instance of an object that inherits from the |
The following describes the default methods. to_reset()
treats the input
dates as value dates and shifts these to the corresponding reset or fixing
dates using the index's spot lag; to_value()
treats the input dates as
reset or fixing dates and shifts them to the corresponding value dates using
the index's spot lag; and to_maturity()
treats the input dates as value
dates and shifts these to the index's corresponding maturity date using the
index's tenor.
a vector of shifted dates
library(lubridate) to_reset(ymd(20170101) + days(0:30), AUDBBSW(months(3))) to_value(ymd(20170101) + days(0:30), AUDBBSW(months(3))) to_maturity(ymd(20170101) + days(0:30), AUDBBSW(months(3)))
library(lubridate) to_reset(ymd(20170101) + days(0:30), AUDBBSW(months(3))) to_value(ymd(20170101) + days(0:30), AUDBBSW(months(3))) to_maturity(ymd(20170101) + days(0:30), AUDBBSW(months(3)))
The InterestRate
class is designed to represent interest rates. Checks
whether: the day_basis
is valid; and the compounding
is valid. An error
is thrown if any of these are not true. The elements of each argument are
recycled such that each resulting vectors have equivalent lengths.
InterestRate(value, compounding, day_basis)
InterestRate(value, compounding, day_basis)
value |
a numeric vector containing interest rate values (as decimals). |
compounding |
a numeric vector representing the compounding frequency. |
day_basis |
a character vector representing the day basis associated
with the interest rate (see |
a vectorised InterestRate
object
library("lubridate") InterestRate(c(0.04, 0.05), c(2, 4), 'act/365') rate <- InterestRate(0.04, 2, 'act/365') as_DiscountFactor(rate, ymd(20140101), ymd(20150101)) as_InterestRate(rate, compounding = 4, day_basis = 'act/365')
library("lubridate") InterestRate(c(0.04, 0.05), c(2, 4), 'act/365') rate <- InterestRate(0.04, 2, 'act/365') as_DiscountFactor(rate, ymd(20140101), ymd(20150101)) as_InterestRate(rate, compounding = 4, day_basis = 'act/365')
InterestRate
operationsA number of different operations can be performed on or with
InterestRate
objects. Methods have been defined for base
package generic operations including arithmetic and comparison.
The operations are:
c
: concatenates a vector of InterestRate
objects
[
: extract parts of a InterestRate
vector
[<-
: replace parts of a InterestRate
vector
rep
: repeat a InterestRate
object
length
: determines the length of a InterestRate
vector
+, -
: addition/subtraction of InterestRate
objects. Where
two InterestRate
objects are added/subtracted, the second is first
converted to have the same compounding and day basis frequency as the first.
Numeric values can be added/subtracted to/from an InterestRate
object by performing the operation directly on the rate
field.
Arguments are recycled as necessary.
*
: multiplication of InterestRate
objects. Where
two InterestRate
objects are multiplied, the second is first
converted to have the same compounding and day basis frequency as the first.
Numeric values can be multiplied to an InterestRate
object by performing the operation directly on the rate
field.
Arguments are recycled as necessary.
/
: division of InterestRate
objects. Where
two InterestRate
objects are divided, the second is first
converted to have the same compounding and day basis frequency as the first.
Numeric values can divide an InterestRate
object by performing the operation directly on the rate
field.
Arguments are recycled as necessary.
<, >, <=, >=, ==, !=
: these operate in the standard way on the
rate
field, and if necessary, the second InterestRate
object
is converted to have the same compounding and day basis frequency as the
first.
Interpolate values from an object
interpolate(x, ...)
interpolate(x, ...)
x |
the object to interpolate. |
... |
other parameters that defines how to interpolate the object |
an interpolated value or set of values
Other interpolate functions: interpolate.CreditCurve
,
interpolate.VolSurface
,
interpolate.ZeroCurve
,
interpolate_dfs.CreditCurve
,
interpolate_zeros.CreditCurve
This interpolates forward rates and forward discount factors from either a ZeroCurve or some other object that contains such an object.
## S3 method for class 'CreditCurve' interpolate_dfs(x, from, to, ...) ## S3 method for class 'CreditCurve' interpolate_fwds(x, from, to, ...) interpolate_dfs(x, from, to, ...) interpolate_fwds(x, from, to, ...) ## S3 method for class 'ZeroCurve' interpolate_fwds(x, from, to, ...) ## S3 method for class 'ZeroCurve' interpolate_dfs(x, from, to, ...)
## S3 method for class 'CreditCurve' interpolate_dfs(x, from, to, ...) ## S3 method for class 'CreditCurve' interpolate_fwds(x, from, to, ...) interpolate_dfs(x, from, to, ...) interpolate_fwds(x, from, to, ...) ## S3 method for class 'ZeroCurve' interpolate_fwds(x, from, to, ...) ## S3 method for class 'ZeroCurve' interpolate_dfs(x, from, to, ...)
x |
the object to interpolate |
from |
a Date vector representing the start of the forward period |
to |
a Date vector representing the end of the forward period |
... |
further arguments passed to specific methods |
interpolate_dfs
returns a DiscountFactor object
of forward discount factors while interpolate_fwds
returns an
InterestRate object of interpolated simply compounded
forward rates.
Other interpolate functions: interpolate.CreditCurve
,
interpolate.VolSurface
,
interpolate.ZeroCurve
,
interpolate_zeros.CreditCurve
,
interpolate
This interpolates zero rates from either a ZeroCurve or some other object that contains such an object.
## S3 method for class 'CreditCurve' interpolate_zeros(x, at, compounding = NULL, day_basis = NULL, ...) interpolate_zeros(x, at, compounding = NULL, day_basis = NULL, ...) ## S3 method for class 'ZeroCurve' interpolate_zeros(x, at, compounding = NULL, day_basis = NULL, ...)
## S3 method for class 'CreditCurve' interpolate_zeros(x, at, compounding = NULL, day_basis = NULL, ...) interpolate_zeros(x, at, compounding = NULL, day_basis = NULL, ...) ## S3 method for class 'ZeroCurve' interpolate_zeros(x, at, compounding = NULL, day_basis = NULL, ...)
x |
the object to interpolate |
at |
a Date vector representing the date at which to interpolate a value |
compounding |
a valid compounding string.
Defaults to |
day_basis |
a valid day basis string.
Defaults to |
... |
further arguments passed to specific methods |
an InterestRate object of interpolated zero rates
with the compounnding
and day_basis
requested.
Other interpolate functions: interpolate.CreditCurve
,
interpolate.VolSurface
,
interpolate.ZeroCurve
,
interpolate_dfs.CreditCurve
,
interpolate
CreditCurve
There are two key interpolation schemes available in the stats
package:
constant and linear interpolation via stats::approxfun()
and
spline interpolation via stats::splinefun()
. The interpolate()
method
is a simple wrapper around these methods that are useful for the purposes
of interpolation financial market objects like credit curves.
## S3 method for class 'CreditCurve' interpolate(x, at, ...)
## S3 method for class 'CreditCurve' interpolate(x, at, ...)
x |
a |
at |
a non-negative numeric vector representing the years at which to interpolate the Credit curve |
... |
unused in this method |
a numeric vector of zero rates (continuously compounded, act/365)
Other interpolate functions: interpolate.VolSurface
,
interpolate.ZeroCurve
,
interpolate_dfs.CreditCurve
,
interpolate_zeros.CreditCurve
,
interpolate
zc <- build_zero_curve(LogDFInterpolation()) interpolate(zc, c(1.5, 3))
zc <- build_zero_curve(LogDFInterpolation()) interpolate(zc, c(1.5, 3))
VolSurface
object.This method is used to interpolate a VolSurface
object at multiple points of
the plane. The interpolation depends on the type of the surface, if the vols are
given by strikes, delta, moneyness.
## S3 method for class 'VolSurface' interpolate(x, at, ...)
## S3 method for class 'VolSurface' interpolate(x, at, ...)
x |
object of class |
at |
indicates the coordinates at which the interpolation is performed.
|
... |
unused in this model. |
numeric
vector with length equal to the number of rows of at
.
Other interpolate functions: interpolate.CreditCurve
,
interpolate.ZeroCurve
,
interpolate_dfs.CreditCurve
,
interpolate_zeros.CreditCurve
,
interpolate
x <- build_vol_surface() at <- tibble::tibble( maturity = c(as.Date("2020-03-31"), as.Date("2021-03-31")), smile = c(40, 80) ) interpolate(x, at)
x <- build_vol_surface() at <- tibble::tibble( maturity = c(as.Date("2020-03-31"), as.Date("2021-03-31")), smile = c(40, 80) ) interpolate(x, at)
ZeroCurve
There are two key interpolation schemes available in the stats
package:
constant and linear interpolation via stats::approxfun()
and
spline interpolation via stats::splinefun()
. The interpolate()
method
is a simple wrapper around these methods that are useful for the purposes
of interpolation financial market objects like zero coupon interest rate
curves.
## S3 method for class 'ZeroCurve' interpolate(x, at, ...)
## S3 method for class 'ZeroCurve' interpolate(x, at, ...)
x |
a |
at |
a non-negative numeric vector representing the years at which to interpolate the zero curve |
... |
unused in this method |
a numeric vector of zero rates (continuously compounded, act/365)
Other interpolate functions: interpolate.CreditCurve
,
interpolate.VolSurface
,
interpolate_dfs.CreditCurve
,
interpolate_zeros.CreditCurve
,
interpolate
zc <- build_zero_curve(LogDFInterpolation()) interpolate(zc, c(1.5, 3))
zc <- build_zero_curve(LogDFInterpolation()) interpolate(zc, c(1.5, 3))
These are lightweight interpolation classes that are used to specify typical financial market interpolation schemes. Their behaviour is dictated by the object in which they defined.
ConstantInterpolation() LogDFInterpolation() LinearInterpolation() CubicInterpolation() LinearCubicTimeVarInterpolation()
ConstantInterpolation() LogDFInterpolation() LinearInterpolation() CubicInterpolation() LinearCubicTimeVarInterpolation()
an object that inherits from the Interpolation
class.
ConstantInterpolation()
ConstantInterpolation()
A non-exported function that checks whether compounding values frequencies are supported.
is_valid_compounding(compounding)
is_valid_compounding(compounding)
compounding |
a numeric vector representing the compounding frequency |
Valid compounding values are:
Value | Frequency |
-1 | Simply, T-bill discounting |
0 | Simply |
1 | Annually |
2 | Semi-annually |
3 | Tri-annually |
4 | Quarterly |
6 | Bi-monthly |
12 | Monthly |
24 | Fortnightly |
52 | Weekly |
365 | Daily |
Inf | Continuously |
a flag (TRUE
or FALSE
) if all the supplied compounding
frequencies are supported.
Checks whether object inherits from CashFlow
class
is.CashFlow(x)
is.CashFlow(x)
x |
an R object |
TRUE
if x
inherits from the CashFlow
class; otherwise FALSE
Other money functions: CashFlow
,
MultiCurrencyMoney
,
SingleCurrencyMoney
,
is.MultiCurrencyMoney
,
is.SingleCurrencyMoney
is.CashFlow(CashFlow(as.Date("2017-11-15"), MultiCurrencyMoney(list(SingleCurrencyMoney(1, AUD())))))
is.CashFlow(CashFlow(as.Date("2017-11-15"), MultiCurrencyMoney(list(SingleCurrencyMoney(1, AUD())))))
Checks whether object inherits from CDSCurve
class
is.CDSCurve(x)
is.CDSCurve(x)
x |
an R object |
TRUE
if x
inherits from the CDSCurve
class; otherwise FALSE
Other CDS curve helpers: CDSCurve
,
CDSMarkitSpec
,
CDSSingleNameSpec
, CDSSpec
,
SurvivalProbabilities
,
ZeroHazardRate
, is.CDSSpec
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) cds_curve <- CDSCurve( as.Date("2019-06-29"), tenors = c(1, 3, 5, 7), spreads = c(0.0050, 0.0070, 0.0090, 0.0110), lgd = 0.6, premium_frequency = 4, specs = curve_specs ) is.CDSCurve(cds_curve)
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) cds_curve <- CDSCurve( as.Date("2019-06-29"), tenors = c(1, 3, 5, 7), spreads = c(0.0050, 0.0070, 0.0090, 0.0110), lgd = 0.6, premium_frequency = 4, specs = curve_specs ) is.CDSCurve(cds_curve)
Checks whether object inherits from CDSSpec
class
is.CDSSpec(x)
is.CDSSpec(x)
x |
an R object |
TRUE
if x
inherits from the CDSSpec
class; otherwise FALSE
Other CDS curve helpers: CDSCurve
,
CDSMarkitSpec
,
CDSSingleNameSpec
, CDSSpec
,
SurvivalProbabilities
,
ZeroHazardRate
, is.CDSCurve
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) is.CDSSpec(curve_specs)
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) is.CDSSpec(curve_specs)
Checks whether object inherits from CreditCurve
class
is.CreditCurve(x)
is.CreditCurve(x)
x |
an R Object |
TRUE
if x
inherits from the CreditCurve
class; otherwise FALSE
Checks whether object inherits from Currency
class
is.Currency(x)
is.Currency(x)
x |
an R object |
TRUE
if x
inherits from the Currency
class; otherwise FALSE
is.Currency(AUD())
is.Currency(AUD())
CurrencyPair
classInherits from CurrencyPair
class
is.CurrencyPair(x)
is.CurrencyPair(x)
x |
an R object |
TRUE
if x
inherits from the CurrencyPair
class; otherwise FALSE
is.CurrencyPair(AUDUSD())
is.CurrencyPair(AUDUSD())
Checks whether object inherits from DiscountFactor
class
is.DiscountFactor(x)
is.DiscountFactor(x)
x |
an R object |
TRUE
if x
inherits from the DiscountFactor
class; otherwise FALSE
is.DiscountFactor(DiscountFactor(0.97, Sys.Date(), Sys.Date() + 30))
is.DiscountFactor(DiscountFactor(0.97, Sys.Date(), Sys.Date() + 30))
Checks whether object inherits from InterestRate
class
is.InterestRate(x)
is.InterestRate(x)
x |
an R object |
TRUE
if x
inherits from the InterestRate
class; otherwise FALSE
is.InterestRate(InterestRate(0.04, 2, "act/365"))
is.InterestRate(InterestRate(0.04, 2, "act/365"))
These methods check whether an interpolation is of a particular scheme.
is.Interpolation(x) is.ConstantInterpolation(x) is.LogDFInterpolation(x) is.LinearInterpolation(x) is.CubicInterpolation(x) is.LinearCubicTimeVarInterpolation(x)
is.Interpolation(x) is.ConstantInterpolation(x) is.LogDFInterpolation(x) is.LinearInterpolation(x) is.CubicInterpolation(x) is.LinearCubicTimeVarInterpolation(x)
x |
an object |
a logical flag
is.Interpolation(CubicInterpolation()) is.CubicInterpolation(CubicInterpolation())
is.Interpolation(CubicInterpolation()) is.CubicInterpolation(CubicInterpolation())
Checks whether object inherits from MultiCurrencyMoney
class
is.MultiCurrencyMoney(x)
is.MultiCurrencyMoney(x)
x |
an R object |
TRUE
if x
inherits from the MultiCurrencyMoney
class; otherwise FALSE
Other money functions: CashFlow
,
MultiCurrencyMoney
,
SingleCurrencyMoney
,
is.CashFlow
,
is.SingleCurrencyMoney
is.MultiCurrencyMoney(MultiCurrencyMoney(list(SingleCurrencyMoney(1, AUD()))))
is.MultiCurrencyMoney(MultiCurrencyMoney(list(SingleCurrencyMoney(1, AUD()))))
Checks whether object inherits from SingleCurrencyMoney
class
is.SingleCurrencyMoney(x)
is.SingleCurrencyMoney(x)
x |
an R object |
TRUE
if x
inherits from the SingleCurrencyMoney
class; otherwise FALSE
Other money functions: CashFlow
,
MultiCurrencyMoney
,
SingleCurrencyMoney
,
is.CashFlow
,
is.MultiCurrencyMoney
is.SingleCurrencyMoney(SingleCurrencyMoney(1:5, AUD()))
is.SingleCurrencyMoney(SingleCurrencyMoney(1:5, AUD()))
Checks whether object inherits from SurvivalProbabilities
class
is.SurvivalProbabilities(x)
is.SurvivalProbabilities(x)
x |
an R object |
TRUE
if x
inherits from the SurvivalProbabilities
class; otherwise FALSE
is.SurvivalProbabilities(SurvivalProbabilities(0.97, Sys.Date(), Sys.Date() + 30, CDSSpec("Empty")))
is.SurvivalProbabilities(SurvivalProbabilities(0.97, Sys.Date(), Sys.Date() + 30, CDSSpec("Empty")))
Checks whether the object inherits from VolQuotes
class
is.VolQuotes(x)
is.VolQuotes(x)
x |
an R object |
TRUE
if x
inherits from the VolQuotes
class; otherwise FALSE
Checks whether object inherits from VolSurface
class
is.VolSurface(x)
is.VolSurface(x)
x |
an R object |
TRUE
if x
inherits from the VolSurface
class; otherwise FALSE
Checks whether object inherits from ZeroCurve
class
is.ZeroCurve(x)
is.ZeroCurve(x)
x |
an R object |
TRUE
if x
inherits from the ZeroCurve
class; otherwise FALSE
is.ZeroCurve(build_zero_curve())
is.ZeroCurve(build_zero_curve())
Checks whether object inherits from ZeroHazardRate
class
is.ZeroHazardRate(x)
is.ZeroHazardRate(x)
x |
an R object |
TRUE
if x
inherits from the ZeroHazardRate
class; otherwise FALSE
is.ZeroHazardRate(ZeroHazardRate(0.04, 2, "act/365", CDSSpec("Empty")))
is.ZeroHazardRate(ZeroHazardRate(0.04, 2, "act/365", CDSSpec("Empty")))
The default method assumes the ISO can be accessed as if it were an attribute
with name iso
(e.g. x$iso
). The method for CurrencyPair
concatenates
the ISOs of the constituent currencies (e.g. iso(AUDUSD())
returns
"AUDUSD") while the methods for CashIndex
and IborIndex
return the ISO of
the index's currency.
## S3 method for class 'CurrencyPair' iso(x) iso(x) ## Default S3 method: iso(x) ## S3 method for class 'IborIndex' iso(x) ## S3 method for class 'CashIndex' iso(x)
## S3 method for class 'CurrencyPair' iso(x) iso(x) ## Default S3 method: iso(x) ## S3 method for class 'IborIndex' iso(x) ## S3 method for class 'CashIndex' iso(x)
x |
object from which to extract an ISO |
a string of the ISO
library("lubridate") iso(AUD()) iso(AUDUSD()) iso(AUDBBSW(months(3))) iso(AONIA())
library("lubridate") iso(AUD()) iso(AUDUSD()) iso(AUDBBSW(months(3))) iso(AONIA())
This class associates a vector of numeric values with a list of currencies.
This can be useful for example to store value of cash flows. Internally it
represents this information as an extension to a tibble.
You are able to bind MultiCurrencyMoney
objects by using rbind()
(see
example below).
MultiCurrencyMoney(monies)
MultiCurrencyMoney(monies)
monies |
a list of SingleCurrencyMoney |
a MultiCurrencyMoney
object that extends tibble::tibble()
Other money functions: CashFlow
,
SingleCurrencyMoney
,
is.CashFlow
,
is.MultiCurrencyMoney
,
is.SingleCurrencyMoney
mcm <- MultiCurrencyMoney(list( SingleCurrencyMoney(1, AUD()), SingleCurrencyMoney(2, USD()) )) rbind(mcm, mcm)
mcm <- MultiCurrencyMoney(list( SingleCurrencyMoney(1, AUD()), SingleCurrencyMoney(2, USD()) )) rbind(mcm, mcm)
These functions create commonly used ONIA indices with standard market conventions.
AONIA() EONIA() SONIA() TONAR() NZIONA() FedFunds() CHFTOIS() HONIX()
AONIA() EONIA() SONIA() TONAR() NZIONA() FedFunds() CHFTOIS() HONIX()
The key conventions are tabulated below. All have a zero day spot lag excepting
CHFTOIS
which has a one day lag (it is a tom-next rate, per 2006 ISDA
definitions).
Creator | Fixing calendars | Day basis | Day convention |
AONIA() | AUSYCalendar | act/365 | f |
EONIA() | EUTACalendar | act/360 | f |
SONIA() | GBLOCalendar | act/365 | f |
TONAR() | JPTOCalendar | act/365 | f |
NZIONA() | NZWECalendar, NZAUCalendar | act/365 | f |
FedFunds() | USNYCalendar | act/360 | f |
CHFTOIS() | CHZHCalendar | act/360 | f |
HONIX() | HKHKCalendar | act/365 | f |
Note that for some ONIA indices, the overnight rate is not published until the following date (i.e. it has publication lag of one day).
AONIA EONIA SONIA TONAR NZIONA FedFunds OpenGamma Interest Rate Instruments and Market Conventions Guide
Other constructors: CurrencyConstructors
,
CurrencyPairConstructors
,
iborindices
This class associates a numeric vector with a currency. This is useful for
example in representing the value of a derivative. You can concatenate a set
SingleCurrencyMoney
objects and return a
MultiCurrencyMoney object (see example below)
SingleCurrencyMoney(value, currency)
SingleCurrencyMoney(value, currency)
value |
a numeric vector of values |
currency |
a single Currency object |
a SingleCurrencyMoney
object
Other money functions: CashFlow
,
MultiCurrencyMoney
,
is.CashFlow
,
is.MultiCurrencyMoney
,
is.SingleCurrencyMoney
SingleCurrencyMoney(1:5, AUD()) c(SingleCurrencyMoney(1, AUD()), SingleCurrencyMoney(100, USD()))
SingleCurrencyMoney(1:5, AUD()) c(SingleCurrencyMoney(1, AUD()), SingleCurrencyMoney(100, USD()))
SurvivalProbabilitiesCurve
This will allow you to create a survival probability curve. This will
typically be bootstrapped from a CDSCurve()
.
SurvivalProbabilities(values, d1, d2, specs)
SurvivalProbabilities(values, d1, d2, specs)
values |
a vector of survival probabilities corresponding to each
time step in |
d1 |
a |
d2 |
a |
specs |
CDS curve specifications that inherits from |
returns an object of type SurvivalProbabilitiesCurve
Other CDS curve helpers: CDSCurve
,
CDSMarkitSpec
,
CDSSingleNameSpec
, CDSSpec
,
ZeroHazardRate
, is.CDSCurve
,
is.CDSSpec
SurvivalProbabilities(0.97, Sys.Date(), Sys.Date() + 30, CDSSpec("Empty"))
SurvivalProbabilities(0.97, Sys.Date(), Sys.Date() + 30, CDSSpec("Empty"))
SurvivalProbabilities
operationsA number of different operations can be performed on or with
SurvivalProbabilities
objects. Methods have been defined for base
package generic operations including arithmetic and comparison.
The operations are:
c
: concatenates a vector of SurvivalProbabilities
objects
[
: extract parts of a SurvivalProbabilities
vector
[<-
: replace parts of a SurvivalProbabilities
vector
rep
: repeat a SurvivalProbabilities
object
length
: determines the length of a SurvivalProbabilities
vector
*
: multiplication of SurvivalProbabilities
objects. The end
date of the first SurvivalProbabilities object must be equivalent to the start
date of the second (or vice versa). Arguments are recycled as necessary.
/
: division of SurvivalProbabilities
objects. The start date
date of both arguments must be the same. Arguments are recycled as necessary.
<, >, <=, >=, ==, !=
: these operate in the standard way on the
discount_factor
field.
VolQuotes
class is designed to capture volatility data. Checks that the
inputs are of the correct type and stores the values in a tibble::tibble()
.
VolQuotes(maturity, smile, value, reference_date, type, ticker)
VolQuotes(maturity, smile, value, reference_date, type, ticker)
maturity |
Date vector that captures the maturity pillar points. |
smile |
numeric vector containing the values of the second dimension
of the volatility surface. The elements of the vector can either contain
the strikes, the moneyness or the delta. The input type is specified in
|
value |
numeric vector containing the values of the volatilities. Should
typically be represented as a decimal value (e.g. 30% should be 0.3) and
must be the same length as |
reference_date |
|
type |
string defining the second dimension of the VolSurface. The
values accepted in |
ticker |
string that represents the underlying asset. This is stored as
an attribute to the tibble and can be extracted by calling
|
object of class VolQuotes
VolSurface()
, build_vol_quotes()
pillars <- seq(as.Date("2019-04-26") + 1, by = "month", length.out = 3) VolQuotes( maturity = rep(pillars, 4), smile = rep(seq(10, 20, length.out = 4), each = 3), value = seq(1, 0.1, length.out = 12), reference_date = as.Date("2019-04-26"), type = "strike", ticker = "ABC.AX" )
pillars <- seq(as.Date("2019-04-26") + 1, by = "month", length.out = 3) VolQuotes( maturity = rep(pillars, 4), smile = rep(seq(10, 20, length.out = 4), each = 3), value = seq(1, 0.1, length.out = 12), reference_date = as.Date("2019-04-26"), type = "strike", ticker = "ABC.AX" )
The VolSurface
class is designed to capture implied volatility information
along with information about how to interpolate an implied volatility between nodes.
VolSurface(vol_quotes, interpolation)
VolSurface(vol_quotes, interpolation)
vol_quotes |
object of class |
interpolation |
Interplation method, given as an object of class
interpolation |
a VolSurface
object
interpolate.VolSurface, build_vol_surface()
VolSurface(build_vol_quotes(), LinearCubicTimeVarInterpolation())
VolSurface(build_vol_quotes(), LinearCubicTimeVarInterpolation())
A class that defines the bare bones of a zero-coupon yield curve pricing structure.
ZeroCurve(discount_factors, reference_date, interpolation)
ZeroCurve(discount_factors, reference_date, interpolation)
discount_factors |
a |
reference_date |
a |
interpolation |
an |
A term structure of interest rates (or yield curve) is a curve showing several yields or interest rates across different contract lengths (2 month, 2 year, 20 year, etc...) for a similar debt contract. The curve shows the relation between the (level of) interest rate (or cost of borrowing) and the time to maturity, known as the "term", of the debt for a given borrower in a given currency. For example, the U.S. dollar interest rates paid on U.S. Treasury securities for various maturities are closely watched by many traders, and are commonly plotted on a graph. More formal mathematical descriptions of this relation are often called the term structure of interest rates. When the effect of coupons on yields are stripped away, one has a zero-coupon yield curve.
a ZeroCurve
object
The following interpolation schemes are supported by ZeroCurve
:
ConstantInterpolation
: constant interpolation on zero rates
LinearInterpolation
: linear interpolation on zero rates
LogDFInterpolation
: linear interpolation on log discount factors or
constant on forward rates
CubicInterpolation
: natural cubic spline on zero rates
Points outside the calibration region use constant extrapolation on zero rates.
build_zero_curve()
build_zero_curve()
ZeroHazardRate
This will allow you to create a harzard rate curve. This will typically be
bootstrapped or implied from a CDSCurve()
or SurvivalProbabilities()
.
ZeroHazardRate(values, compounding, day_basis, specs)
ZeroHazardRate(values, compounding, day_basis, specs)
values |
a numeric vector containing zero hazard rate values (as decimals). |
compounding |
a numeric vector representing the compounding frequency. |
day_basis |
a character vector representing the day basis associated
with the interest rate and hazard rate(see |
specs |
CDS curve specifications that inherits from |
returns an object of type hazard_rates
Other CDS curve helpers: CDSCurve
,
CDSMarkitSpec
,
CDSSingleNameSpec
, CDSSpec
,
SurvivalProbabilities
,
is.CDSCurve
, is.CDSSpec
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) ZeroHazardRate(values = c(0.04, 0.05), compounding = c(2, 4), day_basis = 'act/365', specs = curve_specs )
curve_specs <- CDSMarkitSpec( rating = "AAA", region = "Japan", sector = "Utilities" ) ZeroHazardRate(values = c(0.04, 0.05), compounding = c(2, 4), day_basis = 'act/365', specs = curve_specs )
ZeroHazardRate
operationsA number of different operations can be performed on or with
ZeroHazardRate
objects. Methods have been defined for base
package generic operations including arithmetic and comparison.
The operations are:
c
: concatenates a vector of ZeroHazardRate
objects
[
: extract parts of a ZeroHazardRate
vector
[<-
: replace parts of a ZeroHazardRate
vector
rep
: repeat a ZeroHazardRate
object
length
: determines the length of a ZeroHazardRate
vector
+, -
: addition/subtraction of ZeroHazardRate
objects. Where
two ZeroHazardRate
objects are added/subtracted, the second is first
converted to have the same compounding and day basis frequency as the first.
Numeric values can be added/subtracted to/from an ZeroHazardRate
object by performing the operation directly on the rate
field.
Arguments are recycled as necessary.
*
: multiplication of ZeroHazardRate
objects. Where
two ZeroHazardRate
objects are multiplied, the second is first
converted to have the same compounding and day basis frequency as the first.
Numeric values can be multiplied to an ZeroHazardRate
object by performing the operation directly on the rate
field.
Arguments are recycled as necessary.
/
: division of ZeroHazardRate
objects. Where
two ZeroHazardRate
objects are divided, the second is first
converted to have the same compounding and day basis frequency as the first.
Numeric values can divide an ZeroHazardRate
object by performing the operation directly on the rate
field.
Arguments are recycled as necessary.
<, >, <=, >=, ==, !=
: these operate in the standard way on the
rate
field, and if necessary, the second ZeroHazardRate
object
is converted to have the same compounding and day basis frequency as the
first.