yrnd-functions

library(yrnd)

yrnd

The package ‘“yrnd”’ estimates a parametric form of the Risk Neutral Density (RND) of the price of fixed-income futures such as Short Term Interest Rates futures and government bond futures, using options written on those futures. The RND is estimated at options’ maturity for all types of option’s style. The futures price is modeled as a mixture of either two or three lognormal laws. The package provides with the options prices predicted with the fitted parameters, some statistics of the distribution as well as a density and a cumulative density plot. Leveraging on this, the package provides with several additional functions. First, it provides with the distribution of the STIR rate and the government bond yield themselves at options’ maturity, using the RND of respectively the STIR futures price and the bond futures price. Then, the package extracts in one go from options prices on bond futures two RNDs at options’ maturity: the RND of the cheapest-to-deliver bond yield and the RND of the ctd repo rate. Then, the packages provides with the probability attached to each bond in the delivery basket of a government bond futures contract to be the cheapest to deliver at options’ maturity, either from the observation of the expected net basis distribution by bond at options’ maturity, or from the observation of the implied repo rate distribution by bond at options’ maturity. The package also provides with the probability attached to each bond to be the cheapest at futures’ maturity. It also provides with the non parametric RND of the bond yield spread between two issuers or two maturities, using RNDs on two bond futures with the same maturity date and a Gaussian copula. At last, the package provides with functions to extract from Bloomberg interest rate futures contracts characteristics, options prices on interest futures and major characteristics of the bonds in the delivery basket of a government bond futures contract.

stir_future_price provides with the risk neutral density at options’ maturity of the STIR futures price, using options on the STIR futures

