Logo

BinaryBarrierOnly

Updated 2024-02-13 20:43:43.103000

Syntax

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

Description

Use BinaryBarrierOnly to calculate the price or Greeks 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.

BinaryBarrierOnly 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.

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.

@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.

@ReturnValue

identifies the calculation to be performed. @ReturnValue is an expression of type nvarchar or of a type that can be implicitly converted to nvarchar. For a full description of the return values, see BINARYBARRIERONLYPRICENGREEKS.@ReturnValue is not case-sensitive. The following values are acceptable for @ReturnValue:

{
    "columns": [
        {
            "field": "@ReturnValue"
         },
        {
            "field": "Returns"
        }
    ],
    "rows": [
        {
            "@ReturnValue": "'P','PRICE'",
            "Returns": "Price"
        },
        {
            "@ReturnValue": "'D','DELTA'",
            "Returns": "Delta"
        },
        {
            "@ReturnValue": "'G','GAMMA'",
            "Returns": "Gamma"
        },
        {
            "@ReturnValue": "'T','THETA'",
            "Returns": "Theta"
        },
        {
            "@ReturnValue": "'V','VEGA'",
            "Returns": "Vega"
        },
        {
            "@ReturnValue": "'R','RHO'",
            "Returns": "Rho"
        },
        {
            "@ReturnValue": "'L','LAMBDA'",
            "Returns": "Lambda"
        },
        {
            "@ReturnValue": "'DDDV','VANNA','DVEGADSPOT','DDELTADVOL'",
            "Returns": "DdeltaDvol"
        },
        {
            "@ReturnValue": "'DVV','DDELTADVOLDVOL'",
            "Returns": "DdeltaDvolDvol"
        },
        {
            "@ReturnValue": "'DT','CHARM','DDELTADTIME'",
            "Returns": "DdeltaDtime"
        },
        {
            "@ReturnValue": "'GV','ZOMMA','DGAMMADVOL'",
            "Returns": "DgammaDvol"
        },
        {
            "@ReturnValue": "'GP','GAMMAP'",
            "Returns": "GammaP"
        },
        {
            "@ReturnValue": "'DVDV','VOMMA','VOLGA','DVEGADVOL'",
            "Returns": "DvegaDvol"
        },
        {
            "@ReturnValue": "'VP','VEGAP'",
            "Returns": "VegaP"
        },
        {
            "@ReturnValue": "'PR2','PHIRHO2'",
            "Returns": "PhiRho2"
        },
        {
            "@ReturnValue": "'S','SPEED','DGAMMADSPOT'",
            "Returns": "DgammaDspot"
        },
        {
            "@ReturnValue": "'DX','DELTAX'",
            "Returns": "Delta X"
        },
        {
            "@ReturnValue": "'GX','GAMMAX','DX','RND','RISKNEUTRALDENSITY'",
            "Returns": "Risk Neutral Density"
        },
        {
            "@ReturnValue": "'VVV','ULTIMA','DVOMMADVOL'",
            "Returns": "DvommaDvol"
        },
        {
            "@ReturnValue": "'VT','VETA','DVEGADTIME'",
            "Returns": "DvegaDtime"
        },
        {
            "@ReturnValue": "'GT','COLOR','DGAMMADTIME'",
            "Returns": "DgammaDtime"
        },
        {
            "@ReturnValue": "'FR','RHOFUTURESOPTIONS','FUTURESOPTIONSRHO'",
            "Returns": "Futures Options Rho"
        },
        {
            "@ReturnValue": "'B','CARRYSENSITIVITY'",
            "Returns": "Carry Sensitivity"
        }
    ]
}

@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.

@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.

@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.

@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.

@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.

@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.

@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.

Return Type

float

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 BINARYBARRIERONLYPRICENGREEKS to calculate the price and all the Greeks.

Examples

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

SELECT wct.BinaryBarrierOnly(   'DI',   --BarrierType
                                'True', --CashOrNothing
                                100,    --AssetPrice
                                100,    --StrikePrice
                                92,     --BarrierPrice
                                2,      --Rebate
                                .50,    --TimeToMaturity
                                .10,    --RiskFreeRate
                                .05,    --DividendRate
                                .20,    --Volatility
                                'P'     --ReturnValue
                            ) as Price;

This produces the following result.

{"columns":[{"field":"Price","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Price":"0.990650335835426"}]}

This SQL returns delta for the same option.

SELECT wct.BinaryBarrierOnly(   'DI',   --BarrierType
                                'True', --CashOrNothing
                                100,    --AssetPrice
                                100,    --StrikePrice
                                92,     --BarrierPrice
                                2,      --Rebate
                                .50,    --TimeToMaturity
                                .10,    --RiskFreeRate
                                .05,    --DividendRate
                                .20,    --Volatility
                                'D'     --ReturnValue
                            ) as 'Delta';

This produces the following result.

{"columns":[{"field":"Delta","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Delta":"-0.0921821992078131"}]}

This SELECT statement reproduces the table for cash-or-nothing where Call/Put = Both from the Binary Options paper by Mark Rubenstein and Eric Reiner, July 31, 1991.

