Logo

SQL Server BinaryBarrierPayoutAtHitPriceNGreeks Function

Updated 2023-11-14 21:16:36.643000

Description

Use the table-valued function BinaryBarrierPayoutAtHitPriceNGreeks to calculate the price and other derivatives for binary barrier options having payoffs that are received the moment that the barrier is breached. These calculations are based on the formulae published by Mark Rubinstein and Eric Reiner in 1991. In their July 31, 1991 paper Binary Options, they enumerated 28 different types of binary barrier options. This function deals with options numbers 1–4:

    (1) down-and-in cash-(at-hit)-or-nothing;

    (2) up-and-in cash-(at-hit)-or-nothing;

    (3) down-and-in asset-(at-hit)-or-nothing; and

    (4) up-and-in asset-(at-hit)-or-nothing.

Syntax

SELECT * FROM [westclintech].[wct].[BinaryBarrierPayoutAtHitPriceNGreeks](
  <@BarrierType, nvarchar(4000),>
 ,<@CashOrNothing, bit,>
 ,<@AssetPrice, float,>
 ,<@StrikePrice, float,>
 ,<@BarrierPrice, float,>
 ,<@Rebate, float,>
 ,<@TimeToMaturity, float,>
 ,<@RiskFreeRate, float,>
 ,<@DividendRate, float,>
 ,<@Volatility, float,>)

Arguments

@BarrierType

identifies the type of barrier as 'UI' (Up-and-In), 'UO' (Up-and-Out), 'DI' (Down-and-In), or 'DO' (Down-and-out). @BarrierType must be of a type nvarchar or of a type that implicitly converts to nvarchar.

@CashOrNothing

identifies the option as either a cash-or-nothing ('True') or asset-or-nothing ('False') binary barrier. @CashOrNothing is an expression of type bit or of a type that can be implicitly converted to bit.

@AssetPrice

the price of the underlying asset. @AssetPrice is an expression of type float or of a type that can be implicitly converted to float.

@StrikePrice

the exercise price of the option. @StrikePrice is an expression of type float or of a type that can be implicitly converted to float.

@BarrierPrice

For a knock-in option, @BarrierPrice is the value at which the option comes into existence if the @AssetPrice crosses the barrier. For a knock-out option, @BarrierPrice is the value at which the option is extinguished if the @AssetPrice crosses the barrier. @BarrierPrice must be of a type float or of a type that implicitly converts to float.

@Rebate

An amount paid to the buyer of the option in the event that the barrier is never breached. @Rebate must be of a type float or of a type that implicitly converts to float.

@TimeToMaturity

the time to expiration of the option, expressed in years. @TimeToMaturity is an expression of type float or of a type that can be implicitly converted to float.

@RiskFreeRate

the continuously compounded zero coupon risk-free rate over the life of the option. @RiskFreeRate is an expression of type float or of a type that can be implicitly converted to float.

@DividendRate

the continuously compounded zero coupon dividend rate over the life of the option. For currency options, @DividendRate should be the foreign risk-free zero coupon rate. @DividendRate is an expression of type float or of a type that can be implicitly converted to float.

@Volatility

the volatility of the relative price change of the underlying asset. @Volatility is an expression of type float or of a type that can be implicitly converted to float.

Return Type

table

