策略与回测
策略开发
starfish::facplfBasic::facplf_create_new_strategy(param)
详情
新建一个策略。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
strategy_name:必填,STRING,策略名称。
-
strategy_group:必填,STRING,策略类型股票:stock期货:futures期权:option债券:cfets_bond。
-
data_type:必填,INT,行情类型:0:逐笔+快照1:快照2:快照+成交3: 分钟频率4:日频。
-
msg_as_table:必填,BOOL,是否以表格形式接收消息。
-
tags:必填,STRING,策略标签。
-
comment:必填,STRING,策略备注。
返回值
一个字典,包含以下键值对:
-
id:策略 ID。
例子
starfish::facplfBasic::facplf_create_new_strategy({"strategy_name": "API_demo", "strategy_group": "stock", "data_type": 1, "msg_as_table": false, "tags": "", "comment": ""})
/* output:
id->"a3df58db-ab95-9f8c-e08b-3da51813457f"
*/
starfish::facplfBasic::facplf_save_strategy_code(param)
详情
编辑策略。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
id:必填,STRING,策略 id。
-
code:必填,DICT,策略代码。
-
initialize:STRING,策略初始化函数。
-
beforeTrading:STRING,策略盘前交易函数。
-
onTick:STRING,逐笔行情通知函数(高频)。
-
onBar:STRING,逐笔行情通知函数(低频)。
-
onSnapshot:STRING,快照行情通知函数。
-
onOrder:STRING,委托回报通知函数。
-
onTrade:STRING,成交回报通知函数。
-
afterTrading:STRING,策略每日盘后回调函数。
-
finalize:STRING,策略结束回调函数。
返回值
无。
例子
code = {
"initialize": "print('initialize')",
"beforeTrading": "print('before trading')",
"onTick": "",
"onBar": "",
"onSnapshot": "print('snapshot event')",
"onOrder": "",
"onTrade": "",
"afterTrading": "",
"finalize": ""
}
starfish::facplfBasic::facplf_save_strategy_code(dict(`id`code, ["a3df58db-ab95-9f8c-e08b-3da51813457f", code]))
starfish::facplfBasic::facplf_get_strategy_list()
详情
查看因子模块列表。
参数
无
返回值
一个字典,包含以下键值对:
-
total:整型,策略总数。
-
items:表,策略列表。包含以下字段:
字段名
类型
说明
id STRING 策略 id strategy_name STRING 策略名称 strategy_group STRING 策略类型 data_type STRING 行情类型 tags STRING 标签 comment STRING 备注 creator STRING 创建人 create_time TIMESTAMP 创建时间 update_time TIMESTAMP 更新时间 run_record_count INT 运行记录数 msg_as_table BOOL 数据格式
例子
starfish::facplfBasic::facplf_get_strategy_list()
/* output
total->1
items->
id strategy_name strategy_group data_type msg_as_table create_time update_time comment tags creator run_record_count
------------------------------------ --------------- -------------- ---------- ------------- ----------------------- ----------------------- -------- ----- ------- ----------------
9e6781be-2921-0c9b-c35c-6b9d7d048192 onBarCTAdemo stock 3 false 2024.08.14 10:36:45.561 2024.10.31 14:26:28.529 admin 64
*/
starfish::facplfBasic::facplf_get_backtest_detail(param)
详情
查看因子模块详情。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
id 必填,字符串,表示策略 ID。
返回值
一个字典,包含以下键值对:
-
run_record_count:INT,运行记录数。
-
code:DICT,策略回测代码,包括各回调函数。
-
tags:STRING,标签。
-
comment:STRING,备注。
-
msg_as_table:BOOL,数据格式。
-
data_type:INT,行情类型。
-
creator:STRING,创建人。
-
strategy_group:STRING,策略类型(股票、期货等)。
-
strategy_name:STRING,策略名称。
-
id:STRING,策略 ID。
例子
starfish::facplfBasic::facplf_get_backtest_detail({"id": "a3df58db-ab95-9f8c-e08b-3da51813457f"})
/* output:
run_record_count->0
code->{"initialize": "","beforeTrading": "","onTick": "","onBar": "","onSnapshot": "","onOrder": "","onTrade": "","afterTrading": "","finalize": ""}
tags->
comment->
msg_as_table->0
data_type->1
creator->admin
strategy_group->stock
strategy_name->API_demo1
id->a3df58db-ab95-9f8c-e08b-3da51813457f
*/
回测预设
starfish::facplfBasic::facplf_create_new_strategy(param)
详情
新建一个回测预设。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
name:必填,STRING,参数设置项的名称。
-
comment:选填,STRING,备注。
-
tags:选填,STRING,标签。
-
data_type:必填,INT,行情类型。
-
strategy_group:必填,STRING,策略类型(如股票、期货等)。
-
type:必填,STRING,预设类型(1:历史回测,2:实时回测)。
返回值
一个字典,包含以下键值对:
-
id:回测预设 ID。
例子
starfish::facplfBasic::facplf_create_strategy_setting({"name": "API_demo","strategy_group": "stock","data_type": 1,"type": 1,"tags": "","comment": ""})
/* output:
{"id": "9228ac2a-7de8-0903-e52b-013164c10fb6"}
*/
starfish::facplfBasic::facplf_edit_strategy_setting(param)
详情
编辑回测预设。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
id:必填,STRING,要编辑的回测预设的 id。
-
config:必填,string,回测预设参数,序列化后的字符串形式(可以为 StrategyRunParams 或 StreamingStrategyRunParams)。
-
tag:选填,STRING[],回测预设的标签。
-
comment:选填,STRING,回测预设的备注。
其中,StrategyRunParams 包含以下键值对:
-
vid:STRING,可视化模板。
-
date:Array<[startDate: STRING, endDate: STRING]>,回测时间。
-
cash:DOUBLE[],初始资金。
-
commission:DOUBLE[],手续费。
-
tax:DOUBLE[],印花税。
-
matchingMode:INT[],订单撮合模式。
-
benchmark:STRING[],基准,默认为 null。
-
frequency:INT[],频率,默认为 0。
-
latency:DOUBLE[],订单延时,默认 0。
-
orderBookMatchingRatio:DOUBLE[],行情订单薄的成交百分比。
-
matchingRatio:DOUBLE[],快照的区间成交百分比。
-
enableSubscriptionToTickQuotes:BOOL[],是否订阅逐笔行情。
-
outputQueuePosition:BOOL[],是否获取订单在行情中的位置。
-
symbolList:STRING[],标的选择。
-
msgPartition:BOOL[],是否分段传入行情数据。
-
configTables:DBInfo[],参数中的表格。
-
msgTables:DBInfo[],行情合成所需表格。
-
attribution:BOOL,绩效归因。
-
attribute_template:OBJECT (可选),绩效归因模板,包括 id, custom_params, vid。
-
custom_params:Record (可选),策略自定义参数。
StreamingStrategyRunParams 包含以下键值对:
-
date:[STRING, STRING],回测时间,格式为 ["开始时间", "结束时间"]。
-
cash:DOUBLE,初始资金。
-
commission:DOUBLE,手续费。
-
tax:DOUBLE,印花税。
-
matchingMode:DOUBLE,订单撮合模式。
-
benchmark:STRING,基准,默认为 null。
-
frequency:DOUBLE,频率,默认为 0。
-
latency:DOUBLE,订单延时,默认 0。
-
orderBookMatchingRatio:DOUBLE,行情订单薄的成交百分比。
-
matchingRatio:DOUBLE,快照的区间成交百分比。
-
enableSubscriptionToTickQuotes:BOOL,是否订阅逐笔行情。
-
outputQueuePosition:BOOL,是否获取订单在行情中的位置。
-
symbolList:STRING,标的选择。
-
configTables:DBInfo[],参数中的表格,与历史回测传参一致。
-
msgTables:DICT,行情合成所需表格,包含 `streamTableName` 字段。
-
tableName:STRING,数据源名称。
-
code:STRING,自定义 SQL 代码。
-
variable:STRING,自定义代码中使用的变量。
-
db:OBJECT,数据库信息,包含 database 和 table`字段。
-
mappings:Array<{source: STRING, target: STRING}>,列映射规则,包括计算列 source 和映射列 target。
返回值
无。
例子
starfish::facplfBasic::facplf_edit_strategy_setting({
"config": "{\"date\":[[\"2022.04.11\",\"2022.04.11\"]],\"cash\":[1000000],\"commission\":[0.00015],\"tax\":[0.001],\"matchingMode\":[],\"benchmark\":[],\"frequency\":[0],\"latency\":[],\"symbolList\":[],\"msgPartition\":[],\"orderBookMatchingRatio\":[],\"matchingRatio\":[],\"enableSubscriptionToTickQuotes\":[],\"outputQueuePosition\":[],\"configTables\":[{\"configure\":false},{\"configure\":false}],\"msgTables\":[{\"configure\":true,\"tableName\":\"snapshot\",\"mode\":\"code\",\"code\":\"colName=[\\\"symbol\\\",\\\"symbolSource\\\",\\\"timestamp\\\",\\\"lastPrice\\\",\\\"upLimitPrice\\\",\\\"downLimitPrice\\\",\\\"totalBidQty\\\",\\n\\t\\\"totalOfferQty\\\",\\\"bidPrice\\\",\\\"bidQty\\\",\\\"offerPrice\\\",\\\"offerQty\\\",\\\"signal\\\",\\\"prevClosePrice\\\"]\\ncolType= [\\\"STRING\\\",\\\"STRING\\\",\\\"TIMESTAMP\\\",\\\"DOUBLE\\\",\\\"DOUBLE\\\",\\\"DOUBLE\\\",\\\"LONG\\\",\\n\\t\\\"LONG\\\",\\\"DOUBLE[]\\\",\\\"LONG[]\\\",\\\"DOUBLE[]\\\",\\\"LONG[]\\\",\\\"DOUBLE[]\\\",\\\"DOUBLE\\\"]\\nmessageTable=table(10000000:0, colName, colType)\\n\\ninsert into messageTable values(\\\"000001.XSHE\\\",\\\"XSHE\\\",2022.04.11 10:10:00.000,7,15,5,10000,10000,arrayVector([10],[6.9, 6.8, 6.7, 6.6, 6.5, 6.4, 6.3, 6.2, 6.1,6.0]),arrayVector([10],[800,900,1000,1100,1200,1000,1000,1000,1000,1000]),arrayVector([10],[7.1,7.2,7.3,7.4,7.5,7.6,7.7,7.8,7.9,8.0]),arrayVector([10],[1000,1000,1000,1000,1000,1000,1000,1000,1000,1000]),,6.5)\\ninsert into messageTable values(\\\"000001.XSHE\\\",\\\"XSHE\\\",2022.04.11 10:10:03.000,7.5,15,5,10000,10000,arrayVector([10],[7.4, 6.8, 6.7, 6.6, 6.5, 6.4, 6.3, 6.2, 6.1,6.0]),arrayVector([10],[800,900,1000,1100,1200,1000,1000,1000,1000,1000]),arrayVector([10],[7.6,7.7,7.8,7.9,8.0,8.1,8.2,8.3,8.4,8.5]),arrayVector([10],[1000,1000,1000,1000,1000,1000,1000,1000,1000,1000]),,7)\\n\\nresult = messageTable\\n\"}]}",
"id": "9228ac2a-7de8-0903-e52b-013164c10fb6"
})
starfish::facplfBasic::facplf_get_strategy_setting_list()
详情
查看回测预设详情。
参数
无
返回值
一个字典,包含以下键值对:
-
total:整型,回测预设总数。
-
items:表,回测预设列表。包含以下字段:
字段名
类型
说明
id string 参数设置项的 ID name string 参数设置项名称 strategy_group string 策略类型(股票、期货等) data_type int 行情类型 create_time string 创建时间 update_time string 更新时间 comment string 备注 tags string 标签 creator string 创建人 type int 预设类型(历史或实时)
例子
starfish::facplfBasic::facplf_get_strategy_setting_list()
/* output:
total->1
items->
id name strategy_group data_type create_time update_time comment tags creator type
------------------------------------ -------- -------------- ----------- ----------------------- ----------------------- ------- ---- ------- ----
9228ac2a-7de8-0903-e52b-013164c10fb6 API_demo stock 1 2024.10.23 14:09:00.027 2024.11.04 15:37:45.312 admin 1
*/
starfish::facplfBasic::facplf_get_strategy_setting_detail(param)
详情
查看回测预设详情。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
id 必填,字符串,表示回测预设 ID。
返回值
一个字典,包含以下键值对:
-
creator:STRING,创建人。
-
type:INT,预设类型。
-
tags:STRING,标签。
-
comment:STRING,备注。
-
config:DICT,参数配置。
-
strategy_group:STRING,策略类型。
-
data_type:INT,行情类型。
-
name:STRING,名称。
-
id:STRING,参数设置 ID。
例子
starfish::facplfBasic::facplf_get_strategy_setting_detail({"id": "71050a05-ee0a-f79d-ee65-a4cf8f6f6268"})
/* output:
creator->"admin"
type->1
tags->""
comment->""
config->{"date":[["2022.04.11","2022.04.11"]],"cash":[1000000],"commission":[0.00015],"tax":[0.001],"match…
strategy_group->"stock"
data_type->1
name->"API_demo"
id->9228ac2a-7de8-0903-e52b-013164c10fb6
*/
运行策略
starfish::facplfRun::facplf_run_backtest(param)
详情
运行历史回测。在使用前,需要先运行 use starfish::facplfRun
。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
id:必填,STRING,策略 id。
-
type:必填,INT,策略类型,0 为私有,1 为公开。
-
config:必填,DICT,策略运行参数,格式参照
starfish::facplfBasic::facplf_edit_strategy_setting
的 StrategyRunParams。
返回值
一个字典,包含以下键值对:
-
id:历史回测运行结果 ID。
例子
starfish::facplfRun::facplf_run_backtest({
"id": "f2059d7b-e809-8fa0-21a0-7919a3a4b0d5",
"type": 0,
"config": {
"date": [["2022-04-11", "2022-04-11"]],
"cash": [1000000],
"commission": [0.00015],
"tax": [0.001],
"matchingMode": [],
"benchmark": [],
"frequency": [0],
"latency": [],
"symbolList": [],
"msgPartition": [],
"orderBookMatchingRatio": [],
"matchingRatio": [],
"enableSubscriptionToTickQuotes": [],
"outputQueuePosition": [],
"configTables": [{"configure": false}],
"msgTables": [{"configure": true, "tableName": "snapshot", "mode": "code", "code": "//..."}],
"attribution": false
})
/* output:
id->"eaafd1e4-242c-d648-e40a-c226e8752207"
*/
starfish::facplfRun::facplf_get_backtest_result(param)
详情
查看回测运行详情。在使用前,需要先运行 use starfish::facplfRun
。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
id:必填,STRING,回测任务的 id。
-
backtest_type:必填,STRING,回测类型,1 表示历史回测,2 表示实时回测。
返回值
-
progress:STRING,运行进度,仅历史回测提供。
-
strategy_id:STRING,策略 ID。
-
strategy_group:STRING,策略类型。
-
strategy_name:STRING,策略名称。
-
vid:STRING,可视化模板 id。
-
data_type:INT,行情类型。
-
config:DICT,运行参数
-
time:STRING,运行开始时间。
-
jobs:TABLE,包含子任务详情的数组。
-
id:STRING,回测任务的 ID。
-
status:INT,回测状态。
例子
starfish::facplfRun::facplf_get_backtest_result({
"id": "eaafd1e4-242c-d648-e40a-c226e8752207",
"backtest_type": 1
})
/* output:
progress->"1/1"
strategy_id->f2059d7b-e809-8fa0-21a0-7919a3a4b0d5
strategy_group->"stock"
strategy_name->"API_demo"
vid->""
data_type->1
config->'{"date": [["2022.04.11","2022.04.11"]],"cash": [1000000],"commission": [0.00015],"tax": [0.001],"matchingMode": [],"benchmark": [],"frequency": [0],"latency": [],"symbolList": [],"msgPartition": [],"orderBookMatchingRatio": [],"matchingRatio": [],"enableSubscriptionToTickQuotes": [],"outputQueuePosition": [],"configTables": [{"configure": false},{"configure": false}],"msgTables": [{"configure": true,"tableName": "snapshot","mode": "code","code": "colName=[\"symbol\",\"symbolSource\",\"timestamp\",\"lastPrice\",\"upLimitPrice\",\"downLimitPrice\",\"totalBidQty\",\n\t\"totalOfferQty\",\"bidPrice\",\"bidQty\",\"offerPrice\",\"offerQty\",\"signal\",\"prevClosePrice\"]\ncolType= [\"STRING\",\"STRING\",\"TIMESTAMP\",\"DOUBLE\",\"DOUBLE\",\"DOUBLE\",\"LONG\",\n\t\"LONG\",\"DOUBLE[]\",\"LONG[]\",\"DOUBLE[]\",\"LONG[]\",\"DOUBLE[]\",\"DOUBLE\"]\nmessageTable=table(10000000:0, colName, colType)\n\ninsert into messageTable values(\"000001.XSHE\",\"XSHE\",2022.04.11 10:10:00.000,7,15,5,10000,10000,arrayVector([10],[6.9, 6.8, 6.7, 6.6, 6.5, 6.4, 6.3, 6.2, 6.1,6.0]),arrayVector([10],[800,900,1000,1100,1200,1000,1000,1000,1000,1000]),arrayVector([10],[7.1,7.2,7.3,7.4,7.5,7.6,7.7,7.8,7.9,8.0]),arrayVector([10],[1000,1000,1000,1000,1000,1000,1000,1000,1000,1000]),,6.5)\ninsert into messageTable values(\"000001.XSHE\",\"XSHE\",2022.04.11 10:10:03.000,7.5,15,5,10000,10000,arrayVector([10],[7.4, 6.8, 6.7, 6.6, 6.5, 6.4, 6.3, 6.2, 6.1,6.0]),arrayVector([10],[800,900,1000,1100,1200,1000,1000,1000,1000,1000]),arrayVector([10],[7.6,7.7,7.8,7.9,8.0,8.1,8.2,8.3,8.4,8.5]),arrayVector([10],[1000,1000,1000,1000,1000,1000,1000,1000,1000,1000]),,7)\n\nresult = messageTable\n"}]}'
time->2024.10.22 16:44:30.960
jobs->
job_id name status error_msg run_time backtest_time node attribution_job_id attribution_status
-------------------------------------------- ---------- ------- --------- --------- ------------- ---------- ------------------ ------------------
admin_eaafd1e4_242c_d648_e40a_c226e8752207_1 API_demo_1 1 1.626 0.002 single7301
id->eaafd1e4-242c-d648-e40a-c226e8752207
status->1
*/
starfish::facplfBasic::facplf_get_single_backtest_result(param)
详情
查看单个历史回测运行子任务运行结果。
param:字典,键的类型为字符串。包含以下键值对:
-
id:必填,STRING,回测任务的 ID。
-
backtest_type:必填,INT,回测类型,1 表示历史回测,2 表示实时回测。
返回值
一个字典,包含以下键值对:
-
result:DICT,回测结果详情。
-
job_id:STRING,回测运行结果 id。
-
time:STRING,回测运行时间。
-
strategy_id:STRING,策略 id。
-
getAvailableCash:DOUBLE,可用资金。
-
strategy_group:STRING,策略类型。
-
data_type:INT,行情类型。
-
strategy_name:STRING,策略名称。
-
name:STRING,任务名称。
-
config:STRING,运行参数。
-
id:UUID,策略 id。
-
status:INT,运行状态。
其中,result 包含如下键值对:
-
indicator_onSnapshot:TABLE,订阅指标结果。
-
getPosition:TABLE,持仓信息。
-
getTradeDetails:TABLE,交易明细表。
-
getTodayPnl:TABLE,当日收益。
-
getDailyPosition:TABLE,每日持仓数据详情。
-
getDailyTotalPortfolios:TABLE,策略每日权益指标。
-
getReturnSummary:TABLE,回测结果综合。
例子
starfish::facplfBasic::facplf_get_single_backtest_result({
"job_id": "job_98765"
})
/* output:
{
"job_id": "job_98765",
"time": "2024-10-31T10:00:00.000",
"name": "Strategy_1",
"strategy_id": "strategy_12345",
"getAvailableCash": 985297.5,
"strategy_name": "API_demo",
"data_type": "snapshot",
"strategy_group": "stock",
"config": {
"date": [["2024-01-01", "2024-01-31"]],
"cash": [1000000],
"commission": [0.00015],
"tax": [0.001]
// 其他参数省略...
},
"status": 1,
// result 省略部分结果
"result": {
"getReturnSummary": [{"totalReturn": 0.1, "annualReturn": 0.12}],
"getTradeDetails": {
"items": [{"orderId": 1, "symbol": "000001.XSHE", "tradePrice": 10.5}],
"total": 1
},
"getDailyPosition": {
"items": [{"symbol": "000001.XSHE", "longPosition": 100}],
"total": 1
},
"getDailyTotalPortfolios": {
"items": [{"tradeDate": "2024-01-02", "totalEquity": 1000500}],
"total": 30
},
"getTodayPnl": {"items": [{"symbol": "000001.XSHE", "pnl": 500}], "total": 1},
"getPosition": {"items": [{"symbol": "000001.XSHE", "longPosition": 100}], "total": 1}
}
}
*/
starfish::facplfRun::facplf_run_real_time_backtest(param)
详情
运行实时回测。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
id:必填,STRING,策略 id。
-
type:必填,INT,策略类型,0 为私有,1 为公开。
-
config:必填,DICT,实时回测参数设置,格式参照
starfish::facplfBasic::facplf_edit_strategy_setting
的 StreamingStrategyRunParams。
返回值
一个字典,包含以下键值对:
-
id:STRING,实时回测运行结果 ID。
例子
starfish::facplfRun::facplf_run_real_time_backtest({
"id": "39cd8c97-4a2d-13ab-da23-4f4450e6b4aa",
"type": 0,
"run_params": {
"date": ["2023-01-31", "2023-02-03"],
"cash": 10000000,
"commission": 1.5,
"tax": 0.0,
"frequency": 0,
"latency": 5,
"orderBookMatchingRatio": 0.8,
"matchingRatio": 0.6,
"symbolList": ["000001.XSHE"],
"msgTables": {"streamTableName": "testData"},
"configTables": [{
"tableName": "basicInfo",
"mode": "code",
"code": "select * from loadTable(\"dfs://Backtest\", \"future_minData\")"
}]
})
/* output:
id->"eaafd1e4-242c-d648-e40a-c226e8752207"
*/
starfish::facplfBasic::facplf_get_real_time_backtest_stream_tbs(param)
详情
查看实时回测流表名称。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
job_id:必填,STRING,实时回测任务的运行 ID。
返回值
一个字典,包含以下键值对:
-
daily_position:STRING,持仓详情流表名称。
-
open_order:STRING,当前的未成交(未完成)订单列表。
-
daily_portfolios:STRING,账户详情(收益详情)流表。
-
total_portfolios:STRING,日组合指标展示。
-
trade_detail:STRING,订单详情流表名称。
-
position:STRING,当日持仓。
-
indicator:STRING,订阅指标结果。
-
market:STRING,交易分析流表名称。
-
summary:STRING,收益概述。
例子
starfish::facplfBasic::facplf_get_real_time_backtest_stream_tbs({
"job_id": [
"14afe87e-bc0c-e6f9-7f81-d0e6cbbb2cd8"
]
})
/* output:
daily_position->"Backtest_admin2024_10_31T18_11_41_817_DailyPosition"
open_order->"Backtest_admin2024_10_31T18_11_41_817_OpenOrder"
daily_portfolios->"Backtest_admin2024_10_31T18_11_41_817_DailyPortfolios"
total_portfolios->"Backtest_admin2024_10_31T18_11_41_817_TotalPortfolios"
trade_detail->"Backtest_admin2024_10_31T18_11_41_817_TradeDetail"
position->"Backtest_admin2024_10_31T18_11_41_817_Position"
indicator->"Backtest_admin2024_10_31T18_11_41_817_Indicator"
market->"testData"
summary->"Backtest_admin2024_10_31T18_11_41_817_ReturnSummary"
*/
绩效归因
starfish::facplfBasic::facplf_create_new_attribution_template(param)
详情
新建一个绩效归因模板。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
name:必填,STRING,绩效归因模板的名称。
-
tags:选填,STRING,绩效归因模板的标签,多个标签可以用逗号分隔。
-
comment:选填,STRING,绩效归因模板的备注。
返回值
一个字典,包含以下键值对:
-
template_id:绩效归因模板的唯一 ID。
例子
starfish::facplfBasic::facplf_create_new_attribution_template({
"name": "API_demo",
"tags": "",
"comment": ""
})
/* output:
template_id->"e0fc2ce3-4c59-cf3f-78ae-e1ce4bf55620"
*/
starfish::facplfBasic::facplf_edit_attribution_template(param)
详情
编辑绩效归因模板。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
template_id:必填,STRING,模板 id。
-
name:选填,STRING,模板名称。
-
tags:选填,STRING,标签。
-
comment:选填,STRING,备注。
-
code:选填,STRING,自定义代码。
-
custom_params:必填,DICT[],自定义参数列表,包含如下键值对:
-
name:STRING,参数名称。
-
control_type:STRING,参数控制类型,可为
-
date 日期
-
text 文本
-
number 数字
-
select 布尔选择器
-
run_record_select 策略结果选择器
-
-
value:STRING,参数值。
-
返回值
无。
例子
starfish::facplfBasic::facplf_edit_attribution_template({
"template_id": "8a5bedbe-b9e5-338d-9989-ee477a1cb72e",
"name": "Updated_API_demo",
"tags": "updated_performance",
"comment": "Updated example attribution template",
"code": "return backtestResult",
"custom_params": [
{
"name": "backtestResult",
"control_type": "run_record_select",
"value": "admin_979e2854_e0ce_e6bb_a4e0_17fc8d034cee_1"
}
]
})
starfish::facplfBasic::facplf_attribution_template_list()
详情
获取绩效归因模板列表。
参数
无。
返回值
一个字典,包含以下键值对:
-
total:INT,绩效归因模板总数。
-
items:表,绩效归因模板列表。
字段名 |
类型 |
说明 |
---|---|---|
template_id | UUID | 绩效归因模板的唯一 id |
name | STRING | 绩效归因模板的名称 |
tags | STRING | 绩效归因模板的标签,多个标签之间用逗号分隔 |
is_custom | STRING | 是否为自定义模板 |
create_time | TIMESTAMP | 绩效归因模板的创建时间 |
update_time | TIMESTAMP | 绩效归因模板的创建时间 |
creator | STRING | 创建绩效归因模板的用户名称 |
comment | STRING | 绩效归因模板的备注 |
custom_params | STRING | 绩效归因模板的参数 |
run_record_count | INT | 绩效归因模板的运行次数 |
source_code | BLOB | 绩效归因模板的实际代码 |
例子
starfish::facplfBasic::facplf_attribution_template_list()
/* output:
total->1
items->
template_id name tags is_custom create_time update_time creator comment custom_params run_record_count
------------------------------------ ------- ----- ---------- ----------------------- ----------------------- --------- -------------- ---------------------------------------------------------------------------------------------------------- ----------------
00000000-0000-0000-0011-000000000001 Brinson false 2024.10.21 00:00:00.000 2024.10.21 00:00:00.000 DolphinDB Brinson内置模板 [{"name": "backtestResult","control_type": "strategy_run_record_select","value": ""},{"name": "method",... 13
*/
starfish::facplfBasic::facplf_attribution_template_detail(param)
详情
查看绩效归因模板详情。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
template_id:必填,STRING,绩效归因模板 id。
返回值
一个字典,包含以下键值对:
-
template_id:UUID,绩效归因模板 id。
-
name:STRING,绩效归因模板名称。
-
tags:STRING,标签。
-
create_time:STRING,创建时间。
-
update_time:STRING,更新时间。
-
creator:STRING,创建人。
-
comment:STRING,备注。
-
custom_params:STRING,自定义参数列表,详见
starfish::facplfBasic::facplf_edit_attribution_template
中的解释。 -
code:BLOB,绩效归因模板代码。
例子
starfish::facplfBasic::facplf_attribution_template_detail({
"template_id": "e0fc2ce3-4c59-cf3f-78ae-e1ce4bf55620"
})
// output:
template_id->e0fc2ce3-4c59-cf3f-78ae-e1ce4bf55620
name->'API_demo'
tags->'portfolio'
create_time->2024.11.01 09:42:53.857
update_time->2024.11.01 11:12:20.459
creator->'admin'
comment->''
custom_params->'[{"idx": 0,"name": "backtestResult","control_type": "strategy_run_record_select","value": "admin_979e2854_e0ce_e6bb_a4e0_17fc8d034cee_1"},{"idx": 1,"name": "start_date","control_type": "date","value": "2023.10.01"},{"idx": 2,"name": "end_date","control_type": "date","value": "2024.10.01"}]'
code->res = select * from backtestResult.getDailyTotalPortfolios where tradeDate between start_date…
*/
starfish::facplfRun::facplf_run_attribution(param)
详情
运行绩效归因模板。在使用前,需要先运行 use starfish::facplfRun
。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
template_id:必填,STRING,绩效归因模板的 ID。
-
custom_params:必填,STRING,自定义参数列表,包含控制类型和对应的值。
返回值
一个字典,包含以下键值对:
-
attribution_job_id:STRING,绩效归因模板的运行作业 ID。
例子
starfish::facplfRun::facplf_run_attribution({
"template_id": "8a5bedbe-b9e5-338d-9989-ee477a1cb72e",
"vid": "vis_template_1234",
"custom_params": [
{
"name": "backtestResult",
"control_type": "run_record_select",
"value": "admin_979e2854_e0ce_e6bb_a4e0_17fc8d034cee_1"
}
]
})
/* output:
attribution_job_id->"b9f3dcee-a9e5-338d-9989-ee477a1cb91e"
*/
starfish::facplfBasic::facplf_get_attribution_record_detail(param)
详情
查看绩效归因模板的运行结果。
参数
param:字典,键的类型为字符串。包含以下键值对:
-
attribution_job_id:必填,STRING,绩效归因模板的运行作业 ID。
返回值
一个字典,包含以下键值对:
-
result:DICT,任务结果,每个键对应一个结果项。
-
custom_params:STRING,绩效归因模板的运行参数。
-
vid:STRING,可视化模板 ID,用于展示结果。
-
creator:STRING,任务创建者。
-
status:INT,任务状态。
-
attribution_template_id:UUID,绩效归因模板 ID。
-
attribution_template_name:STRING,绩效归因模板名称。
-
create_time:TIMESTAMP,任务创建时间。
-
attribution_job_id:STRING,绩效归因任务的 ID。
-
failed_reason:STRING,失败原因(如果任务失败则返回原因描述)。
例子
starfish::facplfBasic::facplf_get_attribution_record_detail({
"attribution_job_id": "facplf_7f5e2f8b_f163_9e1a_fd41_da122bb636c1"
})
/* output:
result->
daily_portfolio->
tradeDate cash totalMarketValue totalEquity netValue totalReturn ratio pnl
---------- ----------- ---------------- ------------- ----------- --------------------- --------------------- -----------------
2022.04.11 985,297.795 15,000 1,000,297.795 1.000297795 0.0002977950000000451 0.0002977950000000451 297.7950000000419
custom_params->'[{"idx": 0,"name": "backtestResult","control_type": "strategy_run_record_select","value": "admin_979e2854_e0ce_e6bb_a4e0_17fc8d034cee_1"},{"idx": 1,"name": "start_date","control_type": "date","value": "2020.06.01"},{"idx": 2,"name": "end_date","control_type": "date","value": "2024.10.28"}]'
vid->null
creator->'admin'
status->1
attribution_template_id->e0fc2ce3-4c59-cf3f-78ae-e1ce4bf55620
attribution_template_name->'API_demo'
create_time->2024.11.01 11:25:55.073
attribution_job_id->'facplf_7f5e2f8b_f163_9e1a_fd41_da122bb636c1'
*/