📝 docs(tsl-api): resolve backtesting return contract

This commit is contained in:
csh
2026-08-25 13:16:45 +08:00
parent d1568c02cd
commit 9c8d77e1c4
7 changed files with 834 additions and 56 deletions
@@ -98,11 +98,46 @@
},
{
"api": "tsBackTesting.FGroupType",
"role": "candidate_mode_discriminator",
"role": "return_schema_discriminator",
"contract_evidence_required": true,
"evidence": [
"module/ts-backtesting.md#fgrouptype"
]
},
{
"api": "tsBackTesting.FRateType",
"role": "ratio_allocation_mode",
"evidence": [
"module/ts-backtesting.md#fratetype"
]
},
{
"api": "tsBackTesting.FPriceType",
"role": "execution_price_mode",
"evidence": [
"module/ts-backtesting.md#fpricetype"
]
},
{
"api": "tsBackTesting.FFeeType",
"role": "fee_input_mode",
"evidence": [
"module/ts-backtesting.md#ffeetype"
]
},
{
"api": "tsBackTesting.FOpenVolType",
"role": "quantity_open_size_mode",
"evidence": [
"module/ts-backtesting.md#fopenvoltype"
]
},
{
"api": "tsBackTesting.FCloseVolType",
"role": "quantity_close_size_mode",
"evidence": [
"module/ts-backtesting.md#fclosevoltype"
]
}
],
"hooks": [
@@ -198,10 +233,394 @@
"contracts": [
{
"id": "ts-backtesting-trade-order",
"status": "incomplete",
"status": "resolved",
"callback": "tsBackTesting.GetTradeOrder",
"reason": "The reference states target holdings or trade details but does not yet define the mode-specific record fields.",
"required_next_step": "Resolve the configuration-to-return-schema mapping before generating callback fields.",
"mode_discriminator": {
"api": "tsBackTesting.FGroupType"
},
"return_schemas": [
{
"id": "ratio-target-holdings",
"when": {
"FGroupType": "1"
},
"result_kind": "target_holdings",
"record_shape": "table_array",
"fields": [
{
"name": "截止日",
"type": "date_time",
"required": true,
"pdf_non_empty": true
},
{
"name": "代码",
"type": "string",
"required": true,
"pdf_non_empty": true
},
{
"name": "方向",
"type": "integer",
"required": false,
"default": "1",
"pdf_non_empty": true,
"values": {
"0": "short",
"1": "long"
}
},
{
"name": "比例(%)",
"type": "numeric",
"pdf_non_empty": true,
"required_when": [
{
"field": "FRateType",
"equals": [
"-1"
]
}
]
},
{
"name": "成交价",
"type": "numeric",
"pdf_non_empty": false,
"required_when": [
{
"field": "FPriceType",
"equals": [
"-1"
]
}
],
"description": "Provide when FPriceType=-1; otherwise the framework selects the execution price."
},
{
"name": "乘数",
"type": "numeric",
"required": false,
"pdf_non_empty": false,
"default": "1_or_instrument_default"
},
{
"name": "保证金比例(%)",
"type": "numeric",
"required": false,
"pdf_non_empty": false,
"default": "100_or_instrument_default"
},
{
"name": "开仓费率(%)",
"type": "numeric",
"required": false,
"pdf_non_empty": true,
"used_when": [
{
"field": "FFeeType",
"equals": [
"1"
]
}
],
"fallback": "tsBackTesting.StockFee"
},
{
"name": "平仓费率(%)",
"type": "numeric",
"required": false,
"pdf_non_empty": true,
"used_when": [
{
"field": "FFeeType",
"equals": [
"1"
]
}
],
"fallback": "tsBackTesting.StockFee"
}
],
"alternate_returns": [
{
"type": "empty_array",
"meaning": "clear_all_positions"
},
{
"type": "non_array",
"meaning": "skip_current_rebalance",
"documented_examples": [
-1,
1
]
}
],
"evidence": [
"module/ts-backtesting.md#gettradeorderv_end_t"
]
},
{
"id": "quantity-trade-details",
"when": {
"FGroupType": "2"
},
"result_kind": "trade_details",
"record_shape": "table_array",
"fields": [
{
"name": "截止日",
"type": "date_time",
"required": true,
"pdf_non_empty": true
},
{
"name": "代码",
"type": "string",
"required": true,
"pdf_non_empty": true
},
{
"name": "方向",
"type": "integer",
"required": false,
"default": "1",
"pdf_non_empty": true,
"values": {
"0": "short",
"1": "long"
}
},
{
"name": "动作",
"type": "integer",
"required": true,
"compat_default": "0",
"pdf_non_empty": true,
"values": {
"0": "open",
"1": "close",
"32": "build_option_group",
"33": "unlock_option_group"
}
},
{
"name": "成交量",
"type": "numeric",
"pdf_non_empty": true,
"required_when": [
{
"field": "FOpenVolType",
"equals": [
"1"
],
"record_when": {
"动作": [
"0"
]
}
},
{
"field": "FCloseVolType",
"equals": [
"1"
],
"record_when": {
"动作": [
"1"
]
}
}
],
"record_required_when": {
"动作": [
"32",
"33"
]
}
},
{
"name": "成交价",
"type": "numeric",
"pdf_non_empty": true,
"required_when": [
{
"field": "FPriceType",
"equals": [
"-1"
]
}
],
"record_required_when": {
"动作": [
"32",
"33"
]
},
"record_constraint_when": {
"动作": {
"32": "greater_than_zero",
"33": "greater_than_zero"
}
}
},
{
"name": "资金",
"type": "numeric",
"required_when": [
{
"field": "FOpenVolType",
"equals": [
"2"
],
"record_when": {
"动作": [
"0"
]
}
}
]
},
{
"name": "剩余资金占比(%)",
"type": "numeric",
"required_when": [
{
"field": "FOpenVolType",
"equals": [
"3"
],
"record_when": {
"动作": [
"0"
]
}
}
]
},
{
"name": "平仓数量占比(%)",
"type": "numeric",
"required_when": [
{
"field": "FCloseVolType",
"equals": [
"2"
],
"record_when": {
"动作": [
"1"
]
}
}
]
},
{
"name": "乘数",
"type": "numeric",
"required": false,
"pdf_non_empty": false,
"default": "1_or_instrument_default"
},
{
"name": "保证金比例(%)",
"type": "numeric",
"required": false,
"pdf_non_empty": false,
"default": "100_or_instrument_default"
},
{
"name": "费率(%)",
"type": "numeric",
"pdf_non_empty": true,
"used_when": [
{
"field": "FFeeType",
"equals": [
"1"
]
}
],
"record_value_when": {
"动作": {
"32": 0,
"33": 0
}
},
"fallback": "tsBackTesting.StockFee"
},
{
"name": "费用",
"type": "numeric",
"pdf_non_empty": false,
"required_when": [
{
"field": "FFeeType",
"equals": [
"2"
]
}
],
"record_value_when": {
"动作": {
"32": 0,
"33": 0
}
}
},
{
"name": "组 ID",
"type": "string",
"pdf_non_empty": true,
"required": false,
"applies_when": "option_group_strategy",
"required_in_extension": true,
"description": "Required as a non-empty shared identifier for option-group rows; empty for ungrouped single-leg rows."
},
{
"name": "组合类型",
"type": "string",
"pdf_non_empty": false,
"required": false,
"applies_when": "option_group_strategy",
"description": "Option strategy identifier such as CNSJC or STD; may be empty for single-leg or unrecognized combinations."
}
],
"record_rules": [
{
"when": "option_group_strategy",
"rule": "Return all component contracts for a group; rows in the same group share 组 ID, 动作, and 成交量."
},
{
"when": {
"动作": [
"0",
"32",
"33"
]
},
"rule": "Option-group opening, construction, and unlock records use a concrete 成交量; action 1 may instead use 平仓数量占比(%)."
},
{
"when": {
"动作": [
"0"
]
},
"rule": "Option-group opening (action 0) uses FOpenVolType=1; fixed-amount and remaining-funds modes are not supported for this action."
}
],
"alternate_returns": [
{
"type": "empty_array",
"meaning": "no_trade_at_current_time"
}
],
"evidence": [
"module/ts-backtesting.md#gettradeorderv_end_t"
]
}
],
"evidence": [
"module/ts-backtesting.md#gettradeorderv_end_t"
]
@@ -2658,6 +2658,7 @@ FClearCycle module ts-timing-evaluation FClearCycle module/ts-timing-evaluation.
FClose_N1 module ts-statistical-arbitrage FClose_N1 module/ts-statistical-arbitrage.md fclose_n1 上侧平仓标准差倍数 field instance public tsStatisticalArbitrage tsStatisticalArbitrage.FClose_N1
FClose_N2 module ts-statistical-arbitrage FClose_N2 module/ts-statistical-arbitrage.md fclose_n2 下侧平仓标准差倍数 field instance public tsStatisticalArbitrage tsStatisticalArbitrage.FClose_N2
FCloseFeeRate module ts-timing-evaluation FCloseFeeRate module/ts-timing-evaluation.md fclosefeerate 平仓费率(%) 0 field instance public tsTimingEvaluation tsTimingEvaluation.FCloseFeeRate
FCloseVolType module ts-backtesting FCloseVolType module/ts-backtesting.md fclosevoltype 数量类组合平仓数量模式 1:固定成交量法;2:可平仓数量占比法 field instance public tsBackTesting tsBackTesting.FCloseVolType
FcLowestFee module ts-backtesting FcLowestFee module/ts-backtesting.md fclowestfee 平仓最低费用 5.0 field instance public tsBackTesting tsBackTesting.FcLowestFee
FCombinations module ts-backtest-overfit-prob FCombinations module/ts-backtest-overfit-prob.md fcombinations 生成的子集组合 field instance public tsBacktestOverfitProb tsBacktestOverfitProb.FCombinations
FComFactorArr module ts-hg-data-process FComFactorArr module/ts-hg-data-process.md fcomfactorarr 合成因子库 array() field instance public ts_HGDataProcess ts_HGDataProcess.FComFactorArr
@@ -2782,7 +2783,7 @@ FFaRet module ts-factor-portfolio-optimizer FFaRet module/ts-factor-portfolio-op
FFaRets module ts-factor-portfolio-optimizer FFaRets module/ts-factor-portfolio-optimizer.md ffarets 因子收益序列 field instance public tsFactorPortfolioOptimizer tsFactorPortfolioOptimizer.FFaRets
FFeature module ts-persistence-of-fund FFeature module/ts-persistence-of-fund.md ffeature 基金业绩指标 field instance public ts_PersistenceOfFund ts_PersistenceOfFund.FFeature
FFeeRate module derivatives-analysis FFeeRate module/derivatives-analysis/option-delta-hedging.md ffeerate 交易费率百分比,默认值为 0 field instance public opDeltaHedging opDeltaHedging.FFeeRate
FFeeType module ts-backtesting FFeeType module/ts-backtesting.md ffeetype 费用类别 1:费率法 field instance public tsBackTesting tsBackTesting.FFeeType
FFeeType module ts-backtesting FFeeType module/ts-backtesting.md ffeetype 费用类别 1:费率法;2:费用法。比例类只能使用费率法;数量类可使用费率法或费用法 field instance public tsBackTesting tsBackTesting.FFeeType
FFeeType2 module ts-backtesting FFeeType2 module/ts-backtesting.md ffeetype2 比例类费率 1: 历史明细中查找开、 平仓费率 field instance public tsBackTesting tsBackTesting.FFeeType2
FfhExchangeRatetype module ts-backtesting FfhExchangeRatetype module/ts-backtesting.md ffhexchangeratetype 分红汇率类型 2:对应市场结算汇率中间价 field instance public tsBackTesting tsBackTesting.FfhExchangeRatetype
ffi_es dotnet financial ffi_es(w_p, x, f, delta, confidence_interval) dotnet/financial/financial_engineering-risk_model-application-risk_analysis-algorithm_layer.md ffi_es 金融 金融工程 风险模型 应用 风险分析 算法层 返回 获取 ES 返回期望损失ES function ffi_es
@@ -2824,7 +2825,7 @@ fgRight builtin graph fgRight() builtin/graph.md fgright 图形对象 图形 图
fgRightDown builtin graph fgRightDown() builtin/graph.md fgrightdown 图形对象 图形 图表 graph 对象 实例 object 右下 function fgRightDown
fgRightUp builtin graph fgRightUp() builtin/graph.md fgrightup 图形对象 图形 图表 graph 对象 实例 object 右上 function fgRightUp
FGroups module ts-multi-factor FGroups module/ts-multi-factor.md fgroups 五分位 field instance public tsMultiFactor tsMultiFactor.FGroups
FGroupType module ts-backtesting FGroupType module/ts-backtesting.md fgrouptype 组合类型 1:比例类组合 field instance public tsBackTesting tsBackTesting.FGroupType
FGroupType module ts-backtesting FGroupType module/ts-backtesting.md fgrouptype 组合类型 1:比例类组合2:数量类组合。期权不支持比例类回测 field instance public tsBackTesting tsBackTesting.FGroupType
FGroupType module ts-multi-factor FGroupType module/ts-multi-factor.md fgrouptype 分组方式 1:百分位 field instance public tsMultiFactor tsMultiFactor.FGroupType
fgUp builtin graph fgUp() builtin/graph.md fgup 图形对象 图形 图表 graph 对象 实例 object 上 function fgUp
Fh dotnet math Fh dotnet/math/optimization.md fh 二次型 field instance public tsOptimizer tsOptimizer.Fh
@@ -3149,6 +3150,7 @@ footerValue dotnet base footerValue(t, from_col, tocol, average_col_field, _type
FOpen_N1 module ts-statistical-arbitrage FOpen_N1 module/ts-statistical-arbitrage.md fopen_n1 上侧开仓标准差倍数 field instance public tsStatisticalArbitrage tsStatisticalArbitrage.FOpen_N1
FOpen_N2 module ts-statistical-arbitrage FOpen_N2 module/ts-statistical-arbitrage.md fopen_n2 下侧开仓标准差倍数 field instance public tsStatisticalArbitrage tsStatisticalArbitrage.FOpen_N2
FOpenFeeRate module ts-timing-evaluation FOpenFeeRate module/ts-timing-evaluation.md fopenfeerate 开仓费率(%) 0 field instance public tsTimingEvaluation tsTimingEvaluation.FOpenFeeRate
FOpenVolType module ts-backtesting FOpenVolType module/ts-backtesting.md fopenvoltype 数量类组合开仓数量模式 1:固定成交量法;2:固定金额法;3:剩余资金占比法 field instance public tsBackTesting tsBackTesting.FOpenVolType
FOPMaturityDate module derivatives-analysis FOPMaturityDate module/derivatives-analysis/option-instrument-indicators.md fopmaturitydate 到期月份序号;0 为全部,1 为近月,2 为次近月,依次类推 field instance public ts_Options_Screening ts_Options_Screening.FOPMaturityDate
FOPPZID module derivatives-analysis FOPPZID module/derivatives-analysis/option-instrument-indicators.md foppzid 期权品种或标的代码;空字符串表示不按品种筛选 field instance public ts_Options_Screening ts_Options_Screening.FOPPZID
FOpsId module ts-ops FOpsId module/ts-ops.md fopsid 服务标识 TS-OPS 服务 ID property instance public opsServer opsServer.FOpsId
@@ -3189,7 +3191,7 @@ FPriceRateTo0 module ts-backtesting FPriceRateTo0 module/ts-backtesting.md fpric
FPriceStep module bond-research FPriceStep module/bond-research/bond-price-segmentation.md fpricestep 价格频数分布步长,单位为元,默认 10 field instance public cb_PriceAndDeadlineData cb_PriceAndDeadlineData.FPriceStep
FPriceType module bond-research FPriceType module/bond-research/bond-price-segmentation.md fpricetype 统计最高价和最低价时使用的价格类型;0 为收盘价,1 为当日最高价或最低价 field instance public cb_PriceAndDeadlineData cb_PriceAndDeadlineData.FPriceType
FPriceType module factor-research FPriceType module/factor-research/index-chip-factors.md fpricetype 指数均价算法;支持算术平均、成交量加权、成交金额加权及调整后的成交量加权 field instance public ts_IndexChipDistribution ts_IndexChipDistribution.FPriceType
FPriceType module ts-backtesting FPriceType module/ts-backtesting.md fpricetype 成交价类别 3:日均价 field instance public tsBackTesting tsBackTesting.FPriceType
FPriceType module ts-backtesting FPriceType module/ts-backtesting.md fpricetype 成交价类别 -1:用户自定义;1:时点价格;2:收盘价;3:日均价;4:开盘价;5:系统昨收 field instance public tsBackTesting tsBackTesting.FPriceType
FpriceType module ts-multi-factor FpriceType module/ts-multi-factor.md fpricetype 成交价类别 2:收盘价 field instance public tsMultiFactor tsMultiFactor.FpriceType
FPrincDZ module ts-hg-risk-pca FPrincDZ module/ts-hg-risk-pca.md fprincdz 主成分对照 见 FPrincDZ 默认值 field instance public ts_HGRiskPCA ts_HGRiskPCA.FPrincDZ
FPurchaseRatio module fund-research FPurchaseRatio module/fund-research/fixed-amount-investment.md fpurchaseratio 申购费率,单位为百分比 field instance public ts_AIPBackTesting ts_AIPBackTesting.FPurchaseRatio
@@ -3229,7 +3231,7 @@ frameStocksMark_GetGrouptail module strategy-selection-tools frameStocksMark_Get
frameupdate dotnet base frameupdate(left, right, ons, type) dotnet/base/array.md frameupdate 数组 数据表 更新 缺失值 merge update table 按键字段用右表补充或更新左表中的缺失值,并直接修改左表 function frameupdate
framevaluecounts dotnet base framevaluecounts(data, countfieldname, iforder) dotnet/base/array.md framevaluecounts 数据表-计数 function framevaluecounts
FRateType module quick-back-testing FRateType module/quick-back-testing.md fratetype 比例类组合资金分配方式 4:等权重 field instance public quickBackTesting quickBackTesting.FRateType
FRateType module ts-backtesting FRateType module/ts-backtesting.md fratetype 比例类组合资金分配方式 4:等权重 field instance public tsBackTesting tsBackTesting.FRateType
FRateType module ts-backtesting FRateType module/ts-backtesting.md fratetype 比例类组合资金分配方式;-1:用户自定义比例;0/1/4/5/6/7 为系统配比;8:剩余资金等比例分配;默认 4:等权重 field instance public tsBackTesting tsBackTesting.FRateType
FRateType module ts-future-multifactor FRateType module/ts-future-multifactor.md fratetype 比例类型 4(等权) field instance public tsFutureMultiFactor tsFutureMultiFactor.FRateType
FRateType module ts-multi-factor FRateType module/ts-multi-factor.md fratetype 个股资金分配方法 4:等权重 field instance public tsMultiFactor tsMultiFactor.FRateType
FRatio module tinysoft-strategies FRatio module/tinysoft-strategies/market-cap-rotation.md fratio 买卖费率百分比,默认值为 0.1 field instance public tsLargeAndSmallTurning tsLargeAndSmallTurning.FRatio
Can't render this file because it is too large.