colNamecolDatatypecolDesc
PricefloatThe theoretical value of the option.
DeltafloatThe sensitivity to small changes in the asset price; the first derivative of the option with respect to price.
GammafloatThe rate of change in Delta with respect to small changes in the asset price; the second derivative of the option with respect to price.
ThetafloatThe sensitivity to small changes in time; the first derivative of the option with respect to time.
VegafloatThe sensitivity to small changes in volatility; the first derivative of the option with respect to volatility.
RhofloatThe sensitivity to small changes in the risk-free rate; the first derivative of the option with respect to the risk-free rate.
LambdafloatDelta multiplied by the asset price divided by the theoretical value. If the theoretical value is zero, then lambda is set to zero.
GammaPfloatGamma multiplied by asset price divided by strike price.
DdeltaDtimefloatThe instantaneous change in delta over the passage of time; the second derivative, once to asset price and once to time.
DdeltaDvolfloatThe sensitivity of delta with respect to volatility; the second derivative, once to asset price and once to volatility.
DdeltaDvolDvolfloatThe second derivative of delta with respect to volatility; the third derivative, once to asset price and twice to volatility.
DgammaDvolfloatThe rate of change in gamma with respect to changes in volatility; the third derivative, twice to asset price and once to volatility.
DvegaDvolfloatThe rate of change to Vega as the volatility changes; the second derivative with respect to volatility.
VegaPfloatThe percentage change in theoretical value for a 10 per cent change in volatility.
PhiRho2floatThe sensitivity to a change in the dividend yield (foreign interest rate for a currency option); the first derivative with respect to dividend yield.
DgammaDspotfloatThe rate of change in gamma with respect to change in the asset price; the third derivative with respect to price.
DeltaXfloatThe sensitivity to a change in the strike price; the first derivative with respect to strike price.
RiskNeutralDensityfloatThe sensitivity of DeltaX; the second derivative with respect to strike price.
DvommaDvolfloatThe sensitivity of DvegaDvol to changes in volatility; the third derivative, twice to asset price and once to volatility.
DgammaDtimefloatThe sensitivity of Gamma to the passage of time; the third derivative, twice to asset price and once to time. DvegaDtime The sensitivity of Vega to the passage of ti
FuturesOptionsRhofloatThe sensitivity to change in risk-free rate assuming a cost-of-carry of zero.
CarrySensitivityfloat-PhiRho2
ForwardPricefloatThe value of the underlying asset at the expiration date of the option.
ForwardPointsfloatThe difference between the ForwardPrice and the asset price.

Remarks

@Volatility must be greater than zero (@Volatility > 0).

@TimeToMaturity must be greater than zero (@TimeToMaturity > 0).

@AssetPrice must be greater than zero (@AssetPrice > 0).

@StrikePrice must be greater than zero (@StrikePrice > 0).

If @ReturnValue is NULL, then @ReturnValue is set to 'P'.

If @DividendRate is NULL then @DividendRate = 0.

If @RiskFreeRate is NULL @RiskFreeRate = 0.

@BarrierPrice must be greater than zero (@BarrierPrice > 0).

@Rebate must be greater than or equal to zero (@Rebate >= 0).

If @Rebate is NULL, then @Rebate = 0.

@BarrierPrice assumes continuous monitoring.

To convert a non-continuous @BarrierPrice use the ADJUSTEDBARRIER function.

Examples

In this example we calculate the price and Greeks of a down-and-in cash-(at-hit)-or-nothing option.

SELECT *
FROM wct.BinaryBarrierPayoutAtHitPriceNGreeks(   'DI',   --BarrierType
                                                 'True', --CashOrNothing
                                                 100,    --AssetPrice
                                                 100,    --StrikePrice
                                                 92,     --BarrierPrice
                                                 2,      --Rebate
                                                 .05,    --TimeToMaturity
                                                 .10,    --RiskFreeRate
                                                 .05,    --DividendRate
                                                 .20     --Volatility
                                             );

Here is the resultant table.

PriceDeltaGammaThetaVegaRhoLambdaGammaPDdeltaDtimeDdeltaDvolDdeltaDvolDvolDgammaDvolDvegaDvolVegaPPhiRho2DgammaDspotDeltaXRiskNeutralDensityDvommaDvolDgammaDtimeDvegaDtimeFuturesOptionsRhoCarrySensitivityForwardPriceForwardPoints
0.116492416924189-0.05960337186042270.0259861715479204-0.01329183730283930.0257101284791908-0.0025022914003004800.02598617154792040.0040771393567221-0.007943244673125350.0004372497697920090.0009081735983379470.002153654443948220.05142025695838160.0024600284827786-0.0086250389469411100-0.000395468309802860.0904978465935569-0.179924545181927-4.22629167662336E-05-0.0024600284827786100.250312760580.250312760579519

In this SELECT we un-pivot the columns returned by the function for ease of viewing the results.

SELECT n.*
FROM wct.BinaryBarrierPayoutAtHitPriceNGreeks(   'DI',   --BarrierType
                                                 'True', --CashOrNothing
                                                 100,    --AssetPrice
                                                 100,    --StrikePrice
                                                 92,     --BarrierPrice
                                                 2,      --Rebate
                                                 .05,    --TimeToMaturity
                                                 .10,    --RiskFreeRate
                                                 .05,    --DividendRate
                                                 .20     --Volatility
                                             ) k
    CROSS APPLY
