Type and function reference

Miletus.AmericanCallType
AmericanCall(date, c, strike)

An American call contract, with maturity date, on underlying contract c at price strike.

Miletus.AmericanPutType
AmericanPut(date, c, strike)

An American put contract, with maturity date, on underlying contract c at price strike.

Miletus.AmountType
Amount(o::Observable) <: Contract

Receive amount of o.

Miletus.AnytimeType
Anytime(p::Observable{Bool}, c::Contract)

May acquire c at any point when p is true.

Miletus.AtType
At(t::Date) <: Observable{Bool}

An observable that is true when the date is t.

Miletus.BeforeType
Before(t::Date) <: Observable{Bool}

An observable that is true when the date is before or equal to t.

Miletus.BinomialGeomRWModelType
BinomialGeomRWModel

A model for a Binomial Geometric Random Walk (aka Binomial tree).

Arguments:

  • startdate : start date of process
  • enddate : start date of process
  • nsteps : number of steps in the tree
  • S₀ : inital value
  • Δt : the time-difference between steps, typically days(startdate - enddate) / (365*nsteps)
  • iR : discount rate, exp(-Δt*interestrate)
  • u : scale factor for up
  • d : scale factor for down
  • p : up probability
  • q : down probability, 1-p
Miletus.BothType
Both(c1::Contract, c2::Contract)

Acquire both contracts c1 and c2 (and in PJE2000).

Miletus.CondType
Cond(p::Observable{Bool}, c1::Contract, c2::Contract)

If p is true at the point of aquisition, acquire c1 else acquire c2.

Miletus.CoreForwardModelType
CoreForwardModel(forwarddates, forwardprices, yieldcurve)

Specifies the value of a SingleStock in terms of its forward prices.

  • forwarddates: ordered dates for which forward prices are available
  • forwardprices: forward prices of the asset
  • yieldcurve: risk-free discount curve
Miletus.CoreModelType
CoreModel(startdate, startprice, interestrate, carryrate)

Contains the core parameters for the model of SingleStock:

  • startprice: initial price at startdate
  • yieldcurve: risk free rate of return for the numeraire.
  • carrycurve: the carry rate, i.e. the net income for holding the asset:
    • for stocks this is typically positive (i.e. dividends)
    • for commodities this is typically negative (i.e. cost-of-carry)

The yieldcurve and carryrate are all specified on a continously compounded, Actual/365 basis.

The exact dynamics of the model are unspecified, but has the property that

\[E[S_t] = S_0 \times e^{(r-q)t}\]

Miletus.DateObsType
DateObs() <: Observable{Date}

A singleton type representing the "free" date observable.

Miletus.DiscreteSwingContractType
DiscreteSwingContract

Represents a swing contract. The arguments are:

  • default: this is the contract that is executed on each date if no swing occurs
  • alternate: this is the contract that is executed if the swing occurs
  • penalty: this contract is executed on the last exercise date, and is scaled by the number of swings below the minimum (nxmin)
  • exdates: the exercise dates of the swing option
  • nxmin: the minimum number of swings (the penalty contract is incurred if the total number of swings is below this number)
  • nxmax: the maximum number of swings that may be taken
Miletus.EitherType
Either(c1::Contract, c2::Contract)

Acquire either contract c1 or c2 (or in PJE2000).

Miletus.EuropeanCallType
EuropeanCall(date, c, strike)

A European call contract, with maturity date, on underlying contract c at price strike.

Miletus.EuropeanPutType
EuropeanPut(date, c, strike)

A European put contract, with maturity date, on underlying contract c at price strike.

Miletus.GeomBMModelType
GeomBMModel(startdate, startprice, interestrate, carryrate, volatility)

A model for SingleStock, following a geometric Brownian motion.

  • startdate
  • startprice: initial price at startdate
  • interestrate: risk free rate of return.
  • carryrate: the carry rate, i.e. the net return for holding the asset:
    • for stocks this is typically positive (i.e. dividends)
    • for commodities this is typically negative (i.e. cost-of-carry)
  • volatility:

The interestrate, carryrate and volatility are all specified on a continously compounded, Actual/365 basis.

The price is assumed to follow the PDE:

\[d S_t = \kappa S_t dt + \sigma S_t dW_t\]

or

\[d \log S_t = (\kappa - \sigma^2/2) dt + \sigma dW_t\]

where $W_t$ is a Wiener process, and κ = interestrate - carryrate.

Miletus.GeomOUModelType
GeomOUModel

