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.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.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.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.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.ScaleType
Scale(s::Observable, c::Contract)

Scale the contract c by s.

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.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.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.montecarloMethod
montecarlo(m::GeomBMModel, dates, npaths)

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

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.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.
StatsBase.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

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.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.DateObsType
DateObs() <: Observable{Date}

A singleton type representing the "free" date observable.

Miletus.EitherType
Either(c1::Contract, c2::Contract)

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

Miletus.GiveType
Give(c::Contract)

Take the opposite side of contract c.

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.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.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.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.maturitydateMethod
maturitydate(c::Contract)

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

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.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.