stir_future_price( c(1.44500, 1.32000, 1.19750, 1.07500, 0.95750,
0.84250, 0.78750, 0.73250, 0.68000, 0.62750, 0.57750, 0.53000, 0.48500,
0.44000, 0.39750, 0.35750, 0.32000, 0.28500, 0.25250, 0.22250, 0.19500,
0.17000, 0.14750, 0.12750, 0.10750, 0.09250, 0.07750, 0.06500, 0.05500,
0.04500, 0.03750, 0.03000, 0.02500, 0.02000, 0.01500, 0.01250, 0.01000,
0.00750, 0.00500, 0.00500, 0.00250, 0.00250, 0.00250, 0.00250,
rep(0.00024, 47)),
c(seq(93.25, 93.875, 0.125),  seq(93.9375, 98.8125, 0.0625),
seq(98.875, 99.5, 0.125)),
c(0.0025, 0.0050, 0.0075, 0.0125, 0.0175, 0.0300, 0.0350, 0.0425, 0.0525,
0.0625, 0.0750, 0.0900, 0.1050, 0.1225, 0.1425, 0.1650, 0.1900, 0.2175,
0.2450, 0.2775, 0.3125, 0.3500, 0.3875, 0.4300, 0.4725, 0.5175, 0.5675,
0.6150, 0.6675, 0.7200, 0.7750, 0.8300, 0.8850, 0.9425, 1.0025, 1.0625,
1.1225, 1.1825, 1.2425, 1.3050, 1.3675, 1.4300, 1.4925, 1.5550, 1.6175,
1.6800, 1.7425, 1.8050, 1.8675, 1.9300, 1.9925, 2.0550, 2.1175, 2.1800,
2.2425, 2.3050, 2.3675, 2.4300, 2.4925, 2.5550, 2.6175, 2.6800, 2.7425,
2.8050, 2.8675, 2.9300, 2.9925, 3.0550, 3.1175, 3.1800, 3.2425, 3.3050,
3.3675, 3.4300, 3.4925, 3.5550, 3.6175, 3.6800, 3.7425, 3.8050, 3.8675,
3.9300, 3.9925, 4.0550, 4.1175, 4.1800, 4.3050, 4.4300, 4.5550, 4.6800,
4.8050),
c(seq(93.25, 93.875, 0.125),  seq(93.9375, 98.8125, 0.0625),
seq(98.875, 99.5, 0.125)),
2,
0.0537,
1,
3,
94.7,
as.Date("2024-02-29"),
as.Date("2024-02-25"),
as.Date("2023-12-18"),
"fed_fund_rate",
"USD")
#> $params
#>            [,1]
#> [1,] 4.55465456
#> [2,] 4.54735937
#> [3,] 0.00530515
#> [4,] 0.00555419
#> [5,] 0.45000375
#> attr(,"names")
#> [1] "m1"  "m2"  "s1"  "s2"  "pi1"
#> 
#> $discretized_rnd
#> # A tibble: 10,015 × 2
#>    domain      rnd
#>     <dbl>    <dbl>
#>  1   90.5 1.23e-13
#>  2   90.5 1.25e-13
#>  3   90.5 1.27e-13
#>  4   90.5 1.28e-13
#>  5   90.5 1.30e-13
#>  6   90.5 1.32e-13
#>  7   90.5 1.34e-13
#>  8   90.5 1.36e-13
#>  9   90.5 1.39e-13
#> 10   90.5 1.41e-13
#> # ℹ 10,005 more rows
#> 
#> $discretized_cdf
#> # A tibble: 10,015 × 2
#>    domain      cdf
#>     <dbl>    <dbl>
#>  1   90.5 7.98e-15
#>  2   90.5 8.10e-15
#>  3   90.5 8.23e-15
#>  4   90.5 8.36e-15
#>  5   90.5 8.49e-15
#>  6   90.5 8.62e-15
#>  7   90.5 8.75e-15
#>  8   90.5 8.89e-15
#>  9   90.5 9.03e-15
#> 10   90.5 9.16e-15
#> # ℹ 10,005 more rows
#> 
#> $CV
#> [1] 0
#> 
#> $moments
#>          mean        stddev      skewness      kurtosis 
#> 94.6952305688  0.6195098073 -0.0002829645  2.8051083501 
#> 
#> $mode
#> [1] 94.69638
#> 
#> $quantiles
#>       q0.1     q0.5       q1       q5      q10      q25      q50      q75
#> 1 91.73288 93.14838 93.28988 93.67838 93.89238 94.26488 94.69538 95.12588
#>        q90      q95      q99    q99.5    q99.9
#> 1 95.49738 95.71138 96.10088 96.24238 97.84338
#> 
#> $model_prices
#> $model_prices$model_call_price
#>  [1] 1.446733e+00 1.323138e+00 1.200595e+00 1.079686e+00 9.611771e-01
#>  [6] 8.460129e-01 7.900207e-01 7.352796e-01 6.819366e-01 6.301377e-01
#> [11] 5.800255e-01 5.317360e-01 4.853962e-01 4.411212e-01 3.990123e-01
#> [16] 3.591552e-01 3.216187e-01 2.864533e-01 2.536909e-01 2.233438e-01
#> [21] 1.954051e-01 1.698483e-01 1.466280e-01 1.256804e-01 1.069239e-01
#> [26] 9.026107e-02 7.557992e-02 6.275603e-02 5.165504e-02 4.213530e-02
#> [31] 3.405082e-02 2.725420e-02 2.159955e-02 1.694524e-02 1.315634e-02
#> [36] 1.010658e-02 7.679958e-03 5.771769e-03 4.289135e-03 3.151101e-03
#> [41] 2.288303e-03 1.642310e-03 1.164726e-03 8.161350e-04 5.649573e-04
#> [46] 3.863095e-04 2.609012e-04 1.740187e-04 1.146192e-04 7.454612e-05
#> [51] 4.787047e-05 3.034985e-05 1.899613e-05 1.173735e-05 7.158954e-06
#> [56] 4.310071e-06 2.561282e-06 1.502286e-06 8.696734e-07 4.968850e-07
#> [61] 2.801823e-07 1.559197e-07 8.563053e-08 4.641048e-08 2.482317e-08
#> [66] 1.310229e-08 6.824664e-09 3.507974e-09 1.779384e-09 8.906758e-10
#> [71] 4.399515e-10 2.144493e-10 1.031524e-10 4.896317e-11 2.293486e-11
#> [76] 1.060135e-11 4.835775e-12 2.176777e-12 9.669574e-13 4.238867e-13
#> [81] 1.833770e-13 7.828819e-14 3.298440e-14 1.371470e-14 5.627740e-15
#> [86] 2.279067e-15 3.592945e-16 5.374173e-17 7.627617e-18 1.027386e-18
#> [91] 1.313407e-19
#> 
#> $model_prices$model_put_price
#>  [1] 0.001502534 0.002907377 0.005364906 0.009455727 0.015946519 0.025782346
#>  [7] 0.032290126 0.040049074 0.049206014 0.059907105 0.072294901 0.086505468
#> [13] 0.102665656 0.120890628 0.141281722 0.163924661 0.188888142 0.216222766
#> [19] 0.245960296 0.278113206 0.312674489 0.349617735 0.388897472 0.430449792
#> [25] 0.474193316 0.520030503 0.567849351 0.617525462 0.668924468 0.721904735
#> [31] 0.776320256 0.832023631 0.888868980 0.946714676 1.005425769 1.064876009
#> [37] 1.124949390 1.185541200 1.246558566 1.307920533 1.369557734 1.431411741
#> [43] 1.493434158 1.555585566 1.617834389 1.680155741 1.742530332 1.804943450
#> [49] 1.867384050 1.929843977 1.992317302 2.054799781 2.117288427 2.179781169
#> [55] 2.242276590 2.304773741 2.367271993 2.429770934 2.492270301 2.554769928
#> [61] 2.617269711 2.679769587 2.742269517 2.804769478 2.867269456 2.929769444
#> [67] 2.992269438 3.054769435 3.117269433 3.179769432 3.242269432 3.304769431
#> [73] 3.367269431 3.429769431 3.492269431 3.554769431 3.617269431 3.679769431
#> [79] 3.742269431 3.804769431 3.867269431 3.929769431 3.992269431 4.054769431
#> [85] 4.117269431 4.179769431 4.304769431 4.429769431 4.554769431 4.679769431
#> [91] 4.804769431
#> 
#> 
#> $rnd_plot