Assumes that the stock price follows a geometric Ornstein–Uhlenbeck process

\[\frac{dS_t}{S_t} = [k(t) - \theta \log S_t] dt + \sigma dW_t\]

where the parameters:

  • $\theta$ is the rate of mean reversion (sometimes called "speed")
  • $\sigma$ is the OU volatility

and $k(t)$ is chosen based on the forward curve so that $S_t$ is risk-neutral. This is equivalent to the "one factor model" of Clewlow and Strickland (1999), with dynamics on the forward price of

\[\frac{d F_{t,T}}{F_{t,T}} = \sigma e^{- heta (T-t)} dW_t\]

where $F_{t,T}$ is the forward price of maturity date $T$ at current time $t$.

  • Clewlow, L. and Strickland, C. (1999) "Valuing Energy Options in a One Factor Model Fitted to Forward Prices". https://ssrn.com/abstract=160608
Miletus.GiveType
Give(c::Contract)

Take the opposite side of contract c.

Miletus.HullWhiteTrinomialModelType
HullWhiteTrinomialModel

This is a Hull-White trinomial model, a discrete approximation of a GeomOUModel. The arguments are:

  • m::GeomOUModel: the model to approximate
  • dates::AbstractVector{Date} (optional): the dates at which to compute the approximation. By default, the forward dates are used (if available).
  • k::Int (default=1): the number of discrete steps per day to use
  • cap::Int (default=0.2): a parameter between 0.184 and 0.577 used to determine how to truncate the branching (larger values give less truncation).
Miletus.LatticeStateContractType
LatticeStateContract

Represents a contract with multiple states, where at each exercise date the holder may move up or down states. This can represent a variety of multiple exercise contracs, such as storage options.

  • transition: a square matrix of contracts: at each exercise date, the contract transition[from, to] is exercised when transitioning from state from to to.
  • ends: a vector of contracts exercised at the final exercise date. The ith contract is exercised if the contract is in state i after the final exercise.
  • exdates: the exercise dates of the contract
  • initstate: the initial state of the contract (default = 1).

Note that ups and downs must be of the same length, and ends must be 1 greater (being the number of states in the lattice).

Miletus.MaskedToepelitzTransitionType
MaskedToepelitzTransition(mask, offsets, elements)

Represents a masked Toepelitz-structured transition matrix: that is, a matrix in which the elements on a common diagonal are identical. The aruments are:

  • mask: a square BitMatrix. Any false values are considered invalid transitions.
  • offsets: a range indicating which diagonals have values (0 = main diagonal, +1 = superdiagonal, -1 = subdiagonal).
  • elements: the elements on each diagonal in offsets.
MaskedToepelitzTransition(BitArray(true for i = 1:5, j = 1:5), -2:1, (Receive(2), Receive(1), Zero(), Pay(1)))
Miletus.MonteCarloModelType
MonteCarloModel(core, dates, paths)

A MonteCarloModel is the result of a simulation of a series of asset prices.

  • core: a reference CoreModel
  • dates: an AbstractVector{Date}
  • paths: a matrix of the scenario paths: the rows are the scenarios, and the columns are the values at each date in dates.
Miletus.MonteCarloScenarioType
MonteCarloScenario(core, dates, path)

A MonteCarloScenario is a single simulation scenario of a MonteCarloModel.

  • core: a reference CoreModel
  • dates: an AbstractVector{Date}
  • paths: an AbstractVector of the values at each date in dates.
Miletus.SABRModelType
SABRModel

The SABR model is a stochastic volatility model of the form

dS = σ F^β dW
dσ = ν σ dZ

with σ(0) = α, where W and Z are correlated Wiener processes with parameter ρ.

Unlike Black-Scholes, this is not scale invariant unless β == 1.

  • startdate
  • startprice: initial price at startdate
  • interestrate: risk free rate of return.
  • carryrate: the carry rate, i.e. the net return for holding the asset:
    • for stocks this is typically positive (i.e. dividends)
    • for commodities this is typically negative (i.e. cost-of-carry)
  • α: initial volatlity (note: this is not equivalent to Black-Scholes volatlity)
  • β: constant
  • ρ: correlation between stock price and volatlity
  • ν: volatility of volatility

If ν == 0 and β == 1, then it is equivalent to the GeomBMModel with σ = α.

Miletus.ScaleType
Scale(s::Observable, c::Contract)

Scale the contract c by s.

Miletus.SplineInterpolationType
SplineInterpolation

