Package: ragtop 1.1.1

Brian K. Boonstra

ragtop: Pricing Equity Derivatives with Extensions of Black-Scholes

Algorithms to price American and European equity options, convertible bonds and a variety of other financial derivatives. It uses an extension of the usual Black-Scholes model in which jump to default may occur at a probability specified by a power-law link between stock price and hazard rate as found in the paper by Takahashi, Kobayashi, and Nakagawa (2001) <doi:10.3905/jfi.2001.319302>. We use ideas and techniques from Andersen and Buffum (2002) <doi:10.2139/ssrn.355308> and Linetsky (2006) <doi:10.1111/j.1467-9965.2006.00271.x>.

Authors:Brian K. Boonstra

ragtop_1.1.1.tar.gz
ragtop_1.1.1.tar.gz(r-4.5-noble)ragtop_1.1.1.tar.gz(r-4.4-noble)
ragtop_1.1.1.tgz(r-4.4-emscripten)ragtop_1.1.1.tgz(r-4.3-emscripten)
ragtop.pdf |ragtop.html
ragtop/json (API)
NEWS

# Install 'ragtop' in R:
install.packages('ragtop', repos = 'https://cloud.r-project.org')
Datasets:
  • TSLAMarket - Market information snapshot for TSLA options

On CRAN:

Conda:r-ragtop-1.1.1(2025-03-25)

This package does not link to any Github/Gitlab/R-forge repository. No issue tracker or development information is available.

2.70 score 228 downloads 44 exports 8 dependencies

Last updated 5 years agofrom:41384b6fd7. Checks:1 OK, 2 WARNING. Indexed: yes.

TargetResultLatest binary
Doc / VignettesOKMar 29 2025
R-4.5-linuxWARNINGMar 29 2025
R-4.4-linuxWARNINGMar 29 2025

Exports:accelerated_coupon_valueadjust_for_dividendsamericanamerican_implied_volatilityAmericanOptionblack_scholes_on_term_structuresblackscholesCALLCallableBondconstruct_tridiagonalsConvertibleBondcoupon_value_at_exerciseCouponBonddetail_from_AnnivDatesEquityOptionequivalent_bs_vola_to_jumpequivalent_jump_vola_to_bsEuropeanOptionfind_present_valuefit_to_option_marketfit_to_option_market_dffit_variance_cumulationform_present_value_gridGridPricedInstrumentimplied_jump_process_volatilityimplied_volatilitiesimplied_volatilities_with_rates_structimplied_volatilityimplied_volatility_with_term_structintegrate_pdeis.blankiterate_grid_from_timesteppenalty_with_intensity_linkprice_with_intensity_linkPUTQuandl_df_fcn_USTQuandl_df_fcn_UST_rawspot_to_df_fcntake_implicit_timesteptime_adj_dividendsTIME_RESOLUTION_FACTORTIME_RESOLUTION_SIGNIF_DIGITSvariance_cumulation_from_volsZeroCouponBond

Dependencies:formatRfutile.loggerfutile.optionslambda.rlimSolvelpSolveMASSquadprog

ragtop: Complex Derivatives Pricing

Rendered fromragtop_convertibles_in_r.Rmdusingknitr::rmarkdownon Mar 29 2025.

Last update: 2020-03-03
Started: 2016-09-28

Citation

To cite package ‘ragtop’ in publications use:

Boonstra BK (2020). ragtop: Pricing Equity Derivatives with Extensions of Black-Scholes. R package version 1.1.1, https://CRAN.R-project.org/package=ragtop.

ATTENTION: This citation information has been auto-generated from the package DESCRIPTION file and may need manual editing, see ‘help("citation")’.

Corresponding BibTeX entry:

  @Manual{,
    title = {ragtop: Pricing Equity Derivatives with Extensions of
      Black-Scholes},
    author = {Brian K. Boonstra},
    year = {2020},
    note = {R package version 1.1.1},
    url = {https://CRAN.R-project.org/package=ragtop},
  }

Readme and manuals

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

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

blackscholes(c(CALL, PUT), S0=100, K=c(100,110), time=0.77, r = 0.06, vola=0.20)
#> $Price
#> [1] 9.326839 9.963285
#> 
#> $Delta
#> [1]  0.6372053 -0.5761608
#> 
#> $Vega
#> [1] 32.91568 34.36717

and like this for American exercise

american(PUT, S0=100, K=c(100,110), time=0.77, const_short_rate = 0.06, const_volatility=0.20)
#> A100_281_0 A110_281_0 
#>    5.24386   11.27715
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

## 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))
[1] "Cumulated variance to 18 months is 0.369473684210526"

then we can price vanilla options

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)
$Price
[1] 62.55998