#> 
#> $cdf_plot

ctd_bond_yield provides with the risk neutral density at options’ maturity of the yield to maturity of the Cheapest-to-Deliver Bond in a futures contract, using options on the government bond futures. The current CtD is assumed to be the CtD at futures’ maturity. This is achieved by considering a “term cash and carry relationship” between the Cheapest-to-Deliver Bond and the futures contract, holding constant the CtD repo rate at options’ maturity.

ctd_bond_yield(c(10.39,9.92,9.46,9.00,8.55,8.10,7.66,7.23,
6.81,6.39,5.98,5.58,5.20,4.82,4.46,4.10,3.76,3.44,3.13,2.83,2.56,
2.29,2.05,1.82,1.61,1.42,1.25,1.09,0.95,0.82,0.71,0.61,0.53,0.45,
0.38,0.33,0.28,0.23,0.20,0.17,0.14,0.12,0.10,0.08),
seq(106, 127.5, 0.5),
c(0.22,0.25,0.29,0.33,0.38,0.43,0.49,0.56,0.64,0.72,0.81,0.91,
1.03,1.15,1.29, 1.43,1.59,1.77,1.96,2.16,2.39,2.62,2.88,3.15,
3.44,3.75,4.08, 4.42,4.78,5.15,5.54,5.94,6.36,6.78,7.21,7.66,
8.11,8.56,9.03, 9.50,9.97,10.45,10.93,11.41),
seq(106, 127.5, 0.5),
2,
0.0344,
0.035,
1,
3,
0.893,
0.0435, 
as.Date("2033-11-01"),
2,
100,
2,
116.17,
as.Date("2024-12-10"),
as.Date("2024-11-22"),
as.Date("2024-06-14"),
"Italian",
"EUR")
#> $discretized_rnd
#> # A tibble: 62,805 × 2
#>     domain     rnd
#>      <dbl>   <dbl>
#>  1 0.00518 0.00327
#>  2 0.00518 0.00328
#>  3 0.00518 0.00328
#>  4 0.00519 0.00328
#>  5 0.00519 0.00328
#>  6 0.00519 0.00328
#>  7 0.00519 0.00328
#>  8 0.00519 0.00328
#>  9 0.00519 0.00329
#> 10 0.00519 0.00329
#> # ℹ 62,795 more rows
#> 
#> $discretized_cdf
#> # A tibble: 62,804 × 2
#>     domain           cdf
#>      <dbl>         <dbl>
#>  1 0.00518 0.00000000286
#>  2 0.00518 0.00000000572
#>  3 0.00519 0.00000000857
#>  4 0.00519 0.0000000114 
#>  5 0.00519 0.0000000143 
#>  6 0.00519 0.0000000172 
#>  7 0.00519 0.0000000200 
#>  8 0.00519 0.0000000229 
#>  9 0.00519 0.0000000258 
#> 10 0.00519 0.0000000286 
#> # ℹ 62,794 more rows
#> 
#> $CV
#> [1] 0
#> 
#> $moments
#>        mean      stddev    skewness    kurtosis 
#> 0.039163805 0.007595362 0.477981866 3.657946486 
#> 
#> $mode
#> [1] 0.03728708
#> 
#> $quantiles
#>         q0.1       q0.5         q1         q5       q10        q25        q50
#> 1 0.01170344 0.02082377 0.02294875 0.02797913 0.0303401 0.03411341 0.03843945
#>          q75        q90        q95        q99      q99.5      q99.9
#> 1 0.04350652 0.04927819 0.05303589 0.05996477 0.06248657 0.07305418
#> 
#> $rnd_y_plot