This is used to model interpolation between any two discrete points on a discrete convex curve. This implements double quadratic interpolation.

- `x`: An Array of the discrete values on the x axis
- `y`: An Array of the discrete values on the y axis
- `weights`: An Array of tuples of the weights of every quadratic curve
modelled between two discrete points on the curve
Miletus.SplineVolatilityModelType
SplineVolatilityModel

The SplineVolatilityModel is used to interpolate between two values of
strikeprice to find the appropriate volatility on the volatility smile.
  • startdate
  • startprice: initial price at startdate
  • interestrate: risk free rate of return.
  • carryrate: the carry rate, i.e. the net return for holding the asset:
    • for stocks this is typically positive (i.e. dividends)
    • for commodities this is typically negative (i.e. cost-of-carry)
  • date: Date of Maturity
  • volcurve: A SplineInterpolation type that models the interpolation
Miletus.UntilType
Until(p::Observable{Bool}, c::Contract)

Acts like contract c until p is true, at which point it is abandoned (and hence worthless).

Miletus.WhenType
When(p::Observable{Bool}, c::Contract)

Acquire the contract c at the point when p becomes true.

Miletus._blackFunction
_black(h, t, K = exp(-2*h*t))

The black kernel function:

Φ(h + t) - K*Φ(h - t)

