Title: | Financial Engineering in R |
---|---|
Description: | R implementations of standard financial engineering codes; vanilla option pricing models such as Black-Scholes, Bachelier, CEV, and SABR. |
Authors: | Jaehyuk Choi [aut, cre] |
Maintainer: | Jaehyuk Choi <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.94 |
Built: | 2025-03-12 04:28:49 UTC |
Source: | https://github.com/pyfe/fe-r |
Calculate Bachelier model implied volatility
BachelierImpvol( price, strike = forward, spot, texp = 1, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
BachelierImpvol( price, strike = forward, spot, texp = 1, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
price |
(vector of) option price |
strike |
(vector of) strike price |
spot |
(vector of) spot price |
texp |
(vector of) time to expiry |
intr |
interest rate (domestic interest rate) |
divr |
dividend/convenience yield (foreign interest rate) |
cp |
call/put sign. |
forward |
forward price. If given, |
df |
discount factor. If given, |
Bachelier implied volatility
Choi, J., Kim, K., & Kwak, M. (2009). Numerical Approximation of the Implied Volatility Under Arithmetic Brownian Motion. Applied Mathematical Finance, 16(3), 261-268. doi:10.1080/13504860802583436
spot <- 100 strike <- 100 texp <- 1.2 sigma <- 20 intr <- 0.05 price <- 20 FER::BachelierImpvol(price, strike, spot, texp, intr=intr)
spot <- 100 strike <- 100 texp <- 1.2 sigma <- 20 intr <- 0.05 price <- 20 FER::BachelierImpvol(price, strike, spot, texp, intr=intr)
Calculate Bachelier model option price
BachelierPrice( strike = forward, spot, texp = 1, sigma, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
BachelierPrice( strike = forward, spot, texp = 1, sigma, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
strike |
(vector of) strike price |
spot |
(vector of) spot price |
texp |
(vector of) time to expiry |
sigma |
(vector of) volatility |
intr |
interest rate (domestic interest rate) |
divr |
dividend/convenience yield (foreign interest rate) |
cp |
call/put sign. |
forward |
forward price. If given, |
df |
discount factor. If given, |
option price
Choi, J., Kim, K., & Kwak, M. (2009). Numerical Approximation of the Implied Volatility Under Arithmetic Brownian Motion. Applied Mathematical Finance, 16(3), 261-268. doi:10.1080/13504860802583436
spot <- 100 strike <- seq(80,125,5) texp <- 1.2 sigma <- 20 intr <- 0.05 FER::BachelierPrice(strike, spot, texp, sigma, intr=intr)
spot <- 100 strike <- seq(80,125,5) texp <- 1.2 sigma <- 20 intr <- 0.05 FER::BachelierPrice(strike, spot, texp, sigma, intr=intr)
Calculate Black-Scholes implied volatility
BlackScholesImpvol( price, strike = forward, spot, texp = 1, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
BlackScholesImpvol( price, strike = forward, spot, texp = 1, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
price |
(vector of) option price |
strike |
(vector of) strike price |
spot |
(vector of) spot price |
texp |
(vector of) time to expiry |
intr |
interest rate (domestic interest rate) |
divr |
dividend/convenience yield (foreign interest rate) |
cp |
call/put sign. |
forward |
forward price. If given, |
df |
discount factor. If given, |
Black-Scholes implied volatility
Giner, G., & Smyth, G. K. (2016). statmod: Probability Calculations for the Inverse Gaussian Distribution. The R Journal, 8(1), 339-351. doi:10.32614/RJ-2016-024
spot <- 100 strike <- 100 texp <- 1.2 sigma <- 0.2 intr <- 0.05 price <- 20 FER::BlackScholesImpvol(price, strike, spot, texp, intr=intr)
spot <- 100 strike <- 100 texp <- 1.2 sigma <- 0.2 intr <- 0.05 price <- 20 FER::BlackScholesImpvol(price, strike, spot, texp, intr=intr)
Calculate Black-Scholes option price
BlackScholesPrice( strike = forward, spot, texp = 1, sigma, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
BlackScholesPrice( strike = forward, spot, texp = 1, sigma, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
strike |
(vector of) strike price |
spot |
(vector of) spot price |
texp |
(vector of) time to expiry |
sigma |
(vector of) volatility |
intr |
interest rate (domestic interest rate) |
divr |
dividend/convenience yield (foreign interest rate) |
cp |
call/put sign. |
forward |
forward price. If given, |
df |
discount factor. If given, |
option price
Black, F., & Scholes, M. (1973). The Pricing of Options and Corporate Liabilities. Journal of Political Economy, 81(3), 637-654. doi:10.1086/260062
Black, F. (1976). The pricing of commodity contracts. Journal of Financial Economics, 3(1), 167-179. doi:10.1016/0304-405X(76)90024-6
https://en.wikipedia.org/wiki/Black-Scholes_model
spot <- 100 strike <- seq(80,125,5) texp <- 1.2 sigma <- 0.2 intr <- 0.05 FER::BlackScholesPrice(strike, spot, texp, sigma, intr=intr)
spot <- 100 strike <- seq(80,125,5) texp <- 1.2 sigma <- 0.2 intr <- 0.05 FER::BlackScholesPrice(strike, spot, texp, sigma, intr=intr)
Calculate the mass at zero under the CEV model
CevMassZero( spot, texp = 1, sigma, beta = 0.5, intr = 0, divr = 0, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
CevMassZero( spot, texp = 1, sigma, beta = 0.5, intr = 0, divr = 0, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
spot |
(vector of) spot price |
texp |
(vector of) time to expiry |
sigma |
(vector of) volatility |
beta |
beta |
intr |
interest rate |
divr |
dividend rate |
forward |
forward price. If given, |
df |
discount factor. If given, |
mass at zero
spot <- 100 texp <- 1.2 beta <- 0.5 sigma <- 2 FER::CevMassZero(spot, texp, sigma, beta)
spot <- 100 texp <- 1.2 beta <- 0.5 sigma <- 2 FER::CevMassZero(spot, texp, sigma, beta)
Calculate the constant elasticity of variance (CEV) model option price
CevPrice( strike = forward, spot, texp = 1, sigma, beta = 0.5, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
CevPrice( strike = forward, spot, texp = 1, sigma, beta = 0.5, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
strike |
(vector of) strike price |
spot |
(vector of) spot price |
texp |
(vector of) time to expiry |
sigma |
(vector of) volatility |
beta |
elasticity parameter |
intr |
interest rate (domestic interest rate) |
divr |
dividend/convenience yield (foreign interest rate) |
cp |
call/put sign. |
forward |
forward price. If given, |
df |
discount factor. If given, |
option price
Schroder, M. (1989). Computing the constant elasticity of variance option pricing formula. Journal of Finance, 44(1), 211-219. doi:10.1111/j.1540-6261.1989.tb02414.x
spot <- 100 strike <- seq(80,125,5) texp <- 1.2 beta <- 0.5 sigma <- 2 FER::CevPrice(strike, spot, texp, sigma, beta)
spot <- 100 strike <- seq(80,125,5) texp <- 1.2 beta <- 0.5 sigma <- 2 FER::CevPrice(strike, spot, texp, sigma, beta)
Calculate the option price under the NSVh model with lambda=1 (Choi et al. 2019)
Nsvh1Choi2019( strike = forward, spot, texp = 1, sigma, vov = 0, rho = 0, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
Nsvh1Choi2019( strike = forward, spot, texp = 1, sigma, vov = 0, rho = 0, intr = 0, divr = 0, cp = 1L, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
strike |
(vector of) strike price |
spot |
(vector of) spot price |
texp |
(vector of) time to expiry |
sigma |
(vector of) volatility |
vov |
(vector of) vol-of-vol |
rho |
(vector of) correlation |
intr |
interest rate |
divr |
dividend rate |
cp |
call/put sign. |
forward |
forward price. If given, |
df |
discount factor. If given, |
BS volatility or option price based on cp
Choi, J., Liu, C., & Seo, B. K. (2019). Hyperbolic normal stochastic volatility model. Journal of Futures Markets, 39(2), 186–204. doi:10.1002/fut.21967
spot <- 100 strike <- seq(80,125,5) texp <- 1.2 sigma <- 20 vov <- 0.2 rho <- -0.5 strike <- seq(0.1, 2, 0.1) FER::Nsvh1Choi2019(strike, spot, texp, sigma, vov, rho)
spot <- 100 strike <- seq(80,125,5) texp <- 1.2 sigma <- 20 vov <- 0.2 rho <- -0.5 strike <- seq(0.1, 2, 0.1) FER::Nsvh1Choi2019(strike, spot, texp, sigma, vov, rho)
Calculate the equivalent BS volatility (Hagan et al. 2002) for the Stochatic-Alpha-Beta-Rho (SABR) model
SabrHagan2002( strike = forward, spot, texp = 1, sigma, vov = 0, rho = 0, beta = 1, intr = 0, divr = 0, cp = NULL, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
SabrHagan2002( strike = forward, spot, texp = 1, sigma, vov = 0, rho = 0, beta = 1, intr = 0, divr = 0, cp = NULL, forward = spot * exp(-divr * texp)/df, df = exp(-intr * texp) )
strike |
(vector of) strike price |
spot |
(vector of) spot price |
texp |
(vector of) time to expiry |
sigma |
(vector of) volatility |
vov |
(vector of) vol-of-vol |
rho |
(vector of) correlation |
beta |
(vector of) beta |
intr |
interest rate (domestic interest rate) |
divr |
convenience rate (foreign interest rate) |
cp |
call/put sign. |
forward |
forward price. If given, |
df |
discount factor. If given, |
BS volatility or option price based on cp
Hagan, P. S., Kumar, D., Lesniewski, A. S., & Woodward, D. E. (2002). Managing Smile Risk. Wilmott, September, 84-108.
sigma <- 0.25 vov <- 0.3 rho <- -0.8 beta <- 0.3 texp <- 10 strike <- seq(0.1, 2, 0.1) FER::SabrHagan2002(strike, 1, texp, sigma, vov, rho, beta) FER::SabrHagan2002(strike, 1, texp, sigma, vov, rho, beta, cp=1)
sigma <- 0.25 vov <- 0.3 rho <- -0.8 beta <- 0.3 texp <- 10 strike <- seq(0.1, 2, 0.1) FER::SabrHagan2002(strike, 1, texp, sigma, vov, rho, beta) FER::SabrHagan2002(strike, 1, texp, sigma, vov, rho, beta, cp=1)
The payout of the spread option is
max(S1_T - S2_T - K, 0)
where S1_T
and S2_T
are the
prices at expiry T
of assets 1 and 2 respectively and K
is
the strike price.
SpreadBachelier( strike = 0, spot1, spot2, texp = 1, sigma1, sigma2, corr, intr = 0, divr1 = 0, divr2 = 0, cp = 1L, forward1 = spot1 * exp(-divr1 * texp)/df, forward2 = spot2 * exp(-divr2 * texp)/df, df = exp(-intr * texp) )
SpreadBachelier( strike = 0, spot1, spot2, texp = 1, sigma1, sigma2, corr, intr = 0, divr1 = 0, divr2 = 0, cp = 1L, forward1 = spot1 * exp(-divr1 * texp)/df, forward2 = spot2 * exp(-divr2 * texp)/df, df = exp(-intr * texp) )
strike |
(vector of) strike price |
spot1 |
(vector of) spot price of asset 1 |
spot2 |
(vector of) spot price of asset 2 |
texp |
(vector of) time to expiry |
sigma1 |
(vector of) Bachelier volatility of asset 1 |
sigma2 |
(vector of) Bachelier volatility of asset 2 |
corr |
correlation |
intr |
interest rate |
divr1 |
dividend rate of asset 1 |
divr2 |
dividend rate of asset 2 |
cp |
call/put sign. |
forward1 |
forward price of asset 1. If given, overrides |
forward2 |
forward price of asset 2. If given, overrides |
df |
discount factor. If given, |
option price
FER::SpreadBachelier((-2:2)*10, 100, 120, 1.3, 20, 36, -0.5)
FER::SpreadBachelier((-2:2)*10, 100, 120, 1.3, 20, 36, -0.5)
The payout of the spread option is
max(S1_T - S2_T - K, 0)
where S1_T
and S2_T
are the
prices at expiry T
of assets 1 and 2 respectively and K
is
the strike price.
SpreadBjerksund2014( strike = 0, spot1, spot2, texp = 1, sigma1, sigma2, corr, intr = 0, divr1 = 0, divr2 = 0, cp = 1L, forward1 = spot1 * exp(-divr1 * texp)/df, forward2 = spot2 * exp(-divr2 * texp)/df, df = exp(-intr * texp) )
SpreadBjerksund2014( strike = 0, spot1, spot2, texp = 1, sigma1, sigma2, corr, intr = 0, divr1 = 0, divr2 = 0, cp = 1L, forward1 = spot1 * exp(-divr1 * texp)/df, forward2 = spot2 * exp(-divr2 * texp)/df, df = exp(-intr * texp) )
strike |
(vector of) strike price |
spot1 |
(vector of) spot price of asset 1 |
spot2 |
(vector of) spot price of asset 2 |
texp |
(vector of) time to expiry |
sigma1 |
(vector of) volatility of asset 1 |
sigma2 |
(vector of) volatility of asset 2 |
corr |
correlation |
intr |
interest rate |
divr1 |
dividend rate of asset 1 |
divr2 |
dividend rate of asset 2 |
cp |
call/put sign. |
forward1 |
forward price of asset 1. If given, overrides |
forward2 |
forward price of asset 2. If given, overrides |
df |
discount factor. If given, |
option price
Bjerksund, P., & Stensland, G. (2014). Closed form spread option valuation. Quantitative Finance, 14(10), 1785–1794. doi:10.1080/14697688.2011.617775
FER::SpreadBjerksund2014((-2:2)*10, 100, 120, 1.3, 0.2, 0.3, -0.5)
FER::SpreadBjerksund2014((-2:2)*10, 100, 120, 1.3, 0.2, 0.3, -0.5)
The payout of the spread option is
max(S1_T - S2_T - K, 0)
where S1_T
and S2_T
are the
prices at expiry T
of assets 1 and 2 respectively and K
is
the strike price.
SpreadKirk( strike = 0, spot1, spot2, texp = 1, sigma1, sigma2, corr, intr = 0, divr1 = 0, divr2 = 0, cp = 1L, forward1 = spot1 * exp(-divr1 * texp)/df, forward2 = spot2 * exp(-divr2 * texp)/df, df = exp(-intr * texp) )
SpreadKirk( strike = 0, spot1, spot2, texp = 1, sigma1, sigma2, corr, intr = 0, divr1 = 0, divr2 = 0, cp = 1L, forward1 = spot1 * exp(-divr1 * texp)/df, forward2 = spot2 * exp(-divr2 * texp)/df, df = exp(-intr * texp) )
strike |
(vector of) strike price |
spot1 |
(vector of) spot price of asset 1 |
spot2 |
(vector of) spot price of asset 2 |
texp |
(vector of) time to expiry |
sigma1 |
(vector of) volatility of asset 1 |
sigma2 |
(vector of) volatility of asset 2 |
corr |
correlation |
intr |
interest rate |
divr1 |
dividend rate of asset 1 |
divr2 |
dividend rate of asset 2 |
cp |
call/put sign. |
forward1 |
forward price of asset 1. If given, overrides |
forward2 |
forward price of asset 2. If given, overrides |
df |
discount factor. If given, |
option price
Kirk, E. (1995). Correlation in the energy markets. In Managing Energy Price Risk (First, pp. 71–78). Risk Publications.
FER::SpreadKirk((-2:2)*10, 100, 120, 1.3, 0.2, 0.3, -0.5)
FER::SpreadKirk((-2:2)*10, 100, 120, 1.3, 0.2, 0.3, -0.5)
The payout of the exchange option is
max(S1_T - S2_T, 0)
where S1_T
and S2_T
are the
prices at expiry T
of assets 1 and 2 respectively.
SwitchMargrabe( spot1, spot2, texp = 1, sigma1, sigma2, corr, intr = 0, divr1 = 0, divr2 = 0, cp = 1L, forward1 = spot1 * exp(-divr1 * texp)/df, forward2 = spot2 * exp(-divr2 * texp)/df, df = exp(-intr * texp) )
SwitchMargrabe( spot1, spot2, texp = 1, sigma1, sigma2, corr, intr = 0, divr1 = 0, divr2 = 0, cp = 1L, forward1 = spot1 * exp(-divr1 * texp)/df, forward2 = spot2 * exp(-divr2 * texp)/df, df = exp(-intr * texp) )
spot1 |
(vector of) spot price of asset 1 |
spot2 |
(vector of) spot price of asset 2 |
texp |
(vector of) time to expiry |
sigma1 |
(vector of) volatility of asset 1 |
sigma2 |
(vector of) volatility of asset 2 |
corr |
correlation |
intr |
interest rate |
divr1 |
dividend rate of asset 1 |
divr2 |
dividend rate of asset 2 |
cp |
call/put sign. |
forward1 |
forward price of asset 1. If given, overrides |
forward2 |
forward price of asset 2. If given, overrides |
df |
discount factor. If given, |
option price
Margrabe, W. (1978). The value of an option to exchange one asset for another. The Journal of Finance, 33(1), 177–186.
FER::SwitchMargrabe(100, 120, 1.3, 0.2, 0.3, -0.5)
FER::SwitchMargrabe(100, 120, 1.3, 0.2, 0.3, -0.5)