eqDigitalOptionPricer

First introduced in version: 3.00.6

Syntax

eqDigitalOptionPricer(instrument, pricingDate, spot, discountCurve, dividendCurve, volSurf, [setting], [model], [method])

Details

Prices an equity digital option.

Currently, model only supports "BlackScholes" and method only supports "Analytic".

Parameters

instrument: An INSTRUMENT scalar or vector indicating the equity digital option to be priced. See Instrument Field Description for field requirements.

pricingDate: A DATE scalar or vector specifying the pricing date.

spot: A numeric scalar or vector specifying the spot price.

discountCurve: A MKTDATA scalar or vector of type IrYieldCurve indicating the discount curve. This curve can be constructed with parseMktData.

dividendCurve: A MKTDATA scalar or vector of type DividendCurve indicating the dividend curve. This curve can be constructed with eqDividendCurveBuilder.

volSurf: A MKTDATA scalar or vector of type VolatilitySurface indicating the equity option volatility surface. This surface can be constructed with eqVolatilitySurfaceBuilder.

setting (optional): A Dictionary<STRING, BOOL> used to specify whether to calculate option price sensitivity measures represented by Greeks. The optional keys are:

Key Value Description
calcDelta Boolean value, default false Whether to calculate Delta, i.e., the sensitivity of the option price to the underlying asset price.
calcGamma Boolean value, default false Whether to calculate Gamma, i.e., the sensitivity of the option Delta to the underlying asset price.
calcVega Boolean value, default false Whether to calculate Vega, i.e., the sensitivity of the option price to the underlying asset volatility.
calcTheta Boolean value, default false Whether to calculate Theta, i.e., the sensitivity of the option price to the passage of time.
calcRho Boolean value, default false Whether to calculate Rho, i.e., the sensitivity of the option price to interest rate changes.

model (optional): A STRING scalar indicating the model to use. It can take the following value:

  • BlackScholes: Uses the Black-Scholes formula.

method (optional): A STRING scalar indicating the method to use. It can take the following value:

  • Analytic: Uses the analytic method.

Returns

  • If setting is not specified, returns a DOUBLE scalar indicating the option's net present value (NPV), i.e., the theoretical option price.
  • If setting is specified, returns a dictionary (Dictionary<STRING, DOUBLE>) containing NPV and the Greeks requested by setting.

Examples

The following example builds a discount curve, a dividend curve, and an equity option volatility surface, and then prices an equity digital option.

eqDigitalOptionJson =  {
    "productType": "Option",
    "optionType": "DigitalOption",
    "assetType":"EqDigitalOption",
    "instrumentId":"111222334",
    "notionalCurrency":"CNY",
    "notionalAmount":1,
    "maturity":2026.03.25,
    "strike":3.2000,
    "dayCountConvention":"Actual360",
    "underlying":"CCC",
    "payoffType":"Call",
    "direction":"Buy",
    "discountCurve":"discountCurve",
    "dividendCurve":"dividendCurve"
}

ins3 = parseInstrument(eqDigitalOptionJson)

// ================================================================
// Data sources:
//   Spot price    : akshare fund_etf_hist_sina('sh510050')     -> 3.1140
//   Option chain/IV: akshare option_risk_indicator_sse('20260213')
//                    -> reconstructs the option settlement price with Black-Scholes
//   Interest rate curve: China Foreign Exchange Trade System implied foreign currency
//                    interest rate curve (CNY, USD.CNY/Shibor/swap points)
//                    https://www.chinamoney.com.cn/chinese/bkcurvuiruuh/
//                    API: POST /ags/ms/cm-u-bk-fx/IuirCurvHis  2026-02-13
//
// Pricing target: Call option, strike=3.2000, expiry=2026-03-25
// ================================================================

pricingDate   = 2026.02.13
referenceDate = pricingDate

// ------------------------------------------------------------------
// 1. Spot price
// ------------------------------------------------------------------
spot = 3.1140