$Delta
[1] 0.7977684

$Vega
[1] 52.21925

American exercise options

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)
A360_137_2 
  2.894296 

We can also find volatilities of European exercise options

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)
[1] 0.1133976

as well as American exercise options

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)
[1] 0.113407

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

Travis-CI Build Status

Help Manual

Help pageTopics
Present value of coupons according to an acceleration scheduleaccelerated_coupon_value
Find the sum of time-adjusted dividend values and adjust grid prices according to their size in the given intervaladjust_for_dividends
Price one or more american-exercise optionsamerican
Implied volatility of an american option with equity-independent term structuresamerican_implied_volatility
A standard option contract allowing for _early_ exercise at the choice of the option holderAmericanOption AmericanOption-class
Black-Scholes pricing of european-exercise options with term structure argumentsblack_scholes_on_term_structures
Vectorized Black-Scholes pricing of european-exercise optionsblackscholes
Constant CALL for defining option contractsCALL
Callable (and putable) corporate or government bond.CallableBond CallableBond-class
Structure of implicit numerical integration gridconstruct_implicit_grid_structure
Matrix entries for implicit numerical differentiation using Neumann boundary conditionsconstruct_tridiagonals
Form instrument objects for vanilla optionscontrol_variate_pairs
Convertible bond with exercise into stockConvertibleBond ConvertibleBond-class
Present value of coupons according to an acceleration schedulecoupon_value_at_exercise
Standard corporate or government bondCouponBond CouponBond-class
Convert output of BondValuation::AnnivDates to inputd for Bonddetail_from_AnnivDates
An option contract with call or put termsEquityOption EquityOption-class
Find straight Black-Scholes volatility equivalent to jump process with a given default riskequivalent_bs_vola_to_jump
Find jump process volatility with a given default risk from a straight Black-Scholes volatilityequivalent_jump_vola_to_bs
A standard option contractEuropeanOption EuropeanOption-class
Use a model to estimate the present value of financial derivativesfind_present_value
Calibrate volatilities and equity-linked default intensityfit_to_option_market
Calibrate volatilities and equity-linked default intensity making many assumptionsfit_to_option_market_df
Fit piecewise constant volatilities to a set of equity optionsfit_variance_cumulation
Use a model to estimate the present value of financial derivatives on a grid of initial underlying valuesform_present_value_grid
Representation of financial instrument amenable to grid pricing schemesGridPricedInstrument GridPricedInstrument-class
Implied volatility of any instrumentimplied_jump_process_volatility
Implied volatilities of european-exercise options under Black-Scholes or a jump-process extensionimplied_volatilities
Find the implied volatility of european-exercise options with a term structure of interest ratesimplied_volatilities_with_rates_struct
Implied volatility of european-exercise option under Black-Scholes or a jump-process extensionimplied_volatility
Find the implied volatility of a european-exercise option with term structuresimplied_volatility_with_term_struct
A time grid with extra times inserted for coupons, calls and putsinfer_conforming_time_grid
Numerically integrate the pricing differential equationintegrate_pde
Return TRUE if the argument is empty, NULL or NAis.blank
Iterate over a set of timesteps to integrate the pricing differential equationiterate_grid_from_timestep
Helper function (volatility-normalized pricing error) for calibration of equity-linked default intensitypenalty_with_intensity_link
Helper function (instrument pricing) for calibration of equity-linked default intensityprice_with_intensity_link
Constant PUT for defining option contractsPUT
Get a US Treasury curve discount factor functionQuandl_df_fcn_UST
Get a US Treasury curve discount factor functionQuandl_df_fcn_UST_raw
Pricing schemes for derivatives using equity-linked default intensityragtop-package ragtop
Shift a set of grid values for dividends paid, using spline interpolationshift_for_dividends
Create a discount factor function from a yield curvespot_to_df_fcn
Backwardate grid values one timesteptake_implicit_timestep
Find the sum of time-adjusted dividend valuestime_adj_dividends
Constant to define when times are considered so close to each other that they should be treated as simultaneousTIME_RESOLUTION_FACTOR
Constant to define when times are considered so close to each other that they should be treated as simultaneous, in terms of significant digitsTIME_RESOLUTION_SIGNIF_DIGITS
Take an implicit timestep for all the given instrumentstimestep_instruments
Market information snapshot for TSLA optionsTSLAMarket
Present value of past coupons paidvalue_from_prior_coupons
Create a variance cumulation function from a volatility term structurevariance_cumulation_from_vols
A simple contract paying the 'notional' amount at the 'maturity'ZeroCouponBond ZeroCouponBond-class