createYieldCurveEngine

Syntax

createYieldCurveEngine(name, dummyTable, assetType, fitMethod, keyColumn, modelOutput, frequency, [timeColumn], [predictDummyTable],[predictInputColumn], [predictKeyColumn],[predictTimeColumn], [predictOutput], [extraMetrics],[fitAfterPredict=false])

Details

Create a yield curve engine to fit a curve, primarily used in financial applications to model the relationship between interest rates (or yields) and maturities of financial instruments (currently supporting bonds only).

The engine constructs and predicts yield curves using different interpolation or fitting methods based on the specified fitMethod. Supported techniques include linear interpolation, cubic spline interpolation, Krogh interpolation, piecewise regression, polynomial fitting, and NS/NSS models.

Arguments

name is a STRING scalar indicating the engine name. It is the only identifier of a yield curve engine on a data/compute node. It can have letter, number and "_" and must start with a letter.

dummyTable is a table object whose schema must be the same as the input table. It requires the following columns:

Column Type Description
symbol SYMBOL bond code
sendingTime TIMESTAMP timestamp
askDirtyprice1 DECIMAL best ask (dirty price)
bidDirtyprice1 DECIMAL best bid (dirty price)
midDirtyprice1 DECIMAL mid dirty price
askyield1 DECIMAL best ask yield
bidyield1 DECIMAL best bid yield
midyield1 DECIMAL mid yield
timetoMaturity DOUBLE term to maturity
assetType INT/STRING user-defined asset type
dataSource INT user-defined data source, e.g., 0 represents X-Bond; 1 represents ESP
clearRate STRING settlement date, e.g., "T0”, “T1”, “T2”

assetType is an INT or STRING vector where each element identifies a unique asset. It must match the data type of “assetType“ column defined in dummyTable.

fitMethod is a metacode tuple of fit methods that map to each asset in assetType. Supported fit methods: piecewiseLinFit, cubicSpline, linearInterpolateFit, kroghInterpFit, polyFit, nss, ns.

Note that the length of fitMethod must be the same as assetType.

keyColumn is a STRING scalar (“assetType“) or vector indicating the grouping column(s). If it is a vector, the first element must be "assetType", while the remaining elements specify grouping columns within each asset.

modelOutput is the output table for fitted model. The columns of modelOutput are in the following order:

(1) The first column must be a time column. It has the same data type as timeColumn if specified, otherwise uses system time (TIMESTAMP type).

(2) Followed by keyColumn.

(3) A BLOB column for models.

frequency can be an interger or a DURATION scalar that determines how often the model updates.

  • When given an integer, the model updates once the cumulative count of data entries that have not been used in the model fitting reaches the specified threshold.
  • When given a DURATION value, the model updates every frequency time.
    • if timeColumn is specified, model updates by event time, starting from the rounded timestamp of the first record in each group. For example, given timestamps [09:30:00.100, 09:32:00.100, 09:35:00.100, 09:45:00.100, 09:50:00.100], if frequency=5m, the model updates at 09:35:00.000, 09:40:00.000, 09:50:00.000. The right boundary is open, meaning the model's output at 09:35:00.000 does not include data from 09:35:00.000.
    • if not, model updates based on system time, starting from rounded timestamp of the first record's arrival. If no records arrive within the window, no updates occur.

timeColumn (optional) is a temporal vector indicating the time column of the input table. If not set, the system time is used.

predictDummyTable (optional) is a table object, serving as the input table for prediction. It has the same schema asdummyTable by default.

predictInputColumn (optional) is a STRING scalar specifying the input data for prediction.

predictKeyColumn (optional) is a STRING scalar or vector indicating the grouping column(s) of predictDummyTable. Predictions are grouped by this column, defaulting to keyColumn.

predictTimeColumn (optional) is a temporal vector indicating the time column of the input table. Defaults totimeColumn.

predictOutput (optional) is the output table for prediction results. The columns of predictOutput are in the following order:

(1) The first column must be a time column. It has the same data type as predictTimeColumn if specified, otherwise uses system time (TIMESTAMP type).

(2) The predictKeyColumn column.

(3) The predictInputColumn column.

(4) A column for prediction results.

(5) Additional output matching the results of metrics specified in extraMetrics.

Note: For data prediction, predictOutput is required.

extraMetrics (optional) is metacode or a tuple of metacode indicating the additional output beyond predict results, including columns from the input table (excluding keyColumn) or factors (formulas for calculation).

fitAfterPredict (optional) is a boolean value.

  • If set to true, the incoming data will first be ingested into the predictDummyTable for prediction using the existing model, and then it will be ingested into the dummyTable for model fitting.
  • If set to false (default), the incoming data is directly ingested into the dummyTable for model fitting. You can separately use the appendForPredict method to add data to the predictDummyTable for prediction purposes.

Examples

// define the input table, asset types and corresponding fitting methods
dummyTable = table(1:0, `symbol`sendingtime`askDirtyPrice1`bidDirtyPrice1`midDirtyPirce1`askyield1`bidyield1`midyield1`timetoMaturity`assetType`datasource`clearRate, 
                        [SYMBOL, TIMESTAMP,DECIMAL32(3),DECIMAL32(3),DECIMAL32(3),DECIMAL32(3),DECIMAL32(3),DECIMAL32(3),DOUBLE,INT,INT,STRING])
assetType=[0,1,2]
fitMethod=[<piecewiseLinFit(timetoMaturity, midyield1, 10)>,
            <nss(timetoMaturity,bidyield1,"ns")>,
            <piecewiseLinFit(timetoMaturity, askyield1, 5)>]

// define the output tables
modelOutput=table(1:0, `time`assetType`dataSource`clearRate`model,
                        [TIMESTAMP,INT,INT,SYMBOL,BLOB])
predictOutput=table(1:0, `time`assetType`dataSource`clearRate`x`y,[TIMESTAMP,INT,INT,SYMBOL,DOUBLE,DOUBLE])

// create a yield curve engine
engine = createYieldCurveEngine(name="test", dummyTable=dummyTable,assetType=assetType,fitMethod=fitMethod,
                                keyColumn=`assetType`dataSource`clearRate, modelOutput=modelOutput,
                                frequency=10,predictInputColumn=`timetoMaturity,predictTimeColumn=`sendingtime, 
                                predictOutput=predictOutput,fitAfterPredict=true)
                                
// append data for fitting
data = table(take(`a`b`c, 30) as  symbol, take(now(), 30) as time, decimal32(rand(10.0, 30),3) as p1,  decimal32(rand(10.0, 30),3) as p2,  decimal32(rand(10.0, 30),3) as p3, decimal32(rand(10.0, 30),3) as p4,  decimal32(rand(10.0, 30),3) as p5,  decimal32(rand(10.0, 30),3) as p6, (rand(10.0, 30)+10).sort() as timetoMaturity, take(0 1 2, 30) as assetType, take([1], 30) as datasource, take("1", 30) as clearRate)
engine.append!(data)

Related Function: appendForPrediction