// ------------------------------------------------------------------
// 2. Define the pricing contract (near-month ATM/slightly OTM call option)
// ------------------------------------------------------------------

// ------------------------------------------------------------------
// 3. Raw option chain data (used to construct the dividend curve and volatility surface)
//    Expiry sequence: 2026.02.25 | 2026.03.25 | 2026.06.24 | 2026.09.23
//    Strike range: [2.85, 3.60]
// ------------------------------------------------------------------
termDates = [2026.02.25, 2026.03.25, 2026.06.24, 2026.09.23]

callPrices = matrix(
    [0.2655, 0.2155, 0.1656, 0.1156, 0.0318, 0.0039, 0.0015, 0.0008, 0.0003, 0.0001],
    [0.2690, 0.2248, 0.1770, 0.1385, 0.0697, 0.0303, 0.0128, 0.0069, 0.0046, 0.0036],
    [0.3030, 0.2655, 0.2278, 0.1970, 0.1431, 0.0991, 0.0677, 0.0479, 0.0346, 0.0254],
    [0.3330, 0.2987, 0.2681, 0.2388, 0.1883, 0.1448, 0.1139, 0.0899, 0.0715, 0.0574]
)
putPrices = matrix(
    [0.0004, 0.0009, 0.0021, 0.0045, 0.0218, 0.0939, 0.1901, 0.2896, 0.3908, 0.4916],
    [0.0125, 0.0165, 0.0229, 0.0316, 0.0616, 0.1250, 0.2029, 0.2967, 0.3962, 0.4948],
    [0.0396, 0.0507, 0.0634, 0.0798, 0.1253, 0.1814, 0.2499, 0.3321, 0.4175, 0.5077],
    [0.0651, 0.0798, 0.0973, 0.1180, 0.1662, 0.2250, 0.2952, 0.3651, 0.4508, 0.5342]
)
strikes = matrix(
    [2.8500, 2.9000, 2.9500, 3.0000, 3.1000, 3.2000, 3.3000, 3.4000, 3.5000, 3.6000],
    [2.8500, 2.9000, 2.9500, 3.0000, 3.1000, 3.2000, 3.3000, 3.4000, 3.5000, 3.6000],
    [2.8500, 2.9000, 2.9500, 3.0000, 3.1000, 3.2000, 3.3000, 3.4000, 3.5000, 3.6000],
    [2.8500, 2.9000, 2.9500, 3.0000, 3.1000, 3.2000, 3.3000, 3.4000, 3.5000, 3.6000]
)

// ------------------------------------------------------------------
// 4. Discount curve -- CNY rates from China Foreign Exchange Trade System
//    implied foreign currency interest rate curve (2026-02-13)
//    Data source: https://www.chinamoney.com.cn/chinese/bkcurvuiruuh/
//    USD.CNY / Shibor / average spot inquiry quote / swap points -> rmbRateStr field
// ------------------------------------------------------------------
discountCurveDict = {
    "mktDataType"       : "Curve",
    "curveType"         : "IrYieldCurve",
    "curveName"         : "CNY_FR_007",
    "referenceDate"     : referenceDate,
    "currency"          : "CNY",
    "dayCountConvention": "Actual365",
    "compounding"       : "Continuous",
    "interpMethod"      : "Linear",
    "extrapMethod"      : "Flat",
    "dates"             : [referenceDate + 1, referenceDate + 7, referenceDate + 14, referenceDate + 21, referenceDate + 30, referenceDate + 61, referenceDate + 91, referenceDate + 182, referenceDate + 273, referenceDate + 365, referenceDate + 547, referenceDate + 730, referenceDate + 1095],
    "values"            : [0.016134, 0.016107, 0.016102, 0.016102, 0.016102, 0.016103, 0.016029, 0.015832, 0.015889, 0.015898, 0.015561, 0.015583, 0.015892]
}
discountCurve = parseMktData(discountCurveDict)