#> 
#> $cdf_y_plot

bond_fut_irr_ytm extracts in one go from options prices on a bond futures, for any bond in the delivery basket, the RND of its implied repo rate and the RND of its yield to maturity. To do so, the bond price at options’ maturity and the bond repo price at options’ maturity are both modeled with a mixture of two lognormal laws, with a dependency. Then, the “expected cash and carry relationship” at options’ maturity between the bond and the futures contract is introduced. The RND of the STIR futures contract of the same currency and approximate same maturity is used to set the initial values of the volatility of the log returns of the repo asset price in the optimization phase.

bond_fut_irr_ytm(
c(12.64, 12.14, 11.65, 11.15, 10.65, 10.15, 9.65,
9.16, 8.66, 8.16, 7.67,  7.17, 6.68, 6.19, 5.70, 5.21, 4.73, 4.25,
3.78, 3.32, 2.87, 2.45, 2.05, 1.67, 1.33, 1.03, 0.77, 0.57, 0.41,
0.29, 0.21, 0.15, 0.10, 0.07, 0.06, 0.04, 0.04, 0.03, 0.02, 0.02,
0.02, 0.02, 0.01, 0.01, 0.01, 0.01, 0.01),
c(seq(114, 136.5, 0.5), 137.5),
c(0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 0.02, 0.03, 0.03, 0.03, 0.04,
0.04, 0.05, 0.06, 0.07, 0.08, 0.10, 0.12, 0.15, 0.19, 0.24, 0.32,
0.42, 0.54, 0.70, 0.90, 1.14, 1.44, 1.78, 2.16, 2.58, 3.02, 3.47,
3.94, 4.43, 4.91, 5.41, 5.90, 6.39, 6.89, 7.39, 7.89, 8.38, 8.88,
9.38, 9.88, 10.88),
c(seq(114, 136.5, 0.5), 137.5),
c(1.704999924, 1.579999924, 1.454999924, 1.329999924, 1.204999924,
1.079999924, 0.954999983, 0.892499983, 0.829999983, 0.767499983,
0.704999983, 0.642499983, 0.582499981, 0.519999981, 0.457499981,
0.397499979, 0.334999979, 0.275000006, 0.217500001, 0.162499994,
0.112499997, 0.072499998, 0.039999999, 0.02, 0.0075, 0.0025, 0.0025,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c(seq(95.75, 96.5, 0.125), seq(96.5625, 98.75, 0.0625),
seq(98.875, 99.5, 0.125)),
c(0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0.0025,  0.0025,
0.0025,  0.005, 0.005,  0.0075,  0.012499999,  0.02, 0.029999999,
0.055, 0.085000001, 0.127499998, 0.177499995, 0.234999999,
0.297499985, 0.357499987, 0.419999987, 0.482499987, 0.544999957,
0.607499957, 0.669999957, 0.732499957, 0.794999957, 0.857499957,
0.919999957, 0.982499957, 1.044999957, 1.107499957, 1.169999957,
1.232499957, 1.294999957, 1.419999957, 1.544999957, 1.669999957,
1.794999957, 1.919999957, 2.044999838),
c(seq(95.75, 96.5, 0.125), seq(96.5625, 98.75, 0.0625),
seq(98.875, 99.5, 0.125)),
0.0224,
0.0224,
0.02232,
1,
3,
126.66,
0.026,
1,
0.770088,
2,
bond_N = 100,
as.Date("2035-08-15"),
as.Date("2026-09-08"),
as.Date("2026-08-21"),
3,
97.45,
as.Date("2026-09-14"),
as.Date("2026-08-14"),
as.Date("2026-06-17"),
"Germany",
"EUR",
3)
#> $params_bond.unlist.marginal_bond.
#> [1] 4.58214865 4.57086550 0.01517421 0.03952575 0.85488940
#> 
#> $params_repo.unlist.marginal_repo.
#> [1] 9.778192e-04 9.778944e-04 3.978375e-05 3.889822e-05 9.353457e-01
#> 
#> $moments_ytm
#>        mean      stddev    skewness    kurtosis 
#> 0.029160621 0.002660984 0.654021547 6.935772091 
#> 
#> $mode_ytm
#> [1] 0.02895401
#> 
#> $qt_y
#>         q0.1       q0.5         q1         q5        q10        q25        q50
#> 1 0.01478166 0.02125477 0.02280126 0.02537977 0.02627421 0.02760882 0.02903297
#>          q75        q90        q95        q99      q99.5      q99.9
#> 1 0.03050446 0.03204357 0.03334461 0.03788146 0.03961175 0.04625169
#> 
#> $discretized_rnd_ytm
#> # A tibble: 24,002 × 2
#>    domain    rnd
#>     <dbl>  <dbl>
#>  1 0.0148 0.0848
#>  2 0.0148 0.0848
#>  3 0.0148 0.0849
#>  4 0.0148 0.0849
#>  5 0.0148 0.0850
#>  6 0.0148 0.0851
#>  7 0.0148 0.0851
#>  8 0.0148 0.0852
#>  9 0.0148 0.0852
#> 10 0.0148 0.0853
#> # ℹ 23,992 more rows
#> 
#> $rnd_plot_ytm

#> 
#> $cdf_plot_ytm

#> 
#> $moments_repo
#>          mean        stddev      skewness      kurtosis 
#>  1.982810e-02  8.055773e-04 -1.028538e-05  3.000354e+00 
#> 
#> $mode_repo
#> [1] 0.01982469
#> 
#> $qt_repo
#>          q0.1       q0.5        q1         q5        q10        q25        q50
#> 1 0.003164184 0.01774486 0.0179503 0.01849948 0.01879353 0.01928092 0.01982604
#>          q75        q90        q95       q99      q99.5     q99.9
#> 1 0.02036845 0.02085849 0.02114983 0.0217016 0.02190432 0.2231573
#> 
#> $discretized_rnd_repo
#> # A tibble: 82,304 × 2
#>     domain      rnd
#>      <dbl>    <dbl>
#>  1 0.00317 1.18e-90
#>  2 0.00317 1.26e-90
#>  3 0.00317 1.35e-90
#>  4 0.00317 1.45e-90
#>  5 0.00318 1.55e-90
#>  6 0.00318 1.66e-90
#>  7 0.00318 1.78e-90
#>  8 0.00319 1.90e-90
#>  9 0.00319 2.04e-90
#> 10 0.00319 2.18e-90
#> # ℹ 82,294 more rows
#> 
#> $rnd_plot_repo

#> 
#> $cdf_plot_repo

#> 
#> $correl_b_r
#> [1] 0.09720004
#> 
#> $CV
#> [1] 0
#> 
#> $model_prices.model_call_price
#>  [1] 12.642295910 12.142978720 11.643891648 11.145097568 10.646671701
#>  [6] 10.148702665  9.651293248  9.154560839  8.658637450  8.163669406
#> [11]  7.669817034  7.177255410  6.686178691  6.196813362  5.709450132
#> [16]  5.224509586  4.742660454  4.265006393  3.793340896  3.330436742
#> [21]  2.880291149  2.448208839  2.040600016  1.664422019  1.326301780
#> [26]  1.031506515  0.783023270  0.581010940  0.422787128  0.303345016
#> [31]  0.216234385  0.154552523  0.111801823  0.082459894  0.062224509
#> [36]  0.047990144  0.037659264  0.029891041  0.023861281  0.019071225
#> [41]  0.015213892  0.012090009  0.009559678  0.007516640  0.005875359
#> [46]  0.004564717  0.002705203
#> 
#> $model_prices.model_put_price
#>  [1]  0.001732142  0.002414953  0.003327880  0.004533800  0.006107934
#>  [6]  0.008138897  0.010729480  0.013997071  0.018073682  0.023105638
#> [11]  0.029253266  0.036691642  0.045614924  0.056249595  0.068886365
#> [16]  0.083945818  0.102096687  0.124442625  0.152777129  0.189872975
#> [21]  0.239727381  0.307645071  0.400036249  0.523858251  0.685738012
#> [26]  0.890942747  1.142459502  1.440447172  1.782223360  2.162781248
#> [31]  2.575670617  3.013988756  3.471238055  3.941896126  4.421660741
#> [36]  4.907426376  5.397095496  5.889327273  6.383297513  6.878507458
#> [41]  7.374650125  7.871526242  8.368995910  8.866952872  9.365311591
#> [46]  9.864000949 10.862141435

proba_ctd_opt calculates, for each bond in the delivery basket of a government bond futures contact, its probability to be the cheapest to deliver bond at options’ maturity, relying successively on a ranking of the net basis and on a raking of the implied repo rate of each bond in the delivery basket at options’ maturity

proba_ctd_opt( c(24.10, 23.10, 22.12, 21.12, 20.12, 19.14, 18.14, 17.16, 16.18, 15.20,
14.22, 13.24, 12.28, 11.32, 10.36, 9.44, 8.50, 7.60, 6.72, 5.86, 5.04, 4.28,
3.56, 2.88, 2.30, 1.78,  1.36, 1.02, 0.76, 0.56, 0.42, 0.30, 0.22, 0.18, 0.14,
0.10,  0.08, 0.06, 0.06, 0.04, 0.04, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02),
seq(85, 131),
c(0.02,  0.02, 0.02, 0.02, 0.02, 0.04, 0.04, 0.06, 0.08, 0.10, 0.12, 0.14, 0.18, 0.22,
0.26, 0.34,  0.40, 0.50, 0.62, 0.76, 0.94, 1.18, 1.46, 1.78, 2.20, 2.68, 3.26, 3.92,
4.66,  5.46, 6.32, 7.20, 8.12, 9.08, 10.04, 11.00, 11.98, 12.96, 13.96, 14.94, 15.94,
16.92, 17.92, 18.92, 19.92, 20.92, 21.92),
seq(85, 131),
2,
0.0187,
0.019,
1,
3,
as.Date("2054-08-15"),
109.1,
as.Date("2026-09-08"),
as.Date("2026-08-21"),
as.Date("2026-05-28"),
c("DE0001102572", "DE0001102614", "DE0001030757", "DE000BU2D004", "DE000BU2D012"),
c(0.000, 0.018, 0.018, 0.025, 0.029),
rep(1, 5),
as.Date(c("2052-08-15", "2053-08-15", "2053-08-15", "2054-08-15", "2056-08-15")),
100,
c(0.361698, 0.641260, 0.641260, 0.750372, 0.809987),
c(0.03500, 0.03507, 0.03492, 0.03510, 0.03514),
2)
#>           ISIN proba_ctd_min_net_basis proba_ctd_max_irr
#> 1 DE000BU2D004                   0.586             0.586
#> 2 DE000BU2D012                   0.354             0.355
#> 3 DE0001102572                   0.060             0.059
#> 4 DE0001102614                   0.000             0.000
#> 5 DE0001030757                   0.000             0.000