parseInstrument
Syntax
parseInstrument(obj)
Parameters
obj is a dictionary, a tuple of dictionaries, an in-memory table, or a STRING scalar/vector, indicating the financial instrument description to be parsed.
Note: If obj is specified as a table, it must store instruments of a single type.
Details
Parse the instrument description obj into an INSTRUMENT object for modeling and pricing. See Supported Instruments and Fields for details.
Note: parseInstrument preserves non-standard scalar or vector fields
(i.e., fields not defined as attributes of the financial instrument) during
serialization or deserialization.
Return value: An INSTRUMENT object.
Examples
Store the description of a coupon bond in a dictionary and use
parseInstrument to parse it into an INSTRUMENT object.
bond = {
"productType": "Cash",
"assetType": "Bond",
"bondType": "FixedRateBond",
"instrumentId": "230205.IB",
"start": "2023.03.06",
"maturity": "2033.03.06",
"issuePrice": 100.0,
"coupon": 0.0302,
"calendar": "CFET",
"frequency": "Annual",
"dayCountConvention": "ActualActualISDA",
"subType": "CDB_BOND",
"issuer": "CDB"
}
parseInstrument(bond)
Parse a tuple of dictionaries and obtain INSTRUMENT objects for three bonds.
bond1 = {
"productType": "Cash",
"assetType": "Bond",
"bondType": "DiscountBond",
"instrumentId": "259924.IB",
"start": 2025.04.17,
"maturity": 2025.07.17,
"issuePrice": 99.664,
"dayCountConvention": "ActualActualISDA",
"subType": "TREASURY_BOND",
"issuer": "MOF"
}
bond2 = {
"productType": "Cash",
"assetType": "Bond",
"bondType": "ZeroCouponBond",
"instrumentId": "250401.IB",
"start": 2025.01.09,
"maturity": 2026.02.05,
"coupon": 0.0119,
"dayCountConvention": "ActualActualISDA",
"subType": "CDB_BOND",
"issuer": "ADBC"
}
parseInstrument([bond,bond1,bond2])
Store instrument descriptions in a table, with each column representing a field. Use
parseInstrument to parse it and obtain an INSTRUMENT
object.
Note: If a product is missing a field required by the table columns, set that field to NULL when inserting the product into the table.
create table t (
productType STRING,
assetType STRING,
bondType STRING,
version INT,
instrumentId STRING,
start DATE,
maturity DATE,
issuePrice DOUBLE,
coupon DOUBLE,
calendar STRING,
frequency STRING,
dayCountConvention STRING,
subType STRING,
issuer STRING
)
go
insert into t values( "Cash", "Bond", "FixedRateBond", 0, "230205.IB", 2023.03.06, 2033.03.06, 100.0, 0.0302, "CFET", "Annual", "ActualActualISDA", "CDB_BOND", "CDB")
insert into t values( "Cash", "Bond", "DiscountBond", 0, "259924.IB", 2025.04.17, 2025.07.17, 99.664, NULL, NULL, NULL, "ActualActualISDA", "TREASURY_BOND", "MOF")
insert into t values( "Cash", "Bond", "ZeroCouponBond", 0, "250401.IB", 2025.01.09, 2026.02.05, NULL, 0.0119, NULL, NULL, "ActualActualISDA", "CDB_BOND", "ADBC")
parseInstrument(t)
When obj is a STRING scalar:
bond1Str = '{"productType": "Cash","assetType": "Bond","bondType": "FixedRateBond","coupon": 0.0302,"frequency": "Annual","version": 0,"instrumentId": "230205.IB","nominal": 100,"start": "2023.03.06","maturity": "2033.03.06","dayCountConvention": "ActualActualISDA","calendar": "CFET","currency": "CNY","cashflow": [{"paymentDate": "2024.03.06","coupon": 3.026804551238871,"notional": 0,"total": 3.026804551238871},{"paymentDate": "2025.03.06","coupon": 3.01319544876113,"notional": 0,"total": 3.01319544876113},{"paymentDate": "2026.03.06","coupon": 3.02,"notional": 0,"total": 3.02},{"paymentDate": "2027.03.06","coupon": 3.02,"notional": 0,"total": 3.02},{"paymentDate": "2028.03.06","coupon": 3.026804551238871,"notional": 0,"total": 3.026804551238871},{"paymentDate": "2029.03.06","coupon": 3.01319544876113,"notional": 0,"total": 3.01319544876113},{"paymentDate": "2030.03.06","coupon": 3.02,"notional": 0,"total": 3.02},{"paymentDate": "2031.03.06","coupon": 3.02,"notional": 0,"total": 3.02},{"paymentDate": "2032.03.06","coupon": 3.026804551238871,"notional": 0,"total": 3.026804551238871},{"paymentDate": "2033.03.06","coupon": 3.01319544876113,"notional": 100,"total": 103.013195448761123}],"discountCurve": "","spreadCurve": "","subType": "CDB_BOND","issuePrice": 100,"issuer": "CDB"}'
parseInstrument(bond1Str)
When obj is a STRING vector, parse it and obtain multiple INSTRUMENT objects:
bond2Str = '{"productType": "Cash","assetType": "Bond","bondType": "DiscountBond","issuePrice": 99.664000000000001,"version": 0,"instrumentId": "259924.IB","nominal": 100,"start": "2025.04.17","maturity": "2025.07.17","dayCountConvention": "ActualActualISDA","calendar": "","currency": "CNY","cashflow": [{"paymentDate": "2025.07.17","coupon": 0,"notional": 100,"total": 100}],"discountCurve": "","spreadCurve": "","subType": "TREASURY_BOND","issuer": "MOF"}'
bond3Str = '{"productType": "Cash","assetType": "Bond","bondType": "ZeroCouponBond","coupon": 0.0119,"version": 0,"instrumentId": "250401.IB","nominal": 100,"start": "2025.01.09","maturity": "2026.02.05","dayCountConvention": "ActualActualISDA","calendar": "","currency": "CNY","cashflow": [{"paymentDate": "2026.01.09","coupon": 1.190000000000002,"notional": 0,"total": 1.190000000000002},{"paymentDate": "2026.02.05","coupon": 0.088027397260282,"notional": 100,"total": 100.088027397260276}],"discountCurve": "","spreadCurve": "","subType": "CDB_BOND","issuer": "CDB"}'
parseInstrument([bond1Str,bond2Str,bond3Str])
Supported Instruments and Fields
The INSTRUMENT type is newly introduced in DolphinDB version 3.00.4, designed to store financial instruments and provide a foundation for pricing and risk measurement of financial products.
The parseInstrument function generates corresponding instrument
objects based on the fields of the instrument description. Currently, only
instrument types illustrated as leaf nodes in the classification tree below are
supported:
Discount Bond (DiscountBond)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Must be "Cash" | √ |
| assetType | STRING | Must be "Bond" | √ |
| bondType | STRING | Must be "DiscountBond" | √ |
| nominal | DOUBLE | Nominal amount, defalut 100 | × |
| instrumentId | STRING | Bond code, e.g., "259926.IB" | × |
| start | DATE | Value date | √ |
| maturity | DATE | Maturity date | √ |
| dayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
| issuePrice | DOUBLE | Issue price | √ |
| currency | STRING | Currency, defaults to "CNY" | × |
| cashFlow | TABLE | Cash flow table | × |
| discountCurve | STRING | The discount curve, e.g., "CNY_TRASURY_BOND" | × |
| spreadCurve | STRING | The credit spread curve | × |
| subType | STRING |
Subtypes. China's bonds include:
|
× |
| creditRating | STRING | Credit rating. It can be: "B", "BB", "BBB", "BBB+", "A-", "A", "A+", "AA-", "AA", "AA+", "AAA-", "AAA", "AAA+" | × |
Define an INSTRUMENT object of DiscountBond type.
bond = {
"productType": "Cash",
"assetType": "Bond",
"bondType": "DiscountBond",
"instrumentId": "259924.IB",
"start": 2025.04.17,
"maturity": 2025.07.17,
"issuePrice": 99.664,
"dayCountConvention": "ActualActualISDA"
}
instrument = parseInstrument(bond)
print(instrument)
Zero Coupon Bond (ZeroCouponBond)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Must be "Cash" | √ |
| assetType | STRING | Must be "Bond" | √ |
| bondType | STRING | Must be "ZeroCouponBond" | √ |
| nominal | DOUBLE | Nominal amount, defalut 100 | × |
| instrumentId | STRING | Bond code, e.g., "259926.IB" | × |
| start | DATE | Value date | √ |
| maturity | DATE | Maturity date | √ |
| coupon | DOUBLE | Coupon rate, e.g., 0.03 means 3% | √ |
| frequency | STRING | Frequency of interest payment | × |
| dayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
| currency | STRING | Currency, defaults to "CNY" | × |
| cashFlow | TABLE | Cash flow table | × |
| discountCurve | STRING | The discount curve, e.g., "CNY_TRASURY_BOND" | × |
| spreadCurve | STRING | The credit spread curve | × |
| subType | STRING |
Subtypes. China's bonds include:
|
× |
| creditRating | STRING | Credit rating. It can be: "B", "BB", "BBB", "BBB+", "A-", "A", "A+", "AA-", "AA", "AA+", "AAA-", "AAA", "AAA+" | × |
Define an INSTRUMENT object of ZeroCouponBond type.
dict = {
"productType": "Cash",
"assetType": "Bond",
"bondType": "ZeroCouponBond",
"instrumentId": "250401.IB",
"start": 2025.01.09,
"maturity": 2026.02.05,
"coupon": 0.0119,
"dayCountConvention": "ActualActualISDA"
}
Fixed Rate Bond (FixedRateBond)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Must be "Cash" | √ |
| assetType | STRING | Must be "Bond" | √ |
| bondType | STRING | Must be "FixedRateBond" | √ |
| nominal | DOUBLE | Nominal amount, defalut 100 | × |
| instrumentId | STRING | Bond code, e.g., "259926.IB" | × |
| start | DATE | Value date | √ |
| maturity | DATE | Maturity date | √ |
| coupon | DOUBLE | Coupon rate, e.g., 0.03 means 3% | √ |
| frequency | STRING | Frequency of interest payment | √ |
| dayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
| currency | STRING | Currency, defaults to "CNY" | × |
| cashFlow | TABLE | Cash flow table | × |
| discountCurve | STRING | The discount curve, e.g., "CNY_TRASURY_BOND" | × |
| spreadCurve | STRING | The credit spread curve | × |
| subType | STRING |
Subtypes. China's bonds include:
|
× |
| creditRating | STRING | Credit rating. It can be: "B", "BB", "BBB", "BBB+", "A-", "A", "A+", "AA-", "AA", "AA+", "AAA-", "AAA", "AAA+" | × |
Define an INSTRUMENT object of FixedRateBond type.
bond = {
"productType": "Cash",
"assetType": "Bond",
"bondType": "FixedRateBond",
"instrumentId": "240021.IB",
"start": 2024.10.25,
"maturity": 2025.10.25,
"issuePrice": 100,
"coupon": 0.0133,
"frequency": "Annual",
"dayCountConvention": "ActualActualISDA"
}
instrument = parseInstrument(bond)
print(instrument)
Bond Futures (BondFutures)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Must be "Futures" | √ |
| futuresType | STRING | Must be "BondFutures" | √ |
| nominal | DOUBLE | Nominal amount, defalut 100 | × |
| instrumentId | STRING | Bond future code, e.g., "T2509" | × |
| maturity | DATE | Maturity date | √ |
| settlement | DATE | Settlement date | √ |
| underlying | Dictionary | Fixed-rate bond structure, indicating the underlying deliverable bonds. | √ |
| nominalCouponRate | DOUBLE | Nominal coupon rate | √ |
Define an INSTRUMENT object of BondFutures type.
bond ={
"productType": "Cash",
"assetType": "Bond",
"bondType": "FixedRateBond",
"instrumentId": "220010.IB",
"start": 2020.12.25,
"maturity": 2031.12.25,
"issuePrice": 100.0,
"coupon": 0.0149,
"frequency": "Annual",
"dayCountConvention": "ActualActualISDA"
}
futures = {
"productType": "Futures",
"futuresType": "BondFutures",
"instrumentId": "T2509", //Future code
"nominal": 100.0,
"maturity": "2022.09.09",
"settlement": "2022.09.11",
"underlying": bond,
"nominalCouponRate": 0.03 //Nominal coupon rate corresponding to the bond futures. You can get it from the China Financial Futures Exchange (CFFEX).
}
instrument = parseInstrument(futures)
print(instrument)
Deposit (Deposit)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Must be "Cash" | √ |
| assetType | STRING | Must be "Deposit" | √ |
| notionalAmount | DOUBLE | Notional principal amount | √ |
| notionalCurrency | STRING | Notional principal | √ |
| instrumentId | STRING | Deposit reference rate index, e.g., "SHIBOR_3M" | × |
| start | DATE | Value date | √ |
| maturity | DATE | Maturity date | √ |
| rate | DOUBLE | Deposit interest rate | √ |
| dayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
| payReceive | STRING | Pay/Receive indicator: "Pay" indicates paying; "Receive" indicates receiving. | √ |
| discountCurve | STRING | The domestic discount curve. The default is "CNY_FR_007" for CNY. | × |
| calendar | STRING | Trading calendar | × |
Define an INSTRUMENT object of Deposit type.
deposit = {
"productType": "Cash",
"assetType": "Deposit",
"start": 2025.05.15,
"maturity": 2025.08.15,
"rate": 0.02,
"dayCountConvention": "Actual360",
"notionalCurrency": "CNY",
"notionalAmount": 1E6,
"payReceive": "Receive"
}
instrument = parseInstrument(deposit)
print(instrument)
IR Fixed-Floating Swap (IrFixedFloatingSwap)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Must be "Swap" | √ |
| swapType | STRING | Must be "IrSwap" | √ |
| irSwapType | STRING | Must be "IrFixedFloatingSwap" | √ |
| notionalAmount | DOUBLE | Notional principal amount | √ |
| notionalCurrency | STRING | Notional principal | √ |
| instrumentId | STRING | IR fixed-floating swap name. It can be "CNY_FR_007 or "CNY_SHIBOR_3M". | × |
| start | DATE | Value date | √ |
| maturity | DATE | Maturity date | √ |
| fixedRate | DOUBLE | Fixed-rate | √ |
| calender | STRING | Trading calendar | √ |
| fixedDayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
| floatingDayCountConvetion | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
| spread | DOUBLE | Interest rate spread | √ |
| iborIndex | STRING | Floating reference rate. It can be "FR_007" or "SHIBOR_3M". | √ |
| frequency | STRING | Frequency of interest payment | √ |
| payReceive | STRING |
Pay/Receive indicator
|
√ |
| domesticCurve | STRING | The domestic discount curve name | × |
| foreignCurve | STRING | The foreign discount curve name | × |
Define an INSTRUMENT object of IrFixedFloatingSwap type.
swap = {
"productType": "Swap",
"swapType": "IrSwap",
"irSwapType": "IrFixedFloatingSwap",
"start": 2021.05.15,
"maturity": 2023.05.15,
"frequency": "Quarterly",
"fixedRate": 0.02,
"calendar": "CFET",
"fixedDayCountConvention": "Actual365",
"floatingDayCountConvention": "Actual360",
"payReceive": "Pay",
"iborIndex": "SHIBOR_3M",
"spread": 0.0005,
"notionalCurrency": "CNY",
"notionalAmount": 1E8,
}
instrument = parseInstrument(swap)
print(instrument)
Foreign Exchange Forward (FxForward)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Product name. It must be "Forward". | √ |
| forwardType | STRING | Foreign exchange forward type. It must be "FxForward". | √ |
| notionalAmount | DOUBLE | Notional principal amount | √ |
| notionalCurrency | STRING | Notional principal | √ |
| instrumentId | STRING | InstrumentId ID | × |
| expiry | DATE | Value date | √ |
| delivery | DATE | Settlement date | √ |
| currencyPair | STRING |
The currency pair, in the format "EURUSD", "EUR.USD", or "EUR/USD". Supported currency pairs include:
|
√ |
| direction | STRING | Trading direction, can be "Buy" or "Sell" | √ |
| strike | DOUBLE | Strike price | √ |
| domesticCurve | STRING | The domestic discount curve name | × |
| foreignCurve | STRING | The foreign discount curve name | × |
Define an INSTRUMENT object of FxForward type.
forward = {
"productType": "Forward",
"forwardType": "FxForward",
"expiry": 2025.09.24,
"delivery": 2025.09.26,
"currencyPair": "USDCNY",
"direction": "Buy",
"notionalCurrency": "USD",
"notionalAmount": 1E8,
"strike": 7.2
}
instrument = parseInstrument(forward)
print(instrument)
Foreign Exchange Swap (FxSwap)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Product name. It must be "Swap". | √ |
| swapType | STRING | Foreign exchange swap type. It must be "FxSwap". | √ |
| notionalAmount | DOUBLE | Notional principal amount | √ |
| notionalCurrency | STRING | Notional principal | √ |
| currencyPair | STRING |
The currency pair, in the format "EURUSD", "EUR.USD", or "EUR/USD". Supported currency pairs include:
|
√ |
| nearExpiry | DATE | Maturity date for the near leg | √ |
| nearDelivery | DATE | Settlement date for the near leg | √ |
| direction | STRING |
Trading direction, can be
|
√ |
| nearStrike | DOUBLE | Strike price for the near leg | √ |
| farExpiry | DATE | Maturity date for the far leg | √ |
| farDelivery | DATE | Settlement date for the far leg | √ |
| farStrike | DOUBLE | Strike price for the far leg | √ |
| domesticCurve | STRING | The domestic discount curve name | × |
| foreignCurve | STRING | The foreign discount curve name | × |
Define an INSTRUMENT object of FxSwap type.
swap = {
"productType": "Swap",
"swapType": "FxSwap",
"currencyPair": "EURUSD",
"direction": "Buy",
"notionalCurrency": "EUR",
"notionalAmount": 1E6,
"nearStrike": 1.1,
"nearExpiry": 2025.12.08,
"nearDelivery": 2025.12.10,
"farStrike": 1.2,
"farExpiry": 2026.06.08,
"farDelivery": 2026.06.10
}
instrument = parseInstrument(swap)
print(instrument)
Fx European Style Option (FxEuropeanOption)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Must be "Option" | √ |
| optionType | STRING | Must be "EuropeanOption" | √ |
| assetType | STRING | Must be "FxEuropeanOption" | √ |
| notionalAmount | DOUBLE | Notional principal amount | √ |
| notionalCurrency | STRING | Notional principal | √ |
| instrumentId | STRING | InstrumentId ID | × |
| maturity | DATE | Maturity date | √ |
| underlying | STRING |
The currency pair, in the format "EURUSD", "EUR.USD", or "EUR/USD". Supported currency pairs include:
|
√ |
| direction | STRING | Trading direction, can be "Buy" or "Sell" | √ |
| strike | DOUBLE | Strike price | √ |
| dayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | √ |
| payoffType | STRING | Payoff type. It can be "Call" or "Put". | √ |
| domesticCurve | STRING | The domestic discount curve name | × |
| foreignCurve | STRING | The foreign discount curve name | × |
| delivery | DATE | The delivery date | × |
The delivery field is supported starting from version 2.
When upgrading data from versions earlier than version 2 to version 2 or later, missing delivery fields in existing records will be automatically populated with maturity + 2.
Define an INSTRUMENT object of FxEuropeanOption type.
option = {
"productType": "Option",
"optionType": "EuropeanOption",
"assetType": "FxEuropeanOption",
"notionalCurrency": "EUR",
"notionalAmount": 1000000.0,
"strike": 1.2,
"maturity": "2025.10.08",
"payoffType": "Call",
"dayCountConvention": "Actual365",
"underlying": "EURUSD"
}
instrument = parseInstrument(option)
print(instrument)
Related functions: bondPricer (Bond Pricing), irDepositPricer (Deposit Pricing), bondFuturesPricer (Treasury Futures Pricing), fxForwardPricer (FX Forward Pricing), fxSwapPricer (FX Swap Pricing), irFixedFloatingSwapPricer (IR Fixed-Floating Swap Pricing), fxEuropeanOptionPricer (FX European Option Pricing)
American Commodity Futures Options (cmFutAmericanOption)
| Field Name | Type | Description | Required |
|---|---|---|---|
| productType | STRING | Fixed value: "Option" | Yes |
| optionType | STRING | Fixed value: "AmericanOption" | Yes |
| assetType | STRING | Fixed value: "CmFutAmericanOption" | Yes |
| notionalAmount | DOUBLE | Notional principal amount | Yes |
| notionalCurrency | STRING | Notional currency | Yes |
| instrumentId | STRING | Contract code, standard format: Underlying futures contract code + Contract expiry month + Option type code + Strike price, e.g., Sugar option SR2509P6300 = SR+2509+P+6300 | No |
| direction | STRING | Trading direction. Valid values: “Buy” (default), “Sell”. | No |
| maturity | DATE | Maturity date | Yes |
| strike | DOUBLE | Strike price | Yes |
| payoffType | STRING | Payoff type. Valid values: “Call”, “Put” | Yes |
| underlying | STRING | Underlying futures contract code, e.g., SR2509 | Yes |
| dayCountConvention | STRING | Day count convention. Valid values: "ActualActualISDA", "ActualActualISMA", "Actual365", "Actual360" | Yes |
| discountCurve | STRING | Discount curve name for pricing reference. The default valud for RMB deposits is "CNY_FR_007". | No |
American Equity Options (eqAmericanOptions)
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Fixed value: "Option". |
√ |
| optionType | STRING | Fixed value: "AmericanOption". |
√ |
| assetType | STRING | Fixed value: "EqAmericanOption" (Equity
American Option). |
√ |
| notionalAmount | DOUBLE | Notional amount. | √ |
| notionalCurrency | STRING | Notional currency. Defaults to CNY. | √ |
| instrumentId | STRING | Instrument identifier. For example,
TCH250328C0040000 is interpreted as
follows: TCH = underlying (Tencent Holdings);
250328 = maturity date (March 28, 2025);
C = Call option; 0040000 =
strike price 400.00 HKD. |
× |
| direction | STRING | Trade direction: Buy or
Sell. Defaults to
Buy. |
× |
| maturity | DATE | Maturity date (expiration date). | √ |
| strike | DOUBLE | Strike price. | √ |
| payoffType | STRING | Payoff type (enumeration): Call or
Put. |
√ |
| underlying | STRING | Underlying futures contract code, e.g.,
TCH. |
√ |
| dayCountConvention | STRING | Day count convention. Available options:
"ActualActualISDA",
"ActualActualISMA",
"Actual365",
"Actual360". |
√ |
| discountCurve | STRING | Discount curve name used for pricing. For CNY deposits, the
default is "CNY_FR_007". |
× |
| dividendCurve | STRING | Dividend curve name used for pricing. | × |