where K = exp(-2*h*t) (this is provided as an extra argument, as it is typically known a priori.

Assumes h <= 0, t >= 0 , which implies K >= 1.

Miletus._black_erfcxMethod
_black_erfcx(h, t)

Compute the black kernel function using the erfcx function:

b  =  Φ(h+t) - exp(-2⋅h⋅t) ⋅ Φ(h-t)

      exp(-(h²+t²)/2)
   =  ---------------  ·  [ Φ(h+t)/ϕ(h+t) - Φ(h-t)/ϕ(h-t) ]
          √(2π)

   =  exp(-(h²+t²)/2) ⋅ [erfcx(-(h+t)/√2) - erfcx(-(h-t)/√2)]/2
Miletus._black_ivolMethod
_black_ivol(K, β)

The kernel of the inverse black function: returns the value s such that

black(K,s) == β

where K ≥ 1 and 0 ≤ β ≤ 1.

Miletus._black_normcdfFunction
_black_normcdf(h, t, K=exp(-2*h*t))

Computes the black kernel function directly using the normal CDF.

Miletus._black_small_tMethod
_black_small_t(h, t)

Compute the black kernel function using Taylor series around t=0:

b  =  Φ(h+t) - exp(-2⋅h⋅t) ⋅ Φ(h-t)

      exp(-(h²+t²)/2)
   =  ---------------  ·  [ Φ(h+t)/ϕ(h+t) - Φ(h-t)/ϕ(h-t) ]
          √(2π)

   =  exp(-(h²+t²)/2) ⋅ [erfcx(-(h+t)/√2) - erfcx(-(h-t)/√2)]/2

Using

Y(h) = Φ(h)/φ(h) = √(π/2)·erfcx(-h/√2)
a    = 1+h·Y(h)

Note that due to h < 0, and h·Y(h) -> -1 (from above) as h -> -∞, we also have that a > 0 and a -> 0 as h -> -∞.

Miletus._black_vegaMethod
_black_vega(h, t)

The vega corresponding to the black kernel function:

Φ(h + t) - K*Φ(h - t)

where h = -log(K)/s and t = s/2.

Miletus._cblackFunction
_cblack(h, t, K=exp(-2*h*t))

The complement of the black kernel function

1 - _black(h, t, K)
Miletus.blackMethod
black(F,K,s)

The Black function of standardised arguments:

black(F,K,s) = F ⋅ Φ(log(F/K)/s + s/2) - K ⋅ Φ(log(F/K)/s - s/2)

This is the Black-Scholes price of a call option with spot price F, strike K and volatility s, assuming the discount rate r and carry rate q are zero, and the time to maturity is one.

This is monotonic increasing in s, with

black(K,F,0) == max(F-K, 0)
black(K,F,∞) == F

The corresponding put price is:

black(K,F,s)

and so put-call parity implies:

black(F,K,s) + K = black(K,F,s) + F

black(F,K,s) is the expectation of max(exp(Y)-K,0) where Y has a Normal(log(F)-s^2/2, s) distribution.

This can be used to compute the complementary CDF of the inverse Gaussian distribution with parameters (λ,μ) at x via,

P[X > x] = black(1, exp(2λ/μ), 2*sqrt(λ/x))

This is largely based on the method of Jäckel (2015).

References

  • Jäckel, P. (2015), Let's Be Rational. Wilmott, 2015(75): 40–53. doi:10.1002/wilm.10395
Miletus.black_ivolMethod
black_ivol(F, K, β)

The inverse black function: returns the value s such that

black(K,s) == β

where F > 0, K > 0andmax(F-K, 0) ≤ β ≤ F`.

Miletus.date2indexMethod
date2index(m::Union{MonteCarloScenario, MonteCarloModel}, dt::Date)

Returns the index of dt in the path(s) of m.

Miletus.deltaMethod
delta(m::GeomBMModel, c::Contract)
delta(m::GeomBMModel, c::Contract, MonteCarloModel, npaths::Integer)

Calculate the delta Greek: the first derivative of the option price with respect to the spot price of the underlying for the contract c under the model m

Inputs

  • m::GeomBMModel - The model under which the contract is being valued
  • c::Contract - The contract whose greek is desired.
  • npaths::Integer - Number of Monte Carlo paths to use.
Miletus.fit_ivolMethod
fit_ivol(SABRModel, mcore::AbstractCoreModel, contracts, ivols)

Fit a SABRModel using from a collection of contracts (contracts) and their respective implied volatilities (ivols), under the assumptions of mcore.

Miletus.fit_ivolMethod
fit_ivol(SplineVolatilityModel, mcore::AbstractCoreModel, contracts, ivols)

Fit a SplineVolatilityModel using from a collection of contracts (contracts) and their respective implied volatilities (ivols), under the assumptions of mcore.

Miletus.gammaMethod
gamma(m::GeomBMModel, c::Contract)
gamma(m::GeomBMModel, c::Contract, MonteCarloModel, npaths::Integer)

Calculate the gamma Greek: the second derivative of the option price with respect to the price of the underlying for the contract c under the model m

Inputs

  • m::GeomBMModel - The model under which the contract is being valued
  • c::Contract - The contract whose greek is desired.
  • npaths::Integer - Number of Monte Carlo paths to use.
Miletus.greekMethod
greek(m::GeomBMModel, c::Contract; metric = :vol, n = 1)

Calculate the nth derivative of the option price with respect to different metrics.

Inputs

  • m::GeomBMModel - The model under which the contract is being valued
  • c::Contract - The contract whose greek is desired.
  • metric::Symbol (optional) - The metric with respect to which the derivative

is evaluated. (default = :vol, other options - :strike, :interest)

  • n::Int - (optional) The derivative desired. (default = 1)
Miletus.greekMethod
`greek(m::MonteCarloModel, c::Contract; metric = :vol, n = 1)`

Calculate the nth derivative of the option price with respect to different
metrics.

Inputs

  • m::MonteCarloModel - The model under which the contract is being valued
  • c::Contract - The contract whose greek is desired.
  • metric::Symbol (optional) - The metric with respect to which the derivative

is evaluated. (default = :vol, other options - :strike, :interest)

  • n::Int - (optional) The derivative desired. (default = 1)
Miletus.householder_updateMethod
householder_update(N, [H2, [H3]])

The update incrememnt for nth order Householder's method (where n is the number of arguments) for finding the root of

f(x) == 0
  • n == 1 is Newton's method
  • n == 2 is Halley's method

Arguments:

  • N: the Newton update -f(x) / f′(x)
  • H2: the scaled 2nd order derivative f′′(x) / f′(x)
  • H3: the scaled 3rd order derivative f′′′(x) / f′(x)
Miletus.interpolateMethod
interpolate(m::SplineInterpolation, c::European)

Compute the implied Black-Scholes volatility of an option c under the SplineVolatilityModel m.

Miletus.ivolMethod
ivol(m::CoreModel, c::Contract, price)

Compute the Black-Scholes implied volatility of contract c at price, under the assumptions of model m (ignoring the volatility value of m).

See also: fit

Miletus.ivolMethod
ivol(m::SABRModel, c::European)

Compute the implied Black-Scholes volatility of an option c under the SABR model m.

The SABR model was originally explored in detail in Hagan et. al. (2002). This uses the correction by Obloj (2008).

  • P. S. Hagan, D. Kumar, A. S. Lesniewski, and D. E. Woodward. (2002) 'Managing smile risk". Wilmott Magazine, pages 84–108.

  • J. Obloj (2008) "Fine-tune your smile: Correction to Hagan et al", arXiv: 0708.0998

Miletus.maturitydateMethod
maturitydate(c::Contract)

The maturity date of a contract c is the date at which contract is completed or expires.

Miletus.montecarloMethod
montecarlo(m::GeomBMModel, dates, npaths)

Sample npaths Monte Carlo paths of the model m, at time dates.

Miletus.poscubicrootMethod
poscubicroot(p3,p2,p1,0)

Find the smallest positive real root of the polynomial

p3*x^3 + p2*x^2 + p1*x + p0
Miletus.powm1Method
powm1(x,y)

Compute x^y-1 accurately when x is near 1. Based on Boost's implementation

Miletus.priceMethod
price(c::Contract)

The price of a Buy or Sell contract.

Miletus.rational_cubic_interpolationMethod
rational_cubic_interpolation(x, x₋, x₊, y₋, y₊, d₋, d₊, r)

Compute a shape preserving rational interpolation.

Arguments

  • x the value at which to interpolate
  • x₋,x₊: the lower and upper bounds of the interval
  • y₋,y₊: the value of the function at the lower and upper bounds
  • d₋,d₊: the value of the derivative at the lower and upper bounds
  • r: the control parameter, which must be greater than -1.
    • If r == 3, then it is the usual Hermite cubic polynomial
    • As r → ∞, it approaches linear interpolation.

If Δ = (y₊ - y₋)/(x₋ - x₊) > 0, and d₋ >= 0, d₊ >= 0, then the interpolant is guaranteed monotonic increasing if

r >= (d₋ + d₊)/Δ

[DG85, eq. 3.8].

If d₋ < Δ < d₊, then the interpolant is convex if and only if

r >= 1 + max(d₊ - Δ, Δ - d₋) / min(d₊ - Δ, Δ - d₋)

[DG85, eq. 3.18].

Note: for the purposes of computation, the bounds are actually interchangable (i.e. x₋ can be the upper bound).

References

  • R. Delbourgo and J. A. Gregory (1985) "Shape Preserving Piecewise Rational Interpolation", SIAM J. Sci. and Stat. Comput., 6(4), 967–976. doi:10.1137/0906065
Miletus.rhoMethod
rho(m::GeomBMModel, c::Contract)
rho(m::GeomBMModel, c::Contract, MonteCarloModel, npaths::Integer)

Calculate the rho Greek: the first derivative of the option price with respect to the interest rate, for the contract c under the model m

Inputs

  • m::GeomBMModel - The model under which the contract is being valued
  • c::Contract - The contract whose greek is desired.
  • npaths::Integer - Number of Monte Carlo paths to use.
Miletus.sabr_alphaMethod
sabr_alpha(F, t, σATM, β, ν, ρ)

Compute the α parameter (initial volatility) for the SABR model from the Black-Scholes at-the-money volatility.

  • F: Forward price

  • t: time to maturity

  • σATM: Black-Scholes at-the-money volatility

  • β, ν, ρ: parameters from SABR model.

  • West, G. (2005). Calibration of the SABR model in illiquid markets. Applied Mathematical Finance, 12(4), 371-385.

Miletus.scenariosMethod
scenarios(m::MonteCarloModel)

Returns an iterator over each MonteCarloScenario in m.

Miletus.strikepriceMethod
strikeprice(c::Contract)

The price at which an option or forward can be exercised.

Miletus.vegaMethod
vega(m::GeomBMModel, c::Contract)
vega(m::GeomBMModel, c::Contract, MonteCarloModel, npaths::Integer)

Calculate the vega Greek: the first derivative of the option price with respect to volatility for the contract c under the model m

Inputs

  • m::GeomBMModel - The model under which the contract is being valued
  • c::Contract - The contract whose Greek is desired.
  • npaths::Integer - Number of Monte Carlo paths to use.
StatsAPI.fitMethod
fit(SABRModel, mcore::AbstractCoreModel, contracts, prices)

Fit a SABRModel using from a collection of contracts (contracts) and their respective prices (prices), under the assumptions of mcore.

StatsAPI.fitMethod
fit(SplineVolatilityModel, mcore::AbstractCoreModel, contracts, prices)

Fit a SplineVolatilityModel using from a collection of contracts (contracts) and their respective prices (prices), under the assumptions of mcore.

StatsAPI.fitMethod
fit(GeomBMModel, m::Union{CoreModel,CoreForwardModel}, c::Contract, price)

Fit a GeomBMModel using the implied volatility of c at price, using the parameters of m.

See also: ivol