Logo

SQL Server BinaryBarrierOnlyPriceNGreeks Function

Updated 2023-11-14 21:10:52.037000

Description

Use the table-valued function BinaryBarrierOnlyPriceNGreeks to calculate the price and other derivatives for binary barrier options having payoffs that are received only at expiration. Down-and-in and up-and-in options have positive payoffs if the barrier is breached at some time before expiration. Down-and-out and Up-and-out options have positive payoffs if the barrier is not breached before expiration.

BinaryBarrierOnlyPriceNGreeks valuations 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 5–12:

    (5) down-and-in cash-(at-expiry)-or-nothing;

    (6) up-and-in cash-(at-expiry)-or-nothing;

    (7) down-and-in asset-(at-expiry)-or-nothing;

    (8) up-and-in asset-(at-expiry)-or-nothing;

    (9) down-and-out cash-or-nothing;

    (10) up-and-out cash-or-nothing;

    (11) down-and-out asset-or-nothing; and

    (12) up-and-out asset-or-nothing.

Syntax

SELECT * FROM [westclintech].[wct].[BinaryBarrierOnlyPriceNGreeks](
  <@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
Pricefloat The 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.
DvegaDtimefloatThe sensitivity of Vega to the passage of time; the second derivative, once to volatility and once to time.
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.

Use BinaryBarrierOnly for a single return value.

Examples

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

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

This produces the following result.

PriceDeltaGammaThetaVegaRhoLambdaGammaPDdeltaDtimeDdeltaDvolDdeltaDvolDvolDgammaDvolDvegaDvolVegaPPhiRho2DgammaDspotDeltaXRiskNeutralDensityDvommaDvolDgammaDtimeDvegaDtimeFuturesOptionsRhoCarrySensitivityForwardPriceForwardPoints
0.990650335835426-0.09218219920781310.00581755754680557-0.001661130041410890.0461322337422021-0.026955329915079300.00581755754680557-0.0001614291272953860.002761234380033176.69511645345899E-05-0.000727088308449808-0.003698596022783110.09226446748440420.02200207819658689.76890790482798E-06000.000347967943149396-0.0002319264024361980.00528397406499281-0.0049532516812445-0.0220020781965868102.5315120524432.53151205244289

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

SELECT n.*
FROM wct.BinaryBarrierOnlyPriceNGreeks(   'DI',   --BarrierType
                                          'True', --CashOrNothing
                                          100,    --AssetPrice
                                          100,    --StrikePrice
                                          92,     --BarrierPrice
                                          2,      --Rebate
                                          .50,    --TimeToMaturity
                                          .10,    --RiskFreeRate
                                          .05,    --DividendRate
                                          .20     --Volatility
                                      )
    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.990650335835426
Delta-0.0921821992078131
Gamma0.00581755754680557
Theta-0.00166113004141066
Vega0.0461322337422132
Rho-0.0269553299150849
Lambda0
GammaP0.00581755754680557
DdeltaDtime-0.000161429127295386
DdeltaDvol0.00276123440778875
DdeltaDvolDvol6.69511645234877E-05
DgammaDvol-0.000727088304008916
DvegaDvol-0.00369859602500355
VegaP0.0922644674844264
PhiRho20.0220020781965924
DgammaDspot9.76890790482798E-06
DeltaX0
RiskNeutralDensity0
DvommaDvol0.000347967943149729
DgammaDtime-0.000231926402740369
DvegaDtime0.00528397407259708
FuturesOptionsRho-0.0049532516812445
CarrySensitivity-0.0220020781965924
ForwardPrice102.531512052443
ForwardPoints2.53151205244289

Use CROSS APPLY when there are many input rows.

SELECT n.bt,
       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, 'DO', 'True', 100, 100, 92, 2, .50, .10, .05, .20),
        (7, 'DO', 'True', 100, 100, 96, 2, .50, .10, .05, .20),
        (8, 'DO', 'True', 100, 100, 100, 2, .50, .10, .05, .20),
        (9, 'UO', 'True', 100, 100, 104, 2, .50, .10, .05, .20),
        (10, 'UO', 'True', 100, 100, 108, 2, .50, .10, .05, .20)
) n (rn, bt, cash, S, X, K, H, T, Rf, Rd, Vol)
    CROSS APPLY wct.BinaryBarrierOnlyPriceNGreeks(bt, cash, S, X, K, H, T, Rf, Rd,
              Vol) k;

Here are the results.

btKPriceDeltaGammaThetaVegaRho
DI920.990650335835426-0.09218219920781310.00581755754680557-0.001661130041410890.0461322337422021-0.0269553299150793
DI961.42435048693473-0.1107670471400810.00479583039947329-0.0007249687249073490.0280744402327948-0.0227382501014506
DI1001.90245884900143-0.1222063805095260.003055045105782030.000521293009206669-1.11022302462516E-14-0.00951229424895894
UI1041.52952208970690.0951573616503332-0.000304734015799113-0.000722360262711330.01380368237461350.00622958369623783
UI1081.179427429808840.08925596466480280.001520894521434-0.001741125967602560.02693344565810610.0152820591040381
DO920.9118085131660020.0921821992067029-0.005817557546805570.00218242305061755-0.04613223374221320.0174430356661093
DO960.4781083620667010.110767047140081-0.00479580819501280.00124626173411413-0.02807444023279480.0132259558524861
DO10000.122206380508416-0.00305502290132154000
UO1040.372936759294533-0.09515736164977810.0003047451180293590.001243653271918-0.0138036823746135-0.0157418779451968
UO1080.723031419192591-0.0892559646648028-0.001520916725894490.00226241897680923-0.0269334456581172-0.0247943533530193