Reference Every exported name
API reference
Pricing
FinancialToolbox.blsprice — Function
blsprice(S0, K, r, T, σ, d, FlagIsCall = true)Price of a European option in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blsprice(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
1.1023600107733187
julia> blsprice(10.0, 10.0, 0.01, 2.0, 0.2, 0.01, false)
1.1023600107733194FinancialToolbox.blkprice — Function
blkprice(F0, K, r, T, σ, FlagIsCall = true)Price of a European option on a forward in the Black model.
Arguments
F0: forward price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blkprice(10.0, 10.0, 0.01, 2.0, 0.2)
1.1023600107733187FinancialToolbox.blsbin — Function
blsbin(S0, K, r, T, σ, d, FlagIsCall = true)Price of a binary (cash-or-nothing) European option paying 1 in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blsbin(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
0.4349813361147117Barrier options
FinancialToolbox.blsdownout — Function
blsdownout(S0, K, r, T, σ, d, H, FlagIsCall = true)Price of a down-and-out European option in the Black and Scholes model: the option is knocked out if the underlying ever goes below the barrier H, monitored continuously, without rebate.
Arguments
S0: spot price of the underlying, above the barrier.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.H: barrier, positive and belowS0.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blsdownout(10.0, 10.0, 0.01, 2.0, 0.2, 0.01, 8.0)
1.0349806169570723FinancialToolbox.blsdownin — Function
blsdownin(S0, K, r, T, σ, d, H, FlagIsCall = true)Price of a down-and-in European option in the Black and Scholes model: the option is activated if the underlying ever goes below the barrier H, monitored continuously, without rebate. It is the European option minus the down-and-out one.
Arguments
S0: spot price of the underlying, above the barrier.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.H: barrier, positive and belowS0.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blsdownin(10.0, 10.0, 0.01, 2.0, 0.2, 0.01, 8.0, false)
1.005956123316791See also blsdownout, blsupin, blsprice.
FinancialToolbox.blsupout — Function
blsupout(S0, K, r, T, σ, d, H, FlagIsCall = true)Price of an up-and-out European option in the Black and Scholes model: the option is knocked out if the underlying ever goes above the barrier H, monitored continuously, without rebate.
Arguments
S0: spot price of the underlying, below the barrier.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.H: barrier, aboveS0.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blsupout(10.0, 10.0, 0.01, 2.0, 0.2, 0.01, 12.0, false)
0.9741004570291205See also blsupin, blsdownout, blsprice.
FinancialToolbox.blsupin — Function
blsupin(S0, K, r, T, σ, d, H, FlagIsCall = true)Price of an up-and-in European option in the Black and Scholes model: the option is activated if the underlying ever goes above the barrier H, monitored continuously, without rebate. It is the European option minus the up-and-out one.
Arguments
S0: spot price of the underlying, below the barrier.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.H: barrier, aboveS0.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blsupin(10.0, 10.0, 0.01, 2.0, 0.2, 0.01, 12.0)
1.0537786287548607Sensitivities
FinancialToolbox.blsdelta — Function
blsdelta(S0, K, r, T, σ, d, FlagIsCall = true)Delta, the derivative of the price with respect to S0, of a European option in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blsdelta(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
0.5452173371920436See also blsprice.
FinancialToolbox.blsgamma — Function
blsgamma(S0, K, r, T, σ, d, FlagIsCall = true)Gamma, the second derivative of the price with respect to S0, of a European option in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put; the gamma is the same for both.
Example
julia> blsgamma(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
0.1368788153571282See also blsprice.
FinancialToolbox.blsvega — Function
blsvega(S0, K, r, T, σ, d, FlagIsCall = true)Vega, the derivative of the price with respect to σ, of a European option in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put; the vega is the same for both.
Example
julia> blsvega(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
5.47515261428513See also blsprice.
FinancialToolbox.blsrho — Function
blsrho(S0, K, r, T, σ, d, FlagIsCall = true)Rho, the derivative of the price with respect to r, of a European option in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blsrho(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
8.699626722294234See also blsprice.
FinancialToolbox.blstheta — Function
blstheta(S0, K, r, T, σ, d, FlagIsCall = true)Theta, minus the derivative of the price with respect to T, of a European option in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blstheta(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
-0.2627340306065233See also blsprice.
FinancialToolbox.blslambda — Function
blslambda(S0, K, r, T, σ, d, FlagIsCall = true)Lambda, the elasticity Δ S0 / price, of a European option in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blslambda(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
4.945909973725978See also blsprice.
FinancialToolbox.blspsi — Function
blspsi(S0, K, r, T, σ, d, FlagIsCall = true)Psi, the derivative of the price with respect to d, of a European option in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put.
Example
julia> blspsi(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
-10.904346743840872See also blsprice.
FinancialToolbox.blsvanna — Function
blsvanna(S0, K, r, T, σ, d, FlagIsCall = true)Vanna, the derivative of the delta with respect to σ, of a European option in the Black and Scholes model.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.σ: implied volatility.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put; the vanna is the same for both.
Example
julia> blsvanna(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
0.2737576307142565See also blsprice.
Implied volatility
FinancialToolbox.blsimpv — Function
blsimpv(S0, K, r, T, Price, d, FlagIsCall = true, xtol = 100eps(Float64), n_iter_max = 4)Implied volatility of a European option in the Black and Scholes model: the σ such that blsprice(S0, K, r, T, σ, d, FlagIsCall) == Price.
It is computed with the 2024 version of Peter Jäckel's Let's Be Rational, accurate to the attainable machine precision for any moneyness, maturity and volatility.
Arguments
S0: spot price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.Price: price of the option.d: continuously compounded dividend yield of the underlying.FlagIsCall:truefor a call,falsefor a put.xtol: relative tolerance of the Newton iteration that computes the implied volatility of complex inputs: it stops when a step is smaller thanxtoltimes the volatility. It is not used for real inputs, nor for dual numbers and Taylor series, whose implied volatility is computed from the one of their real values. Must be positive. The default is100eps(Float64), or8epsof the element type when the inputs are inFloat32orFloat16, which cannot resolve smaller steps.n_iter_max: maximum number of Householder iterations of Let's Be Rational, for real inputs and for the real values of the other number types. Two are enough for any input inFloat64; more refine the result for wider types such asBigFloat. Must be positive.
Example
julia> price = blsprice(10.0, 10.0, 0.01, 2.0, 0.2, 0.01);
julia> blsimpv(10.0, 10.0, 0.01, 2.0, price, 0.01)
0.20000000000000015FinancialToolbox.blkimpv — Function
blkimpv(F0, K, r, T, Price, FlagIsCall = true, xtol = 1e-14, n_iter_max = 4)Implied volatility of a European option on a forward in the Black model: the σ such that blkprice(F0, K, r, T, σ, FlagIsCall) == Price, computed as in blsimpv.
Arguments
F0: forward price of the underlying.K: strike price.r: continuously compounded zero rate.T: time to maturity, in years.Price: price of the option.FlagIsCall:truefor a call,falsefor a put.xtol: relative tolerance of the Newton iteration for complex inputs, not used for the other number types (seeblsimpv). Must be positive. The default is1e-14, or8epsof the element type when the inputs are inFloat32orFloat16.n_iter_max: maximum number of Householder iterations of Let's Be Rational (seeblsimpv). Must be positive.
Example
julia> price = blkprice(10.0, 10.0, 0.01, 2.0, 0.2);
julia> blkimpv(10.0, 10.0, 0.01, 2.0, price)
0.1999999999999999Dates
FinancialToolbox.yearfrac — Function
yearfrac(Date1::Date, Date2::Date, basis::Integer)Fraction of year from Date1 to Date2 with the day count convention basis, as in Matlab:
basis | Convention |
|---|---|
| 0 | ACT/ACT |
| 1 | 30/360 SIA |
| 2 | ACT/360 |
| 3 | ACT/365 |
| 4 | 30/360 PSA |
| 5 | 30/360 ISDA |
| 6 | 30E/360 |
| 7 | ACT/365 JPN |
Arguments
Date1: start date.Date2: end date. If it comes beforeDate1, the result is negative.basis: day count convention, an integer from 0 to 7 (see the table above).
Example
julia> using Dates
julia> yearfrac(Date(1996, 10, 12), Date(1998, 1, 10), 1)
1.2444444444444445FinancialToolbox.daysact — Function
daysact(Date1::Date, Date2::Date)Actual number of days from Date1 to Date2, negative if Date2 comes first.
Arguments
Date1: start date.Date2: end date.
Example
julia> using Dates
julia> daysact(Date(1996, 10, 12), Date(1998, 1, 10))
455FinancialToolbox.fromExcelNumberToDate — Function
fromExcelNumberToDate(ExcelNumber::Integer)The Date of an Excel serial date number.
Arguments
ExcelNumber: number of days since December 30, 1899, the date system of Excel on Windows (45000 is March 15, 2023).
Example
julia> fromExcelNumberToDate(45000)
2023-03-15Gaussian distribution
FinancialToolbox.normcdf — Function
normcdf(x)Cumulative distribution function of a standard Gaussian random variable at x, computed with erfc.
Arguments
x: point of evaluation, of any number type supported by the package.
Example
julia> normcdf(0.0)
0.5FinancialToolbox.normpdf — Function
normpdf(x)Probability density function of a standard Gaussian random variable at x.
Arguments
x: point of evaluation, of any number type supported by the package.
Example
julia> normpdf(0.0)
0.3989422804014327Index
FinancialToolbox.blkimpvFinancialToolbox.blkpriceFinancialToolbox.blsbinFinancialToolbox.blsdeltaFinancialToolbox.blsdowninFinancialToolbox.blsdownoutFinancialToolbox.blsgammaFinancialToolbox.blsimpvFinancialToolbox.blslambdaFinancialToolbox.blspriceFinancialToolbox.blspsiFinancialToolbox.blsrhoFinancialToolbox.blsthetaFinancialToolbox.blsupinFinancialToolbox.blsupoutFinancialToolbox.blsvannaFinancialToolbox.blsvegaFinancialToolbox.daysactFinancialToolbox.fromExcelNumberToDateFinancialToolbox.normcdfFinancialToolbox.normpdfFinancialToolbox.yearfrac