(
    VALUES
        ('Price', Price),
        ('Delta', Delta),
        ('Gamma', Gamma),
        ('Theta', Theta),
        ('Vega', Vega),
        ('Rho', Rho),
        ('Lambda', Lambda),
        ('GammaP', GammaP),
        ('DdeltaDtime', DdeltaDtime),
        ('DdeltaDvol', DdeltaDvol),
        ('DdeltaDvolDvol', DdeltaDvolDvol),
        ('DgammaDvol', DgammaDvol),
        ('DvegaDvol', DvegaDvol),
        ('VegaP', VegaP),
        ('PhiRho2', PhiRho2),
        ('DgammaDspot', DgammaDspot),
        ('DeltaX', DeltaX),
        ('RiskNeutralDensity', RiskNeutralDensity),
        ('DvommaDvol', DvommaDvol),
        ('DgammaDtime', DgammaDtime),
        ('DvegaDtime', DvegaDtime),
        ('FuturesOptionsRho', FuturesOptionsRho),
        ('CarrySensitivity', CarrySensitivity),
        ('ForwardPrice', ForwardPrice),
        ('ForwardPoints', ForwardPoints)
) n ([Return Value], Value);

This produces the following result.

Return ValueValue
Price0.116492416924189
Delta-0.059603371860284
Gamma0.0259861715479204
Theta-0.0132918373028393
Vega0.0257101284791915
Rho-0.00250229140030256
Lambda0
GammaP0.0259861715479204
DdeltaDtime0.00407713935862317
DdeltaDvol-0.00794324465924756
DdeltaDvolDvol0.00043724976979409
DgammaDvol0.00090817359812978
DvegaDvol0.00215365444436455
VegaP0.051420256958383
PhiRho20.00246002848277652
DgammaDspot-0.00862503893306332
DeltaX0
RiskNeutralDensity0
DvommaDvol-0.000395468309802832
DgammaDtime0.0904978465936139
DvegaDtime-0.179924545179075
FuturesOptionsRho-4.22629167655397E-05
CarrySensitivity-0.00246002848277652
ForwardPrice100.25031276058
ForwardPoints0.250312760579519

Use CROSS APPLY when there are many input rows.

SELECT CASE n.cash
           WHEN 'True' THEN
               'CASH'
           ELSE
               'ASSET'
       END as CA,
       n.K,
       k.Price,
       K.Delta,
       K.Gamma,
       K.Theta,
       K.Vega,
       K.Rho
FROM
(
    VALUES
        (1, 'DI', 'True', 100, 100, 92, 2, .50, .10, .05, .20),
        (2, 'DI', 'True', 100, 100, 96, 2, .50, .10, .05, .20),
        (3, 'DI', 'True', 100, 100, 100, 2, .50, .10, .05, .20),
        (4, 'UI', 'True', 100, 100, 104, 2, .50, .10, .05, .20),
        (5, 'UI', 'True', 100, 100, 108, 2, .50, .10, .05, .20),
        (6, 'DI', 'False', 100, 100, 92, 92, .50, .10, .05, .20),
        (7, 'DI', 'False', 100, 100, 96, 96, .50, .10, .05, .20),
        (8, 'DI', 'False', 100, 100, 100, 100, .50, .10, .05, .20),
        (9, 'UI', 'False', 100, 100, 104, 104, .50, .10, .05, .20),
        (10, 'UI', 'False', 100, 100, 108, 108, .50, .10, .05, .20)
) n (rn, bt, cash, S, X, K, H, T, Rf, Rd, Vol)
    CROSS APPLY wct.BinaryBarrierPayoutAtHitPriceNGreeks(bt, cash, S, X, K, H, T,
              Rf, Rd, Vol) k;

Here are the results.

CAKPriceDeltaGammaThetaVegaRho
CASH921.02274787839312-0.09685892193189720.00644595488097366-0.001932313885453230.0483273384070948-0.0245476704039849
CASH961.48240181937219-0.1184821676458720.00572986103009043-0.001115102640520060.0298672594598259-0.0177208679012386
CASH1002-0.134056977413310.00435140812271584000
CASH1041.592413077214330.1025431390921930.000306976666308856-0.001141308678813010.01504743427895860.0129257645991032
CASH1081.21896026417960.09434444109612810.00200326422117314-0.002064018635074880.02863814565873260.0198364568311793
ASSET9247.0464024060835-4.455510408831740.296513746889104-0.08888643873084592.22305756672654-1.12919283858339
ASSET9671.155287329865-5.687144047001880.275032618901605-0.053524926744971.43362845407182-0.850601659259809
ASSET100100-6.702848870645540.217571027860686000
ASSET10482.80548001514535.332243232771820.0159616320161149-0.05934805129827230.7824665825054920.672139759153367
ASSET10865.82385426569845.094599819202020.108177289348532-0.1114570062940321.546459865571851.07116866888362