Logo

SQL Server StandardBarrierPriceNGreeks Function

Updated 2023-11-14 21:24:46.300000

Description

Use the table-valued function StandardBarrierPriceNGreeks to calculate the price and Greeks of a European-style Knock-In or Knock-Out option. StandardBarrierPriceNGreeks valuations are based on the formulae published by Mark Rubinstein and Eric Reiner in 1991.

Syntax

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

Arguments

@CallPut

identifies the option as being a call ('C') or a put ('P'). @CallPut is an expression of type nvarchar or of a type that can be implicitly converted to nvarchar.

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

@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.v
PhiRho2floatThe sensitivity to a change in the dividend yield (foreign interest rate for a currency option); the first derivative with respect to dividend yield.
RhoFuturesOptionfloatThe sensitivity to a change in the cost-of carry; the first derivative with respect to the cost-of-carry.
CarrySensitivityfloat-PhiRho2
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.
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.

To calculate a single return value use StandardBarrier.

Examples

A down-and-in call.

SELECT *
FROM wct.StandardBarrierPriceNGreeks(   'C',  --PutCall
                                        'DI', --BarrierType
                                        100,  --Asset Price
                                        90,   --Strike Price
                                        97,   --Barrier
                                        2,    --Rebate
                                        0.5,  --Time-to-expiry
                                        .10,  --Risk Free Rate
                                        .05,  --Dividend Rate
                                        .20   --Volatility
                                    );

Here is the resultant table.

PriceDeltaGammaThetaVegaRhoLambdaGammaPDdeltaDtimeDdeltaDvolDdeltaDvolDvolDgammaDvolDvegaDvolVegaPPhiRho2RhoFuturesOptionCarrySensitivityDgammaDspotDeltaXRiskNeutralDensityDvommaDvolDgammaDtimeDvegaDtimeForwardPriceForwardPoints
8.59507043337689-0.649025842971440.0520920195867802-0.01731533785802770.2586659044428790.156984606560862-7.551140482236240.05209201958678020.0003060857503529310.0135552475910572-0.650285444001763-0.00416152947657622-0.001996875340637420.517331808885757-0.199959958364104-0.03796268188320790.19995995836410412980.5178819353-0.5827838341687650.02075566385428830.000564868690818621-5.0437133921443E-05-0.0699760441980818102.5315120524432.53151205244289

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

SELECT *
FROM wct.StandardBarrierPriceNGreeks(   'C',  --PutCall
                                        'DI', --BarrierType
                                        100,  --Asset Price
                                        90,   --Strike Price
                                        97,   --Barrier
                                        2,    --Rebate
                                        0.5,  --Time-to-expiry
                                        .10,  --Risk Free Rate
                                        .05,  --Dividend Rate
                                        .20   --Volatility
                                    );

This produces the following result.

Return ValueValue
Price8.59507043337689
Delta-0.649025843078022
Gamma0.052092730129516
Theta-0.0173153378580135
Vega0.258665904443234
Rho0.156984606562283
Lambda-7.55114048347627
GammaP0.052092730129516
DdeltaDtime0.000306086723699144
DdeltaDvol0.0135552546964846
DdeltaDvolDvol-0.650285444002208
DgammaDvol-0.00416152983184759
DvegaDvol-0.00199687541169169
VegaP0.517331808886468
PhiRho2-0.199959958365525
RhoFuturesOption-0.0379626818828527
CarrySenstivity0.199959958365525
DgammaDspot12980.5178819264
DeltaX-0.582783834275347
RiskNeutralDensity0.0207577954824956
DvommaDvol0.000564868690799969
DgammaDtime-5.04370755206702E-05
DvegaDtime-0.0699760427380625
ForwardPrice102.531512052443
ForwardPoints2.5315120524428

Use CROSS APPLY to with StandardBarrierPriceNGreeks when there are multiple rows of input data.

SELECT n.rn,
       k.*
FROM
(
    VALUES
        (1, 'C', 'DI', 100, 97, 95, 2, 0.75, 0.005, 0.009, 0.16),
        (2, 'P', 'DI', 100, 97, 95, 2, 0.75, 0.005, 0.009, 0.16),
        (3, 'C', 'DO', 100, 97, 95, 2, 0.75, 0.005, 0.009, 0.16),
        (4, 'P', 'DO', 100, 97, 95, 2, 0.75, 0.005, 0.009, 0.16),
        (5, 'C', 'UI', 100, 103, 105, 2, 0.75, 0.005, 0.009, 0.16),
        (6, 'P', 'UI', 100, 103, 105, 2, 0.75, 0.005, 0.009, 0.16),
        (7, 'C', 'UO', 100, 103, 105, 2, 0.75, 0.005, 0.009, 0.16),
        (8, 'P', 'UO', 100, 103, 105, 2, 0.75, 0.005, 0.009, 0.16)
) n (rn, z, bt, S, X, H, K, T, Rf, Rd, Vol)
    CROSS APPLY wct.StandardBarrierPriceNGreeks(z, bt, S, X, H, K, T, Rf, Rd, Vol)
              k;

