getInstrumentField

Syntax

getInstrumentField(instrument, key, [default])

Details

Get the value of the specified field (key) from one or more instruments:

  • If default is not set, the function returns the field value if it exists; otherwise, it returns a null value.
  • If default is set, the function returns the field value converted to the type specified by default if the field has a valid value; otherwise, it returns default.

Arguments

instrument is a scalar or vector of the INSTRUMENT type, indicating one or more instruments.

key is a scalar of the STRING type, indicating a field from the instrument. The value must match a field name defined in instrument.

default is a scalar, indicating the default value for key. The following types are supported: LOGICAL, INTEGRAL (except COMPRESSED), TEMPORAL (except DATEHOUR), FLOATING, LITERAL, and DECIMAL.

Returns

  • If instrument is a scalar, the function returns a scalar.
  • If instrument is a vector, the function returns a vector of the same length as instrument.

Examples

bond = {
    "productType": "Cash",
    "assetType": "Bond",
    "bondType": "ZeroCouponBond",
    "version": 0,
    "instrumentId": "0001",
    "start": 1996.03.01,
    "maturity": 2032.05.15,
    "dayCountConvention": "ActualActualISDA",
    "coupon": 0.0276,
    "issuePrice": 100.0,
    "frequency": "Semiannual",
    "subType":"TREASURY_BOND",
    "creditRating":"B",
    "settlement": 2022.05.15 
}
ins = parseInstrument(bond)
getInstrumentField(ins, "productType")
// output: Cash

Related functions: parseInstrument, getInstrumentKeys