SELECT *
FROM
(
    SELECT 'OUT' as [OUT/IN],
           n.T,
           n2.H,
           wct.BinaryBarrierOnly(   CASE
                                        WHEN n2.H <= 100 THEN
                                            'DO'
                                        ELSE
                                            'UO'
                                    END,
                                    'True',
                                    100,
                                    100,
                                    n2.H,
                                    2,
                                    n.T,
                                    .10,
                                    .05,
                                    .20,
                                    'P'
                                ) as Price
    FROM
    (
        VALUES
            (.05),
            (.50),
            (.95)
    ) n (T)
        CROSS APPLY
    (
        VALUES
            (92),
            (96),
            (100),
            (104),
            (108)
    ) n2 (H)
    UNION ALL
    SELECT 'IN',
           n.T,
           n2.H,
           wct.BinaryBarrierOnly(   CASE
                                        WHEN n2.H <= 100 THEN
                                            'DI'
                                        ELSE
                                            'UI'
                                    END,
                                    'True',
                                    100,
                                    100,
                                    n2.H,
                                    2,
                                    n.T,
                                    .10,
                                    .05,
                                    .20,
                                    'P'
                                ) as Price
    FROM
    (
        VALUES
            (.05),
            (.50),
            (.95)
    ) n (T)
        CROSS APPLY
    (
        VALUES
            (92),
            (96),
            (100),
            (104),
            (108)
    ) n2 (H)
) D
PIVOT
(
    SUM(Price)
    for T in ([.05], [.50], [.95])
) as P
ORDER BY 1;

Here are the results of this query.

{"columns":[{"field":"OUT/IN"},{"field":"H","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":".05","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":".50","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":".95","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"OUT/IN":"IN","H":"92",".05":"0.116332741515103",".50":"0.990650335835426",".95":"1.13926655655622"},{"OUT/IN":"IN","H":"96",".05":"0.697206534976101",".50":"1.42435048693473",".95":"1.46893372615867"},{"OUT/IN":"IN","H":"100",".05":"1.99002495838536",".50":"1.90245884900143",".95":"1.81874586893646"},{"OUT/IN":"IN","H":"104",".05":"0.779567765456951",".50":"1.5295220897069",".95":"1.57190933249169"},{"OUT/IN":"IN","H":"108",".05":"0.179698692952776",".50":"1.17942742980884",".95":"1.33149478308123"},{"OUT/IN":"OUT","H":"92",".05":"1.87369221687026",".50":"0.911808513166002",".95":"0.679479312380241"},{"OUT/IN":"OUT","H":"96",".05":"1.29281842340926",".50":"0.478108362066701",".95":"0.349812142777789"},{"OUT/IN":"OUT","H":"100",".05":"0",".50":"0",".95":"0"},{"OUT/IN":"OUT","H":"104",".05":"1.21045719292841",".50":"0.372936759294533",".95":"0.246836536444773"},{"OUT/IN":"OUT","H":"108",".05":"1.81032626543259",".50":"0.723031419192591",".95":"0.487251085855231"}]}

This SELECT statement reproduces the table for asset-or-nothing where Call/Put = Both from the Binary Options paper by Mark Rubenstein and Eric Reiner, July 31, 1991.

SELECT *
FROM
(
    SELECT 'OUT' as [OUT/IN],
           n.T,
           n2.H,
           wct.BinaryBarrierOnly(   CASE
                                        WHEN n2.H <= 100 THEN
                                            'DO'
                                        ELSE
                                            'UO'
                                    END,
                                    'False',
                                    100,
                                    100,
                                    n2.H,
                                    n2.H,
                                    n.T,
                                    .10,
                                    .05,
                                    .20,
                                    'P'
                                ) as Price
    FROM
    (
        VALUES
            (.05),
            (.50),
            (.95)
    ) n (T)
        CROSS APPLY
    (
        VALUES
            (92),
            (96),
            (100),
            (104),
            (108)
    ) n2 (H)
    UNION ALL
    SELECT 'IN',
           n.T,
           n2.H,
           wct.BinaryBarrierOnly(   CASE
                                        WHEN n2.H <= 100 THEN
                                            'DI'
                                        ELSE
                                            'UI'
                                    END,
                                    'False',
                                    100,
                                    100,
                                    n2.H,
                                    n2.H,
                                    n.T,
                                    .10,
                                    .05,
                                    .20,
                                    'P'
                                ) as Price
    FROM
    (
        VALUES
            (.05),
            (.50),
            (.95)
    ) n (T)
        CROSS APPLY
    (
        VALUES
            (92),
            (96),
            (100),
            (104),
            (108)
    ) n2 (H)
) D
PIVOT
(
    SUM(Price)
    for T in ([.05], [.50], [.95])
) as P
ORDER BY 1;

Here are the results of this query.

{"columns":[{"field":"OUT/IN"},{"field":"H","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":".05","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":".50","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":".95","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"OUT/IN":"IN","H":"92",".05":"5.35497683346729",".50":"46.301375928576",".95":"54.2277320498817"},{"OUT/IN":"IN","H":"96",".05":"33.5081492503015",".50":"69.7470933571464",".95":"73.4112441588757"},{"OUT/IN":"IN","H":"100",".05":"99.750312239746",".50":"97.5309912028333",".95":"95.3610473132626"},{"OUT/IN":"IN","H":"104",".05":"40.5899819235456",".50":"81.1526499591973",".95":"85.1258322342053"},{"OUT/IN":"IN","H":"108",".05":"9.71097774327964",".50":"64.7464288427614",".95":"74.4634839727713"},{"OUT/IN":"OUT","H":"92",".05":"94.3953354062787",".50":"51.2296152742572",".95":"41.1333152633809"},{"OUT/IN":"OUT","H":"96",".05":"66.2421629894445",".50":"27.7838978456869",".95":"21.9498031543869"},{"OUT/IN":"OUT","H":"100",".05":"0",".50":"0",".95":"0"},{"OUT/IN":"OUT","H":"104",".05":"59.1603303162004",".50":"16.3783412436359",".95":"10.2352150790573"},{"OUT/IN":"OUT","H":"108",".05":"90.0393344964664",".50":"32.7845623600719",".95":"20.8975633404914"}]}