hasquant
Safe HaskellNone
LanguageHaskell2010

QuantLib.Instrument.Option

Synopsis

Types

Option hierarchy

type GenOption o = GenInstrument (AnyOf COption' o) Source #

type Option = GenOption COption Source #

An Instrument; see the hierarchy under GenInstrument.

type GenOneAssetOption oo = GenOption (AnyOf COneAssetOption' oo) Source #

type OneAssetOption = GenOneAssetOption COneAssetOption Source #

An Option; see the hierarchy under GenInstrument.

type GenMultiAssetOption mo = GenOption (AnyOf CMultiAssetOption' mo) Source #

type MultiAssetOption = GenMultiAssetOption CMultiAssetOption Source #

An Option; see the hierarchy under GenInstrument.

type CdsOption = GenOption CCdsOption Source #

An Option; see the hierarchy under GenInstrument.

type BarrierOption = GenOneAssetOption CBarrierOption Source #

An OneAssetOption; see the hierarchy under GenInstrument.

type DoubleBarrierOption = GenOneAssetOption CDoubleBarrierOption Source #

An OneAssetOption; see the hierarchy under GenInstrument.

type EverestOption = GenMultiAssetOption CEverestOption Source #

A MultiAssetOption; see the hierarchy under GenInstrument.

type MargrabeOption = GenMultiAssetOption CMargrabeOption Source #

A MultiAssetOption; see the hierarchy under GenInstrument.

type QuantoBarrierOption = GenOneAssetOption CQuantoBarrierOption Source #

An OneAssetOption; see the hierarchy under GenInstrument.

type QuantoDoubleBarrierOption = GenOneAssetOption CQuantoDoubleBarrierOption Source #

An OneAssetOption; see the hierarchy under GenInstrument.

type QuantoForwardVanillaOption = GenOneAssetOption CQuantoForwardVanillaOption Source #

An OneAssetOption; see the hierarchy under GenInstrument.

type QuantoVanillaOption = GenOneAssetOption CQuantoVanillaOption Source #

An OneAssetOption; see the hierarchy under GenInstrument.

type SoftBarrierOption = GenOneAssetOption CSoftBarrierOption Source #

An OneAssetOption; see the hierarchy under GenInstrument.

type VanillaOption = GenOneAssetOption CVanillaOption Source #

An OneAssetOption; see the hierarchy under GenInstrument.

Exercises

data Exercise Source #

Exercise
 American
 Early
 Vanilla
 EuropeanExercise
 BermudanExercise
   SwingExercise
 Rebated (wraps another Exercise)

Constructors

American 

Fields

Early !ExerciseType !Bool 
Vanilla !ExerciseType 
European !EuropeanExercise 
Bermudan !BermudanExercise 
Rebated 

Fields

data SwingExercise Source #

Use swingExerice to construct Exercise

Constructors

SwingListExercise !(NonEmpty (Day, Word))

(dates, seconds)

SwingIntervalExercise !Day !Day !Word

stepSizeSecs

Option conventions

Payoffs

data StrikedPayoff Source #

use strikedPayoff to construct Payoff

Constructors

AssetOrNothing 

Fields

CashOrNothing 

Fields

Gap 

Fields

PercentageStrike !PercentageStrikePayoff 
PlainVanilla !PlainVanillaPayoff 
SuperFund 

Fields

SuperSharePayoff 

Fields

CustomStriked 

Fields

data PlainVanillaPayoff Source #

use plainVanillaPayoff to construct Payoff

Constructors

PlainVanillaPayoff 

Fields

data BasketPayoff Source #

Constructors

Average 

Fields

AverageMultiple 

Fields

Max !Payoff

p

Min !Payoff

p

Spread !Payoff

p |A Haskell-defined accumulate over the underlying-state vector, wrapped around a base Payoff exactly as Max/Min/Spread are. Build it with withCustomBasketPayoff.

CustomAccumulate 

Fields

  • !Payoff

    base payoff, applied to the accumulated value

  • !(FunPtr BasketAccumulateFun)
     

data Payoff Source #

Payoff
 DoubleStickyRatchet
 ForwardType
 RatchettMax
 RatchetMin
 StickyMax
 StickyMin
 Sticky
 Custom
 TypePayoff
   Floating
   Striked
     AssetOrNothing
     CashOrNothing
     Gap
     PercentageStrike
     PlainVanilla
     SuperFund
     SuperSharePayoff
     CustomStriked
 BasketPayoff
   Average
   AverageMultiple
   Max
   Min
   Spread
   CustomAccumulate

Constructors

DoubleStickyRatchet 

Fields

ForwardType 

Fields

RatchetMax 

Fields

RatchetMin 

Fields

Ratchet 

Fields

StickyMax 

Fields

StickyMin 

Fields

Sticky 

Fields

Type !TypePayoff 
Basket !BasketPayoff 
Custom

A Haskell-defined payoff. Build it with withCustomPayoff rather than by hand: the FunPtr must stay alive for as long as anything can still call the payoff, which withCustomPayoff arranges and a hand-built value does not.

Fields

Constructors

Hierarchy conversion

Payoffs and exercises

withCustomPayoff Source #

Arguments

:: String

name

-> String

description

-> (Double -> Double)

payoff(price)

-> (Payoff -> IO b) 
-> IO b 

Wrap a Haskell price -> value function as a real QuantLib Payoff, usable anywhere a Payoff is (QuantLib.Instrument.Option.oneAssetOption, multiAssetOption, QuantLib.Instrument.Swap.varianceOption, QuantLib.Method.fdmLogInnerValue, fdmCellAveragingInnerValue, ...) -- the fully custom counterpart to the concrete pre-implemented payoffs listed by the Payoff constructors above.

The payoff is valid only inside the continuation, and the continuation must span the whole use, not just the construction: every consumer stores the payoff and calls back into it later (an Instrument at NPV time, an FdmInnerValueCalculator at fdmSolve time), so pricing must happen before this function returns. Same lifetime rule, and the same reason, as QuantLib.Method.withCustomFdmInnerValueCalculator.

name and description are what QuantLib's own error messages and Payoff::name report; they are not interpreted.

Not every engine accepts a non-standard payoff. QuantLib's analytic, binomial, finite- difference and MCEuropeanEngine families all recover the strike by downcasting to StrikedTypePayoff/PlainVanillaPayoff first, and a further ~30 engines route through BlackCalculator, whose AcyclicVisitor knows only the four built-in striked payoffs. Most of these fail with a clean QuantLib exception, but QuantLib.PricingEngine.fdBlackScholesVanillaEngine and QuantLib.PricingEngine.fdHestonVanillaEngine perform that downcast unchecked upstream and will crash the process, not throw, on a custom payoff. Confirmed-generic consumers: QuantLib.Method.fdmLogInnerValue/fdmCellAveragingInnerValue (and hence fdmSolve), and QuantLib.PricingEngine.mcAmericanEngine with controlVariate = False.

withCustomStrikedPayoff Source #

Arguments

:: OptionType

advisory option type

-> Double

advisory strike (grid centring only)

-> String

name

-> (Double -> Double)

payoff(price)

-> (StrikedPayoff -> IO b) 
-> IO b 

As withCustomPayoff, but produces a real QuantLib StrikedTypePayoff carrying an (optionType, strike) pair alongside the Haskell function.

The pair is advisory: it does not define the payoff -- payoff(price) alone does, exactly as for withCustomPayoff. It exists because QuantLib's finite-difference vanilla engines reach past the Payoff interface for a strike when sizing their grid: FdBlackScholesVanillaEngine dynamic_pointer_casts to StrikedTypePayoff without a check and calls strike() twice -- once for the mesher's extent, once for its node-concentration point -- then hands the payoff itself to FdmLogInnerValue, which takes a plain Payoff. So a payoff built here prices correctly through fdBlackScholesVanillaEngine and fdHestonVanillaEngine, where one built by withCustomPayoff would crash the process on that unchecked cast. Pass the strike you want the grid centred on.

Everything else matches withCustomPayoff, including the continuation-lifetime rule: the payoff is valid only inside the continuation, which must span the whole use (pricing included), not just construction. description is not a parameter here -- StrikedTypePayoff derives it from the type and strike itself.

Engines routing through BlackCalculator (the analytic* family) still reject this, as they must: its AcyclicVisitor knows only the four built-in striked payoffs, and there is no closed-form price for an arbitrary function. That rejection is a clean QuantLib exception.

withCustomBasketPayoff Source #

Arguments

:: Payoff

base payoff

-> ([Double] -> Double)

accumulate(underlyings)

-> (BasketPayoff -> IO b) 
-> IO b 

Wrap a Haskell underlyings -> accumulated function as a real QuantLib BasketPayoff around base (which is applied to the accumulated value, exactly as for Max/Min/Spread) -- usable with QuantLib.Instrument.Option.basketOption and QuantLib.Method.fdmLogBasketInnerValue. Same continuation-lifetime rule as withCustomPayoff; unlike it, this callback crosses once per evaluation with the whole underlying-state vector, because that is the shape BasketPayoff::accumulate already has upstream.

Barrier, chooser and multi-asset options

barrierOption Source #

Arguments

:: BarrierType 
-> Double

barrier

-> Double

rebate

-> StrikedPayoff 
-> Exercise 
-> IO BarrierOption 

Barrier option on a single asset.

partialTimeBarrierOption Source #

Arguments

:: BarrierType 
-> PartialBarrierRange 
-> Double

barrier

-> Double

rebate

-> Day

coverEventDate

-> StrikedPayoff 
-> Exercise 
-> IO OneAssetOption 

Barrier option on a single asset that is only monitored for part of its life (a partial-time barrier).

doubleBarrierOption Source #

Arguments

:: DoubleBarrierType 
-> Double

barrierLo

-> Double

barrierHi

-> Double

rebate

-> StrikedPayoff 
-> Exercise 
-> IO DoubleBarrierOption 

Double-barrier option on a single asset, with a lower and an upper barrier.

softBarrierOption Source #

Arguments

:: BarrierType 
-> Double

barrierLo

-> Double

barrierHi

-> StrikedPayoff 
-> Exercise 
-> IO SoftBarrierOption 

Soft barrier option on a single asset: knocked in/out proportionally over a barrier range [barrierLo, barrierHi], rather than in full at a single hard barrier. European exercise only.

forwardVanillaOption Source #

Arguments

:: Double

moneyness

-> Day

resetDate

-> StrikedPayoff 
-> Exercise 
-> IO OneAssetOption 

Forward-starting (strike-resetting) version of a vanilla option.

compoundOption Source #

Arguments

:: StrikedPayoff

motherPayoff

-> Exercise

motherExercise

-> StrikedPayoff

daughterPayoff

-> Exercise

daughterExercise

-> IO OneAssetOption 

Compound option (an option on another option) on a single asset. The mother option is the compound option itself; the daughter option is its underlying.

margrabeOption Source #

Arguments

:: Int

Q1

-> Int

Q2

-> Exercise 
-> IO MargrabeOption 

Margrabe option on two assets: the right to exchange Q2 units of the second asset for Q1 units of the first at expiration.

simpleChooserOption Source #

Arguments

:: Day

choosingDate

-> Double

strike

-> Exercise 
-> IO OneAssetOption 

Simple chooser option on a single asset: the holder chooses, on the choosing date, whether the option is a call or a put; both share the same strike and exercise date.

complexChooserOption Source #

Arguments

:: Day

choosingDate

-> Double

strikeCall

-> Double

strikePut

-> Exercise

exerciseCall

-> Exercise

exercisePut

-> IO OneAssetOption 

Complex chooser option: on the choosing date the holder selects between a call and a put with independent strikes and exercise dates.

twoAssetCorrelationOption Source #

Arguments

:: OptionType

type

-> Double

strike1

-> Double

strike2

-> Exercise 
-> IO MultiAssetOption 

Two-asset correlation option: pays a payoff based on the second asset's value against strike2 at exercise, but only if the first asset is also in the money against strike1; otherwise pays 0.

writerExtensibleOption Source #

Arguments

:: PlainVanillaPayoff

payoff1

-> Exercise

exercise1

-> PlainVanillaPayoff

payoff2

-> Exercise

exercise2

-> IO OneAssetOption 

Writer-extensible option on a single asset: if out of the money at the first exercise, it is extended to a second exercise with an amended payoff.

holderExtensibleOption Source #

Arguments

:: OptionType

type

-> Double

premium

-> Day

secondExpiryDate

-> Double

secondStrike

-> StrikedPayoff

payoff

-> Exercise

exercise

-> IO OneAssetOption 

Holder-extensible option: the holder may pay premium at the first exercise to replace its payoff with an option at secondExpiryDate and secondStrike.

Vanilla, quanto and path-dependent options

multiAssetOption :: Payoff -> Exercise -> IO MultiAssetOption Source #

Base construction for an option on multiple assets.

oneAssetOption :: Payoff -> Exercise -> IO OneAssetOption Source #

Base construction for an option on a single asset.

quantoBarrierOption Source #

Arguments

:: BarrierType 
-> Double

barrier

-> Double

rebate

-> StrikedPayoff 
-> Exercise 
-> IO QuantoBarrierOption 

Quanto version of a barrier option on a single asset.

quantoDoubleBarrierOption Source #

Arguments

:: DoubleBarrierType 
-> Double

barrierLo

-> Double

barrierHi

-> Double

rebate

-> StrikedPayoff 
-> Exercise 
-> IO QuantoDoubleBarrierOption 

Quanto version of a double-barrier option on a single asset, with a lower and an upper barrier.

quantoForwardVanillaOption Source #

Arguments

:: Double

moneyness

-> Day

resetDate

-> StrikedPayoff 
-> Exercise 
-> IO QuantoForwardVanillaOption 

Quanto version of a forward-starting (strike-resetting) vanilla option.

quantoVanillaOption :: StrikedPayoff -> Exercise -> IO QuantoVanillaOption Source #

Quanto version of a vanilla option on a single asset.

twoAssetBarrierOption Source #

Arguments

:: BarrierType 
-> Double

barrier

-> StrikedPayoff 
-> Exercise 
-> IO Instrument 

Barrier option on two assets: the first asset's value is compared to the strike to determine the payoff, while the second asset's value is monitored against the barrier.

vanillaOption :: StrikedPayoff -> Exercise -> IO VanillaOption Source #

Vanilla option (no discrete dividends, no barriers) on a single asset.

basketOption :: BasketPayoff -> Exercise -> IO MultiAssetOption Source #

Basket option on a number of assets, combined by the given basket payoff (e.g. minmaxspread/average).

cliquetOption Source #

Arguments

:: PercentageStrikePayoff 
-> EuropeanExercise

maturity

-> [Day]

resetDates

-> IO OneAssetOption 

Cliquet (ratchet) option: a series of forward-starting options where each period's strike is set to a fixed percentage of the spot price at the start of that period.

continuousAveragingAsianOption :: AverageType -> StrikedPayoff -> Exercise -> IO OneAssetOption Source #

Continuous-averaging Asian option on a single asset, for an unseasoned (fresh) option where averaging has not yet started.

continuousFixedLookbackOption Source #

Arguments

:: Double

currentMinmax

-> StrikedPayoff 
-> Exercise 
-> IO OneAssetOption 

Continuous-fixed lookback option: the payoff uses the fixed strike against the minimum/maximum price observed over the option's life.

continuousFloatingLookbackOption Source #

Arguments

:: Double

currentMinmax

-> TypePayoff 
-> Exercise 
-> IO OneAssetOption 

Continuous-floating lookback option: the strike is set to the minimum/maximum price observed over the option's life.

continuousPartialFixedLookbackOption Source #

Arguments

:: Day

lookbackPeriodStart

-> StrikedPayoff 
-> Exercise 
-> IO OneAssetOption 

Partial-time fixed-strike lookback option: the lookback period runs from lookbackPeriodStart to expiry, cheaper than a full fixed lookback. Priced analytically by Heynen and Kat (1994).

continuousPartialFloatingLookbackOption Source #

Arguments

:: Double

currentMinmax

-> Double

lambda

-> Day

lookbackPeriodEnd

-> TypePayoff 
-> Exercise 
-> IO OneAssetOption 

Partial-time floating-strike lookback option: the lookback period runs from inception to lookbackPeriodEnd, cheaper than a full floating lookback. lambda scales the strike relative to the observed extremum. Priced analytically by Heynen and Kat (1994).

everestOption Source #

Arguments

:: Double

notional

-> Double

guarantee

-> Exercise 
-> IO EverestOption 

The excess return over guarantee, realized on the worst-performing of a basket of assets and paid out on notional at exercise.

discreteAveragingAsianOption Source #

Arguments

:: AverageType 
-> Double

runningAccumulator, the running sum or products of past fixings

-> Word

pastFixings

-> [Day]

fixingDates

-> StrikedPayoff 
-> Exercise 
-> IO OneAssetOption 

Discrete-averaging Asian option on a single asset, taking the running sum/product of past fixings plus a list of future fixing dates.

vanillaStorageOption Source #

Arguments

:: BermudanExercise 
-> Double 
-> Double

load

-> Double

changeRate

-> IO OneAssetOption 

Storage option (e.g. a gas storage facility): a payoff-free instrument exercisable on a Bermudan schedule, with a maximum capacity, load/withdrawal rate, and per-period rate of change.

vanillaSwingOption Source #

Arguments

:: StrikedPayoff 
-> SwingExercise 
-> Word

minExerciseRights

-> Word

maxExerciseRights

-> IO OneAssetOption 

Swing option: a payoff exercisable a bounded number of times (between minExerciseRights and maxExerciseRights) at the dates of a SwingExercise.

europeanOption :: StrikedPayoff -> Exercise -> IO VanillaOption Source #

European (single-exercise-date) vanilla option on a single asset.

Inspectors

Implied volatility

class HasImpliedVol a where Source #

Methods

impliedVolatility Source #

Arguments

:: a 
-> Double

price

-> GeneralizedBlackScholesProcess

process

-> [Dividend]

dividends

-> Double

accuracy

-> Word

maxEvaluations

-> Double

minVol

-> Double

maxVol

-> IO Double 

doubleBarrierOptionImpliedVolatility Source #

Arguments

:: DoubleBarrierOption 
-> Double

price

-> GenGeneralizedBlackScholesProcess gbs 
-> Double

accuracy

-> Word

maxEvaluations

-> Double

minVol

-> Double

maxVol

-> IO Double 

Implied Black-Scholes volatility that reproduces the given price for a DoubleBarrierOption; see VanillaOption's implied-volatility for the caveats on reliability.

softBarrierOptionImpliedVolatility Source #

Arguments

:: SoftBarrierOption 
-> Double

price

-> GenGeneralizedBlackScholesProcess gbs 
-> Double

accuracy

-> Word

maxEvaluations

-> Double

minVol

-> Double

maxVol

-> IO Double 

Implied Black-Scholes volatility that reproduces the given price for a SoftBarrierOption; see VanillaOption's implied-volatility for the caveats on reliability.

Sensitivities and probabilities

firstAssetDelta :: MargrabeOption -> IO Double Source #

Sensitivity of a MargrabeOption's value to the price of the first asset.

secondAssetDelta :: MargrabeOption -> IO Double Source #

Sensitivity of a MargrabeOption's value to the price of the second asset.

firstAssetGamma :: MargrabeOption -> IO Double Source #

Second derivative of a MargrabeOption's value with respect to the price of the first asset.

secondAssetGamma :: MargrabeOption -> IO Double Source #

Second derivative of a MargrabeOption's value with respect to the price of the second asset.

deltaForward :: GenOneAssetOption oo -> IO Double Source #

Sensitivity of the option's value to the forward price of the underlying.

elasticity :: GenOneAssetOption oo -> IO Double Source #

Percentage change in the option's value per percentage change in the underlying price.

itmCashProbability :: GenOneAssetOption oo -> IO Double Source #

Probability of the option expiring in-the-money in a cash-or-nothing sense.

strikeSensitivity :: GenOneAssetOption oo -> IO Double Source #

Sensitivity of the option's value to the strike price.

thetaPerDay :: GenOneAssetOption oo -> IO Double Source #

Theta divided by the number of days elapsed per day (as opposed to per year).

yield :: EverestOption -> IO Double Source #

The realized yield on the notional, i.e. NPV/(notional*discount) - 1.