This produces the following result.

rnPriceDeltaGammaThetaVegaRhoLambdaGammaPDdeltaDtimeDdeltaDvolDdeltaDvolDvolDgammaDvolDvegaDvolVegaPPhiRho2RhoFuturesOptionCarrySensitivityDgammaDspotDeltaXRiskNeutralDensityDvommaDvolDgammaDtimeDvegaDtimeForwardPriceForwardPoints
13.07846160020878-0.1702522167823520.0202527772330541-0.007250148460873350.2571238071044760.131041056567249-5.530431718583250.02025277723305410.0004207724883893-0.0156441741783198-0.168478019411356-0.0005110055045776110.009068890873820120.411398091367161-0.154129518875523-0.02355196701544490.1541295188755233405.04485359228-0.2881962860357130.0262375010606775-0.00155662427154724-2.04810244867238E-05-0.072006934205236499.7004495503373-0.299550449662704
24.69882019877999-0.2909484058966070.024994850633675-0.009024686287052220.29749582967713-0.301615915811126-6.191945926599820.0249948506336750.00029094023993634-0.00902774055511202-0.289777346090059-0.001201645343229530.004557270214533560.4759933274834080.266374758334065-0.0344503488128201-0.2663747583340655818.968542596890.4438907538073520.0262382116034132-0.000808031412470544-3.40977888238161E-05-0.068007049672057299.7004495503373-0.299550449662704
35.781118319235480.7711070896387890.00739355243695172-0.001674482385441320.07415777161132730.26171370862040413.33837238848910.00739355243695172-0.0002843111438819070.01258031057105310.769920148577308-0.00116530134430803-0.008370770521182180.118652434578124-0.296816283578538-0.03606663055575330.296816283578538-15422.1420392329-0.2610170539085740.003088729272349160.00139862286618442-2.82449363745456E-050.0095143809421557199.7004495503373-0.299550449662704
41.470417892317-0.101469451376790.00265560906598239-0.001025337745561350.0337857490390059-0.0304063035266422-6.900722026505030.00265560906598239-0.0001789703088924360.0059638752269997-0.10205325482262-0.000474661339122662-0.003859149653173690.05405719846240940.0276339874691334-0.0027524657316258-0.02763398746913342029.388873355130.003152928798044740.003089439815084920.000650030007124158-1.46281924168897E-050.0055144964698106999.7004495503373-0.299550449662704
54.680207663188670.3178148995530710.0252326159966287-0.008443452525380480.3056525383459350.2600449764433856.790615340699230.0252326159966287-0.0003362158040560760.01304614860586640.316574940590675-0.001145544228364770.004923306526904980.489044061353496-0.29514654013485-0.03599825611826370.29514654013485-6356.29817608052-0.3765896979857080.024112267738019-0.000890483003651354-3.57423253855396E-05-0.068571739032777799.7004495503373-0.299550449662704
63.450024507992510.2268398766247510.0245946374377581-0.008332760609516040.279283409440989-0.172679909786916.57502218025530.0245946374377581-0.0005629899286489410.01808245941870010.225052094862588-0.0008477177959598240.008218147486971360.4468534551055830.146804725574201-0.0254347515963316-0.146804725574201-4536.797936084190.3220045773133510.0241129782807548-0.00149295086525258-1.96060555918219E-05-0.075518002931710199.7004495503373-0.299550449662704
71.40280312414560.1140083339767890.00303013170110944-0.0009207015893575310.03300051159840220.02585849877170258.127179930984860.003030131701109440.000158998385234177-0.00562849078455940.114551817901221-0.000539626171525143-0.003871853566650430.0528008185574436-0.028392135172095-0.002555071169285660.028392135172095-2280.16651359209-0.002453055927276180.002475530891388190.000666395939629472-1.42102856118379E-050.0048628952767169999.7004495503373-0.299550449662704
85.92018658580952-0.7882893732213960.00366808805551955-0.002074901991868220.0593696405037036-0.311025165576506-13.31527920270110.003668088055519550.000361280624898981-0.0106647981557018-0.78719806644969-0.000837452716062614-0.007166694597771080.09499142480592580.274611147376769-0.0355343587172818-0.27461114737676915765.78784799750.2952096912522960.002473399263180910.00126886380122704-3.03465538847021E-050.011809159130023899.7004495503373-0.299550449662704