Bond Backtesting Configurations
The backtesting platform supports bond assets, including interbank bonds and Shanghai Stock Exchange bonds.
Interbank Bonds
Engine Configuration
Configurations for config in the createBacktester and createBacktestEngine methods:
| Key | Description | Notes |
|---|---|---|
| "startDate" | Start date |
Required. DATE type. e.g., 2020.01.01 |
| "endDate" | End date |
Required. DATE type. e.g., 2020.01.01 |
| "strategyGroup" | Strategy type |
Required. The following values are supported:
|
| "cash" | Initial cash | Required. DOUBLE type. |
| "dataType" | Market data type |
Required. INT type. Possible values are:
|
| "matchingMode" | Order matching mode | INT type. Orders are matched using the order matching simulator by default. When set to 3, trades are executed at the order price. Setting it to 1 or 2 has no effect. |
| "msgAsTable" | Market data format |
BOOL type. Default is false.
|
| "benchmark" | Benchmark instrument | STRING type, e.g., "000300.XSHG". Used in the
getReturnSummary method. |
| "latency" | The latency from order submission to execution | DOUBLE type, in milliseconds, this simulates the delay between the time a user submits an order and the time it is processed. The default is 0, which means no delay. |
| "enableIndicatorOptimize" | Whether to enable indicator calculation optimization |
BOOL type. Default is false.
|
| "addTimeColumnInIndicator" | Whether to add a time column to the indicator subscription results. |
BOOL type. Default is false.
|
| "isBacktestMode" | Backtesting or matching mode. |
BOOL type. Default is true.
|
| "dataRetentionWindow" | Data retention policy for indicator optimization |
STRING type. Effective only when
|
| "context" | Strategy logic context structure |
A dictionary consisting of global strategy variables, for example:
|
| "orderBookMatchingRatio" | The proportion of an order that gets filled | DOUBLE type. Default is 1.0, valid range: [0-1.0]. |
| "matchingRatio" | The matching ratio within price intervals | DOUBLE type, with a value ranging from 0 to 1.0. If not specified, it takes the value of "orderBookMatchingRatio". If both are unspecified, the default is 1.0. |
| "immediateOrderConfirmation" | Whether to return order confirmation immediately. | The default is false. When set to true, the order
confirmation is returned immediately. Currently, only snapshots
(dataType = 2) are supported. |
| "immediateCancel" | Whether to cancel the order immediately | The default is false. When set to true, the order is canceled immediately. |
| "msgAsPiecesOnSnapshot" | Whether each data record triggers the
onSnapshot callback in sequence, or all
records with the same timestamp trigger it at the same
time. |
BOOL type. The default value is false, and
onSnapshot is triggered sequentially for
each data record. |
| "tradeInLots" | Sets the minimum trading volume for interbank bonds. |
|
Basic Information Table
See the following table for the fields in the security reference information table specified by the securityReference parameter of the createBacktester method:
| Field | Type | Description |
|---|---|---|
| symbol | STRING | Bond. |
| couponRate | DOUBLE | Coupon rate. |
| frequency | INT | Coupon payment frequency. |
| valueDate | DATE | Interest accrual start date. |
| maturityDate | DATE | Maturity date. |
| bondLendingRate | DOUBLE | Securities lending rate (optional, this field may be omitted if securities lending and short selling are not available). |
| marginRatio | DOUBLE | Margin ratio (optional, this field may be omitted if securities lending and short selling are not available). |
| bondType | STRING |
Choose one of the following options:
|
| issuePrice | DOUBLE | Issue price. The default value is 100. |
Market Data Schema
When appending data into the backtesting engine via appendQuotationMsg, the msg is:
colName=[`symbol,`symbolSource,`timestamp,`bidSettlType,`bidQty,`bidPrice,
`bidYield,`askSettlType,`askQty,`askPrice,`askYield,`tradePrice,
`tradeQty,`settlType,`yield]
colType=["SYMBOL","SYMBOL","TIMESTAMP","INT[]","LONG[]","DOUBLE[]","DOUBLE[]",
"INT[]","LONG[]","DOUBLE[]","DOUBLE[]","DOUBLE[]","LONG[]","INT[]","DOUBLE[]"]
messageTable=table(10000000:0, colName, colType)
Snapshot and tick-by-tick trade detail table schema:
| Name | Type | Description |
|---|---|---|
| symbol | STRING/SYMBOL | Bond symbol. |
| symbolSource | STRING/SYMBOL | Market: interbank "X_BOND". |
| timestamp | TIMESTAMP | Timestamp. |
| bidSettlType | INT[] | Bid settlement cycle. |
| bidQty | LONG[] | Bid volume. |
| bidPrice | DOUBLE[] | Bid clean price (yuan). |
| bidYield | DOUBLE[] | Bid yield to maturity (YTM). |
| askSettlType | INT[] | Ask settlement cycle. |
| askQty | LONG[] | Ask volume. |
| askPrice | DOUBLE[] | Ask clean price (yuan). |
| askYield | DOUBLE[] | Ask yield to maturity (YTM). |
| tradePrice | DOUBLE[] | List of trade prices for the interval. |
| tradeQty | LONG[] | List of trade volumes for the interval. |
| settlType | INT[] | Settlement cycle. |
| yield | DOUBLE[] | Yield to maturity. |
Minute-level data table schema:
| Name | Type | Description |
|---|---|---|
| symbol | STRING/SYMBOL | Bond symbol. |
| symbolName | STRING/SYMBOL | Bond short name. |
| tradeDate | TIMESTAMP | Timestamp. |
| tradeClean | DOUBLE | Closing clean price. |
| tradeDirty | DOUBLE | Closing dirty price. |
| tradeAccruedInterest | DOUBLE | Accrued interest. |
| yield | DOUBLE | Yield to maturity at close. |
| tradeVolume | DOUBLE | Filled quantity. |
When market data replay ends during backtesting, send an end marker to the engine through Backtest::appendEndMarker(engine) to notify the engine that all market data has been sent.
messageTable=select top 1* from messageTable where timestamp=max(timestamp)
Backtest::appendQuotationMsg(engine,messageTable)
Backtest::appendEndMarker(engine)
Snapshot Callback Function
Snapshot data callback function onSnapshot: input parameter msg
msg is a dictionary. Each key represents a symbol, and the corresponding value contains snapshot data for that symbol. Each snapshot data contains the following fields:
| Field | Type | Description |
|---|---|---|
| symbol | SYMBOL | Bond symbol. |
| messageSource | SYMBOL | Market: interbank "X_BOND". |
| timestamp | TIMESTAMP | Timestamp. |
| byield | DOUBLE[] | Bid yield to maturity (YTM). |
| ayield | DOUBLE[] | Ask yield to maturity (YTM). |
| bmdEntryPrice | DOUBLE[] | Bid clean price (yuan). |
| amdEntryPrice | DOUBLE[] | Ask clean price (yuan). |
| bmdEntrySize | LONG[] | Bid volume. |
| amdEntrySize | LONG[] | Ask volume. |
| bsettlType | LONG[] | Bid settlement cycle. |
| asettlType | LONG[] | Ask settlement cycle. |
| settlType | LONG[] | Interval settlement cycle. |
| tradePrice | DOUBLE[] | List of trade prices for the interval. |
| tradeYield | DOUBLE[] | Yield to maturity. |
| tradeQty | LONG[] | List of trade volumes for the interval. |
Shanghai Stock Exchange Bonds
Engine Configuration
The config parameter of the createBacktester method:
| Key | Description | Notes |
|---|---|---|
| "startDate" | Start date |
Required. DATE type. e.g., 2020.01.01 |
| "endDate" | End date |
Required. DATE type. e.g., 2020.01.01 |
| "strategyGroup" | Strategy type | Required: Must be "XSHGBond". |
| "cash" | Initial cash | Required. DOUBLE type. |
| "commission" | Commission | Required. DOUBLE type. |
| "tax" | Stamp duty | Required. DOUBLE type. |
| "dataType" | Market data type |
Required. INT type. Possible values are:
|
| "orderBookMatchingRatio" | The proportion of an order that gets filled | DOUBLE type. Defaults to 1.0. Valid values range from 0 to 1.0. |
| "matchingRatio" | The matching ratio within price intervals | DOUBLE type, with a value between 0 and 1.0. If unspecified, this configuration uses the value of "orderBookMatchingRatio". If both are unspecified, the default is 1.0. |
| "setLastDayPosition" | Initial position | Initial position information table; see the table below for its schema. |
| "msgAsPiecesOnSnapshot" | Whether each data record triggers the
onSnapshot callback in sequence, or all
records with the same timestamp trigger it at the same
time. |
BOOL type. The default value is false, and
onSnapshot is triggered sequentially for
each data record. |
The schema of the initial position information table is as follows:
| Field | Type | Description |
|---|---|---|
| symbol | SYMBOL | Bond symbol. |
| longPosition | LONG or INT | Long position quantity. |
| costPrice | DOUBLE | Cost price. |
Basic Information Table
See the following table for the fields in the security reference information table specified by the securityReference parameter of the createBacktester method:
| Field | Type | Description |
|---|---|---|
| symbol | STRING | Bond. |
| couponRate | DOUBLE | Coupon rate. |
| frequency | INT | Coupon payment frequency. |
| valueDate | DATE | Interest accrual start date. |
| maturityDate | DATE | Maturity date. |
Market Data Schema
The input market data can be provided in a wide table that includes firm-quote market data and trade details. Its schema is as follows:
| Field | Data Type | Description |
|---|---|---|
| symbol | STRING/SYMBOL | Security symbol. |
| timestamp | TIMESTAMP | Timestamp. |
| msgType | INT |
Market data type. Valid values are:
|
| symbolName | STRING/SYMBOL | Security name. |
| bidId | INT | Bid order ID. |
| bidTime | TIMESTAMP | Bid quote time. |
| bidParty | STRING/SYMBOL | Bid quoting party. |
| bidClean | DOUBLE | Bid clean price. |
| bidQty | LONG | Bid quantity. |
| bidDirty | DOUBLE | Bid dirty price. |
| bidYield | DOUBLE | Bid yield to maturity (YTM). |
| askId | INT | Ask order ID. |
| askTime | TIMESTAMP | Ask quote time. |
| askParty | STRING/SYMBOL | Ask quoting party. |
| askClean | DOUBLE | Ask clean price. |
| askQty | LONG | Ask quantity. |
| askDirty | DOUBLE | Ask dirty price. |
| askYield | DOUBLE | Ask yield to maturity (YTM). |
| accruedInterest | DOUBLE | Accrued interest. |
| tradeTime | TIMESTAMP | Execution time. |
| tradeClean | DOUBLE | Trade clean price. |
| tradeAccruedInterest | DOUBLE | Accrued interest. |
| tradeDirty | DOUBLE | Trade dirty price. |
| yield | DOUBLE | Yield to maturity. |
| tradeVolume | INT | Filled quantity. |
| tradeValue | DOUBLE | Trading value (Turnover). |
| tradeType | INT |
Trade method. Valid values are:
|