// ------------------------------------------------------------------
// 5. Dividend curve -- implied with Call-Put parity (CallPutParity)
// ------------------------------------------------------------------
dividendCurve = eqDividendCurveBuilder(
    referenceDate, termDates, "CallPutParity", ,
    callPrices, putPrices, strikes, spot, discountCurve,
    "Actual365", "510050"
)

// ------------------------------------------------------------------
// 6. Volatility surface -- SABR model, using OTM options
//    Strike < Spot -> OTM Put; Strike >= Spot -> OTM Call
// ------------------------------------------------------------------
optionExpiries = termDates

optionPrices = matrix(
    [0.0004, 0.0009, 0.0021, 0.0045, 0.0218, 0.0039, 0.0015, 0.0008, 0.0003, 0.0001],
    [0.0125, 0.0165, 0.0229, 0.0316, 0.0616, 0.0303, 0.0128, 0.0069, 0.0046, 0.0036],
    [0.0396, 0.0507, 0.0634, 0.0798, 0.1253, 0.0991, 0.0677, 0.0479, 0.0346, 0.0254],
    [0.0651, 0.0798, 0.0973, 0.1180, 0.1662, 0.1448, 0.1139, 0.0899, 0.0715, 0.0574]
)
payoffTypes = matrix(
    ["Put", "Put", "Put", "Put", "Put", "Call", "Call", "Call", "Call", "Call"],
    ["Put", "Put", "Put", "Put", "Put", "Call", "Call", "Call", "Call", "Call"],
    ["Put", "Put", "Put", "Put", "Put", "Call", "Call", "Call", "Call", "Call"],
    ["Put", "Put", "Put", "Put", "Put", "Call", "Call", "Call", "Call", "Call"]
)
volSurface = eqVolatilitySurfaceBuilder(
    referenceDate,
    optionExpiries,
    strikes,
    optionPrices,
    payoffTypes,
    spot,
    discountCurve,
    dividendCurve,
    "SABR",
    "50ETF_SABR_20260213"
)

// ------------------------------------------------------------------
// 7. Pricing -- single-contract NPV
// ------------------------------------------------------------------
npv = eqDigitalOptionPricer(ins3, pricingDate, spot, discountCurve, dividendCurve, volSurface)
print("NPV = " + string(npv))

// ------------------------------------------------------------------
// 8. Pricing -- with Greeks
// ------------------------------------------------------------------
setting = {
    "calcDelta"      : true,
    "calcGamma"      : true,
    "calcVega"       : true,
    "calcTheta"      : true,
    "calcRho"      : true
}
result = eqDigitalOptionPricer(ins3, pricingDate, spot, discountCurve, dividendCurve, volSurface, setting)
print(result)
// output:
// npv->0.279855211680205
// delta->2.043402240346535
// gamma->6.568738172923309
// vega->1.121915880314628
// theta->-0.675386277908325
// rho->0.675922151639878

Instrument Field Description

Field Name Data Type Description Required
productType STRING Must be "Option". Yes
optionType STRING Must be "DigitalOption". Yes
assetType STRING Must be "EqDigitalOption". Yes
instrumentId STRING Contract code. For OTC options, it can be customized. No
maturity DATE Maturity date. Yes
strike DOUBLE Strike price. Yes
dayCountConvention STRING Day count convention. It can be "ActualActualISDA", "ActualActualISMA", "Actual365", or "Actual360". Yes
direction STRING Buy/sell direction. It can be "Buy" or "Sell". The default value is "Buy". No
payoffType STRING Payoff type. It can be "Call" or "Put". Yes
underlying STRING Underlying code, for example "510050". Yes
notionalAmount DOUBLE Notional amount. Yes
notionalCurrency STRING Notional currency. The default value is "CNY". No
discountCurve STRING Name of the discount curve used for pricing. The default value is an empty string. No
dividendCurve STRING Name of the dividend curve used for pricing. The default value is an empty string. No

Related Functions: parseInstrument, parseMktData, eqDividendCurveBuilder, eqVolatilitySurfaceBuilder