createPricingEngine

Syntax

createPricingEngine(name, instrument, [handler], [engineConfig])

Details

Creates a pricing engine that supports both DolphinDB's built-in functions and user-defined functions or expressions for valuation and pricing.

Parameters

name is a STRING scalar indicating the name of the engine. It is the only identifier of an engine on a data or compute node. It can contain letters, digits and "_" and must start with a letter.

instrument is an INSTRUMENT scalar/vector, indicating the instrument(s) to be priced. During pricing, market data is matched according to the rules defined by instrumentPricer.

handler (optional) is a user-defined function to handle the results of pricing.

  • If outputTime = true is set in engineConfig, the function signature is:

    def(eventTime, name, date, npv)

  • If outputTime = false (default value) is set in engineConfig, the function signature is:

    def(name, date, npv)

Parameter descriptions:

  • eventTime: NANOTIMESTAMP, the event time. Passed only if outputTime=true is set in engineConfig.
  • name: STRING, the instrument ID of the pricing target.
  • date: DATE, the pricing date.
  • npv: DOUBLE,the net present value.
  • engineConfig (optional) is a dictionary specifying engine runtime configuration. Supported key-value pairs include:
    • numThreads (optional): is an INT scalar indicating the number of worker threads. Default is 8.
    • maxQueueDepth (optional): is an INT scalar indicating the maximum queue depth. Default is 10,000,000.
    • useSystemTime (optional): is a Boolean value indicating whether to use system time as the event time. Default is true.
    • timeColumn (optional) is a STRING scalar to specify a NANOTIMESTAMP column as the event time. When specified, input data must contain this column. To specify timeColumn, useSystemTime must be set to false.
    • outputTime (optional) is a Boolean value indicating whether to output the event time. Default is false.

Returns

A handle of the created pricing engine.

Examples

This example defines 240025.IB as the pricing instrument. Based on the default matching rules in instrumentPricer, the instrument is associated with the market data CNY_TREASURY_BOND, which is subsequently added to the pricing engine using appendMktData.

try{dropStreamEngine("PRICING_ENGINE")}catch(ex){}

bondDict  = {
    "productType": "Cash",
    "assetType": "Bond",
    "bondType": "FixedRateBond",
    "instrumentId": "240025.IB",
    "start": 2024.12.25,
    "maturity": 2031.12.25,
    "issuePrice": 100.0,
    "coupon": 0.0149,
    "frequency": "Annual",
    "dayCountConvention": "ActualActualISDA"
}
instrument = parseInstrument(bondDict)

pricingDate = 2025.08.18

curveDict = {
    "mktDataType": "Curve",
    "curveType": "IrYieldCurve",
    "referenceDate": pricingDate,
    "currency": "CNY",
    "curveName": "CNY_TREASURY_BOND",
    "dayCountConvention": "ActualActualISDA",
    "compounding": "Compounded",
    "interpMethod": "Linear",
    "extrapMethod": "Flat",
    "frequency": "Annual",
    "dates": [
        2025.09.18, 2025.11.18, 2026.02.18, 2026.08.18, 2027.08.18,
        2028.08.18, 2030.08.18, 2032.08.18, 2035.08.18, 2040.08.18,
        2045.08.18, 2055.08.18, 2065.08.18, 2075.08.18
    ],
    "values": [
        1.3000, 1.3700, 1.3898, 1.3865, 1.4299,
        1.4471, 1.6401, 1.7654, 1.7966, 1.9930,
        2.1834, 2.1397, 2.1987, 2.2225
    ] \ 100.0
}

discountCurve = parseMktData(curveDict)

share streamTable(1:0, `name`date`price, [STRING, DATE, DOUBLE]) as st

def myHandler(name, date, price) {
    tableInsert(st, name, date, price)
}

engine = createPricingEngine("PRICING_ENGINE", [instrument], myHandler)

appendMktData(engine, discountCurve)

select * from st
name date price
240025.IB 2025.08.18 99.60

Related functions: appendMktData