API
Instruments
FinancialDerivatives.Instruments.FinancialInstrument — Type
Abstract supertype for all financial instruments. Subtypes define contract terms only (strike, expiry, call/put). Market observables belong in an AbstractMarketData subtype.
FinancialDerivatives.Instruments.FXOption — Type
Arguments
k: strike pricet: time to expirationcall:trueif call,falseif put
FinancialDerivatives.Instruments.payoff — Function
Return the amount that option pays at exercise for the price s of the underlying.
FinancialDerivatives.Instruments.isamerican — Function
Return true if the holder can exercise the Option o before the expiry
Day counts
FinancialDerivatives.Instruments.DayCount — Type
Abstract supertype for the day count conventions. A day count converts an issue date and an expiry date to a time in years.
FinancialDerivatives.Instruments.Actual365Fixed — Type
Actual/365 Fixed day count: the number of calendar days between the two dates, divided by 365.
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.
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:
- Equity:
spot,discount_rate,dividend_yield,volatility. - Foreign exchange:
spot,discount_rate,foreign_rate,volatility. - Interest rate:
short_rate.
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.
FinancialDerivatives.MarketData.EquityMarketData — Type
Market observables required to price equity derivatives.
FinancialDerivatives.MarketData.FXMarketData — Type
Market observables required to price foreign-exchange derivatives.
FinancialDerivatives.MarketData.InterestRateMarketData — Type
Market observables required to simulate the short rate.
Accessors
FinancialDerivatives.MarketData.spot — Function
spot(md)Return the spot price of the underlying.
FinancialDerivatives.MarketData.discount_rate — Function
discount_rate(md, t)Return the continuously compounded discount rate for the horizon t, in years.
For FXMarketData, the discount rate is the domestic rate.
FinancialDerivatives.MarketData.foreign_rate — Function
foreign_rate(md, t)Return the continuously compounded foreign rate for the horizon t, in years.
FinancialDerivatives.MarketData.dividend_yield — Function
dividend_yield(md)Return the continuous dividend yield of the underlying.
FinancialDerivatives.MarketData.volatility — Function
volatility(md, t)Return the volatility of the underlying for the horizon t, in years.
FinancialDerivatives.MarketData.short_rate — Function
short_rate(md)Return the current short-term interest rate.
FinancialDerivatives.MarketData.discount_factor — Function
Return the discount factor between the times t1 and t2, in years.
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.
FinancialDerivatives.Engines.AnalyticEngine — Type
Pricing engine for instruments with closed-form or semi-analytic solutions.
FinancialDerivatives.Engines.BinomialEngine — Type
Pricing engine based on recombining binomial tree methods.
FinancialDerivatives.Engines.MonteCarloEngine — Type
Pricing engine based on Monte Carlo simulation.
FinancialDerivatives.Engines.FiniteDifferenceEngine — Type
Pricing engine based on finite-difference PDE methods.
Binomial schemes
FinancialDerivatives.Engines.BinomialScheme — Type
Abstract supertype for the schemes of the BinomialEngine.
A scheme sets the two moves of the tree and the probability of the up move. Each subtype is a strategy of the Strategy pattern.
To add a scheme, define a subtype and a tree_parameters method for that subtype. If the scheme needs a special number of steps, also define a tree_steps method.
FinancialDerivatives.Engines.LeisenReimer — Type
The tree must have an odd number of steps. If steps is even, the tree has steps + 1 steps.
FinancialDerivatives.Engines.RendlemanBartterTree — Type
Binomial tree of Rendleman and Bartter. The two moves have the same probability.
References
- Rendleman, R. J., and Bartter, B. J. (1979). Two-state option pricing. The Journal of Finance, 34(5), 1093-1110. doi:10.1111/j.1540-6261.1979.tb00058.x
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: theBinomialSchemeof 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.
FinancialDerivatives.Engines.tree_steps — Function
tree_steps(scheme, steps)Return the number of time steps in the tree of scheme for the engine setting steps.
The method for a BinomialScheme returns steps.
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.
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.
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.
FinancialDerivatives.Models.ShortRateModel — Type
Abstract supertype for the models of the short rate.
The state is the short rate $r$. The rate follows the diffusion process
\[dr = a(t, r)\,dt + b(t, r)\,dW\]
drift returns $a$, and diffusion returns $b$.
The market data supplies the initial rate.
To add a model, define a subtype and its drift and diffusion methods.
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
FinancialDerivatives.Models.BrennanSchwartzModule.BrennanSchwartz — Type
Select the one-factor Brennan-Schwartz model of the short rate.
The short rate $r$ follows
\[dr = k (θ - r)\,dt + σ\,r\,dW\]
The diffusion term is proportional to $r$. The InterestRateMarketData supplies the initial rate.
References
- Brennan, M. J., and Schwartz, E. S. (1980). Analyzing convertible bonds. The Journal of Financial and Quantitative Analysis, 15(4), 907-929. doi:10.2307/2330567
FinancialDerivatives.Models.CoxIngersollRossModule.CoxIngersollRoss — Type
Select the Cox-Ingersoll-Ross model of the short rate.
The short rate $r$ follows
\[dr = k (θ - r)\,dt + σ \sqrt{r}\,dW\]
The diffusion term is proportional to $\sqrt{r}$. The InterestRateMarketData supplies the initial rate.
References
- Cox, J. C., Ingersoll, J. E., and Ross, S. A. (1985). A theory of the term structure of interest rates. Econometrica, 53(2), 385-407. doi:10.2307/1911242
FinancialDerivatives.Models.RendlemanBartterModule.RendlemanBartter — Type
Select the Rendleman-Bartter model of the short rate.
The short rate $r$ follows
\[dr = θ\,r\,dt + σ\,r\,dW\]
The drift term and the diffusion term are proportional to $r$. The InterestRateMarketData supplies the initial rate.
References
- Rendleman, R. J., and Bartter, B. J. (1980). The pricing of options on debt securities. The Journal of Financial and Quantitative Analysis, 15(1), 11-24. doi:10.2307/2979016
FinancialDerivatives.Models.VasicekModule.Vasicek — Type
Select the Vasicek model of the short rate.
The short rate $r$ follows
\[dr = k (θ - r)\,dt + σ\,dW\]
The diffusion term does not depend on $r$. The InterestRateMarketData supplies the initial rate.
References
- Vasicek, O. (1977). An equilibrium characterization of the term structure. Journal of Financial Economics, 5(2), 177-188. doi:10.1016/0304-405X(77)90016-2
Model interface
FinancialDerivatives.Models.initial_state — Function
initial_state(model, md)Return the state of model at the time zero.
FinancialDerivatives.Models.growth_rate — Function
growth_rate(model, md, t)Return the growth rate of the underlying in the risk-neutral measure for the horizon t.
FinancialDerivatives.Models.drift — Function
drift(model, md, t, x)Return the drift coefficient of the state x of model at the time t, in years.
FinancialDerivatives.Models.diffusion — Function
diffusion(model, md, t, x)Return the diffusion coefficient of the state x of model at the time t, in years.
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.
Pricing and simulation
FinancialDerivatives.Engines.price — Function
price(engine, instrument, model, market_data) -> RealCompute 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.
FinancialDerivatives.Engines.simulate — Function
simulate(engine, model, market_data, t) -> MatrixSimulate 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.
Private
FinancialDerivatives.Instruments.Derivative — Type
Abstract type for derivative contract.
FinancialDerivatives.Instruments.Forward — Type
Abstract type for forward contract.
FinancialDerivatives.Instruments.Future — Type
Abstract type for futures contract.
FinancialDerivatives.Instruments.Option — Type
Abstract type for option.
FinancialDerivatives.Instruments.Swap — Type
Abstract type for swap.
FinancialDerivatives.Instruments.Swaption — Type
Abstract type for swaption.