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: true for a call, false for 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.1023600107733194

See also blkprice, blsimpv.

source
FinancialToolbox.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: true for a call, false for a put.

Example

julia> blkprice(10.0, 10.0, 0.01, 2.0, 0.2)
1.1023600107733187

See also blsprice, blkimpv.

source
FinancialToolbox.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: true for a call, false for a put.

Example

julia> blsbin(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
0.4349813361147117
source

Barrier 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 below S0.
  • FlagIsCall: true for a call, false for a put.

Example

julia> blsdownout(10.0, 10.0, 0.01, 2.0, 0.2, 0.01, 8.0)
1.0349806169570723

See also blsdownin, blsupout, blsprice.

source
FinancialToolbox.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 below S0.
  • FlagIsCall: true for a call, false for a put.

Example

julia> blsdownin(10.0, 10.0, 0.01, 2.0, 0.2, 0.01, 8.0, false)
1.005956123316791

See also blsdownout, blsupin, blsprice.

source
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, above S0.
  • FlagIsCall: true for a call, false for a put.

Example

julia> blsupout(10.0, 10.0, 0.01, 2.0, 0.2, 0.01, 12.0, false)
0.9741004570291205

See also blsupin, blsdownout, blsprice.

source
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, above S0.
  • FlagIsCall: true for a call, false for a put.

Example

julia> blsupin(10.0, 10.0, 0.01, 2.0, 0.2, 0.01, 12.0)
1.0537786287548607

See also blsupout, blsdownin, blsprice.

source

Sensitivities

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: true for a call, false for a put.

Example

julia> blsdelta(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
0.5452173371920436

See also blsprice.

source
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: true for a call, false for 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.1368788153571282

See also blsprice.

source
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: true for a call, false for 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.47515261428513

See also blsprice.

source
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: true for a call, false for a put.

Example

julia> blsrho(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
8.699626722294234

See also blsprice.

source
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: true for a call, false for a put.

Example

julia> blstheta(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
-0.2627340306065233

See also blsprice.

source
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: true for a call, false for a put.

Example

julia> blslambda(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
4.945909973725978

See also blsprice.

source
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: true for a call, false for a put.

Example

julia> blspsi(10.0, 10.0, 0.01, 2.0, 0.2, 0.01)
-10.904346743840872

See also blsprice.

source
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: true for a call, false for 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.2737576307142565

See also blsprice.

source

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: true for a call, false for a put.
  • xtol: relative tolerance of the Newton iteration that computes the implied volatility of complex inputs: it stops when a step is smaller than xtol times 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 is 100eps(Float64), or 8eps of the element type when the inputs are in Float32 or Float16, 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 in Float64; more refine the result for wider types such as BigFloat. 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.20000000000000015

See also blkimpv, blsprice.

source
FinancialToolbox.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: true for a call, false for a put.
  • xtol: relative tolerance of the Newton iteration for complex inputs, not used for the other number types (see blsimpv). Must be positive. The default is 1e-14, or 8eps of the element type when the inputs are in Float32 or Float16.
  • n_iter_max: maximum number of Householder iterations of Let's Be Rational (see blsimpv). 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.1999999999999999

See also blsimpv, blkprice.

source

Dates

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:

basisConvention
0ACT/ACT
130/360 SIA
2ACT/360
3ACT/365
430/360 PSA
530/360 ISDA
630E/360
7ACT/365 JPN

Arguments

  • Date1: start date.
  • Date2: end date. If it comes before Date1, 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.2444444444444445
source
FinancialToolbox.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))
455
source
FinancialToolbox.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-15
source

Gaussian 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.5
source
FinancialToolbox.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.3989422804014327
source

Index