createPricingEngine
Syntax
createPricingEngine(name, dummyTable, timeColumn, typeColumn, securityType,
method, outputTable, [securityReference], [keyColumn],
[extraMetrics])
Details
Create a pricing engine that supports both DolphinDB's built-in functions and user-defined functions or expressions for valuation and pricing. It is applicable to various business scenarios, asset types, and data frequencies, contributing to market analysis, investment decisions, and risk management.
Arguments
name is a STRING scalar indicating the engine name, which is the unique identifier of the pricing engine on a data node. It must begin with a letter and may contain letters, numbers and underscores.
dummyTable is a table object indicating the schema of the input table.
timeColumn is a STRING vector indicating the time column in the input.
typeColumn is a STRING vector indicating the security type column in the input. Based on security type, the engine applies the corresponding pricing method.
securityType is a vector of integers indicating the types of securities.
method is a tuple of metacode indicating the algorithms and parameters for security pricing, which corresponds to each element in securityType. Note that:
-
User-defined functions or expressions are supported.
-
The parameters of method can be columns from dummyTable, securityReference, or constants. In case of name conflicts, columns from dummyTable are prioritized by default. To search columns from securityReference first, use column references such as
securityReference.X
. -
The kwargs parameter of the vanillaOption method can be specified as follows:
- Define kwargs before specifying the
method:
kwargs = dict(STRING, ANY) kwargs['theta'] = <theta> kwargs['kappa'] = <kappa> kwargs['rho'] = <rho> kwargs['sigma'] = <sigma> method=[<vanillaOption(settlement, maturity, valDay, spot, strike, riskFree, dividend, volatility, isCall, style, basis, calendar,"heston",kwargs)>]
- Define kwargs within the
method:
method=[<vanillaOption(settlement, maturity, valDay, spot, strike, riskFree, dividend, volatility, isCall, style, basis, calendar,"heston",dict(`theta`kappa`rho`sigma, [theta, kappa, rho, sigma]))>]
- Define kwargs before specifying the
method:
outputTable is a table object indicating the schema of the output table, which contains the following columns in order:
- Time column: matches timeColumn.
- Security type: matches typeColumn.
- Security symbol: matches keyColumn.
- Pricing result: a DOUBLE array vector with the number of output values matching the number of algorithms specified in methodList.
- Additional output: matches the metrics specified by extraMetrics.
securityReference (optional) is an in-memory table indicating the basic information on each security. Leave empty if no information is available. The information on different securities must be combined into a table. The table contains the following fields:
Field | Type | Description |
---|---|---|
type | INT | Security type (scalar/vector) |
assetType | INT | Asset type |
symbol | SYMBOL | Security symbol |
maturity | DOUBLE | Maturity date |
coupon | DOUBLE | Coupon rate |
frequency | INT | Coupon frequency |
underlying | SYMBOL | Reference interest rate including "FR007", "Shibor3M", "FDR001", "FDR007", "ShiborO/N", "LPR1Y", "LPR5Y". |
startDate | DATE | Start date of interest rate swap |
endDate | DATE | End date of interest rate swap. Must be later than startDay. |
fixRate | DOUBLE | Fixed interest rate (percentage) paid by the fixed rate payer in a swap contract. |
interval | INT | Interval of of interest rate swap |
basis | INT | Day count basis |
Price | DOUBLE | Current price of the security |
strike | DOUBLE | Strike price of the security |
dividendYield | DOUBLE | Dividend yield rate |
keyColumn (optional) is a STRING scalar or tuple of length 2, indicating the security symbol column in dummyTable and securityReference. Note that securityReference and keyColumn must be both set or unset.
extraMetrics (optional) is a tuple of metacode indicating the additional output beyond pricing results, including columns from the input and securityReference. Constants are not allowed.
Examples
// Specify input/output table schema and security info
dummyTable = table(1:0, `tradeTime`Symbol`realTimeX`predictY`price,[TIMESTAMP,SYMBOL, DOUBLE, DOUBLE, DOUBLE])
securityReference= table(take(0 1 2, 100) as type, take(1 2 3 4, 100) as assetType,"s"+string(1..100) as symbol, 2025.07.25+1..100 as maturity, rand(10.0, 100) as coupon, rand(10,100) as frequency,take([1],100) as basis )
outputTable = table(1:0, `tradeTime`type`symbol`result`factor1`factor2,[TIMESTAMP, INT, SYMBOL, DOUBLE, DOUBLE, DOUBLE])
// Specify the type, purchase date, and face value of the securities to be priced
typeList=[0,1,2]
date=2024.07.25
par=100
// Specify the algorithms and parameters for security pricing
methodList=[<bondDirtyPrice(date, maturity, coupon, predictY, frequency,basis)>,
<bondAccrInt(date, maturity, coupon, frequency,par,basis)>,
<bondDuration(date, maturity, coupon, predictY, frequency, basis)>]
// Create a pricing engine
createPricingEngine(name="engine1", dummyTable=dummyTable, timeColumn=`tradeTime, typeColumn=`type, securityType=typeList, method=methodList, outputTable=outputTable, securityReference=securityReference, keyColumn=`Symbol, extraMetrics=[<price * predictY>, <coupon+price>])
Use getStreamEngine
to get the handle of the pricing engine and
input data in the required format.
data = table(take(now(), 100)as tradeTime,"s"+string(1..100) as symbol, rand(10.0, 100) as realTimeX, rand(10.0, 100) as predictY, rand(10.0, 100) as price)
getStreamEngine(`engine1).append!(data)
Related functions: