API

Instruments

Day counts

FinancialDerivatives.Instruments.Business252 — Type
Business252(calendar)

Business/252 day count: the number of business days of calendar between the two dates, divided by 252.

If the issue date is a business day, the count includes it. The count does not include the expiry date. calendar is a HolidayCalendar of BusinessDays.jl, or its name as a Symbol, for example :USNYSE. Load BusinessDays.jl before you use this day count.

The market data must use the same time basis as the instrument. Each rate must be continuously compounded over a year of 252 business days. The volatility must be annualized over 252 business days.

source

Market Data

FinancialDerivatives.MarketData.AbstractMarketData — Type

Abstract supertype for the market observables: spot prices, rates, and volatilities.

The price methods read each observable from the market data through an accessor function. They do not read the observables from the instrument.

Each subtype must implement the accessors of its asset class:

Each rate and each volatility applies to a horizon t that starts at the time zero. A closed-form formula reads them for the expiry of the instrument. A tree and a simulation read them for the two ends of each time step, and compute the forward value of the step.

In the subtypes of this package, a rate or a volatility is a constant or a function of the horizon. The function must accept each horizon from zero to the expiry.

source

Accessors

Pricing Engines

FinancialDerivatives.Engines.PricingEngine — Type

Abstract supertype for the numerical pricing methods: analytic, binomial tree, Monte Carlo, and finite difference.

Each subtype is a strategy of the Strategy pattern. A subtype holds the settings of its numerical method, for example the number of tree steps.

To add an engine, define a subtype and the price methods that take the subtype as the first argument.

source

Binomial schemes

FinancialDerivatives.Engines.tree_parameters — Function
tree_parameters(scheme, m, w, x, steps) -> (u, d, p)

Return the up factor u, the down factor d, and the probability p of the up move for one step of the tree.

The ratio u / d must not depend on m. If the ratio depends on m, the tree does not recombine.

Arguments

  • scheme: the BinomialScheme of the tree.
  • m: the growth factor of the underlying on the step, in the risk-neutral measure.
  • w: the variance of the logarithm of the underlying on the step.
  • x: the logarithm of the ratio of the forward value of the underlying at the last step to a reference level. A scheme can put the centre of the tree at this level. For an option, the engine uses the strike as the reference level.
  • steps: the number of time steps in the tree.
source

Models

FinancialDerivatives.Models.Model — Type

Abstract supertype for all the pricing models in this package.

Each subtype is a strategy of the Strategy pattern. A subtype holds the parameters of its model. The type of the model selects the price method.

To add a model with a closed-form formula, define a subtype and a price method for that subtype. To add a model to the generic engines, define a subtype of LognormalModel or of ShortRateModel.

source
FinancialDerivatives.Models.OneFactorModel — Type

Abstract supertype for the models with one state that one Brownian motion drives.

The state $x$ follows the diffusion process

\[dx = a(t, x)\,dt + b(t, x)\,dW\]

$W$ is the Brownian motion. The drift term is $a(t, x)\,dt$, and drift returns $a$. The diffusion term is $b(t, x)\,dW$, and diffusion returns $b$. The diffusion term is the random shock of the process.

simulate accepts each subtype.

To add a model, define a subtype and its initial_state, drift and diffusion methods. simulate then moves the state with Euler-Maruyama steps. If the model has a better step, define a transition method for the subtype.

source
FinancialDerivatives.Models.LognormalModel — Type

Abstract supertype for the models in which the price of the underlying is lognormal.

The state is the price $s$ of the underlying. The price follows the diffusion process

\[ds = g(t)\,s\,dt + σ(t)\,s\,dW\]

The drift term is $g(t)\,s\,dt$, and the diffusion term is $σ(t)\,s\,dW$. $g$ is the growth rate in the risk-neutral measure, and $σ$ is the volatility.

growth_rate returns the mean of $g$ between the time zero and the horizon $t$. The volatility of the market data is the square root of the mean of $σ^2$ in the same interval.

The AnalyticEngine, the BinomialEngine and the MonteCarloEngine accept each subtype.

To add a model, define a subtype and a growth_rate method for that subtype.

source
FinancialDerivatives.Models.BlackKarasinskiModule.BlackKarasinski — Type

Select the Black-Karasinski model of the short rate.

The logarithm of the short rate $r$ follows

\[d\ln r = k (\ln θ - \ln r)\,dt + σ\,dW\]

The short rate is always positive. $θ$ is a rate. $\ln θ$ is the long-term mean of $\ln r$.

The InterestRateMarketData supplies the initial rate.

References

  • Black, F., and Karasinski, P. (1991). Bond and option pricing when short rates are lognormal. Financial Analysts Journal, 47(4), 52-59. doi:10.2469/faj.v47.n4.52
source

Model interface

FinancialDerivatives.Models.transition — Function

Return the function that moves the state of model from the time t1 to the time t2.

The result is a function (x, z) -> y. x is the state at the time t1, z is a standard normal shock, and y is the state at the time t2.

The method for a OneFactorModel is one Euler-Maruyama step. The method for a LognormalModel is exact.

source

Pricing and simulation

FinancialDerivatives.Engines.price — Function
price(engine, instrument, model, market_data) -> Real

Compute the fair value of instrument under model with engine and market_data.

This declaration has no methods. It is the abstract interface of the package (dependency inversion). The model modules and the engine modules depend on this declaration and add the methods.

Multiple dispatch selects the method from the types of the four arguments. The AnalyticEngine, the BinomialEngine and the MonteCarloEngine each have one generic method for the subtypes of LognormalModel. A closed-form formula of one model has one method for its combination of types. If a combination has no method, price throws a MethodError.

source
FinancialDerivatives.Engines.simulate — Function
simulate(engine, model, market_data, t) -> Matrix

Simulate paths of the state of model from the time zero to the time t, in years.

Each column of the result is one path. The first row holds the initial state. The last row holds the state at the time t.

source

Private