@dshtrading/kit-us 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,75 @@
1
+ Copyright (c) 2026 zhu1090093659 (dsh-trading)
2
+
3
+ # PolyForm Noncommercial License 1.0.0
4
+
5
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
6
+
7
+ ## Acceptance
8
+
9
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
14
+
15
+ ## Distribution License
16
+
17
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
18
+
19
+ ## Notices
20
+
21
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
22
+
23
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
24
+
25
+ ## Changes and New Works License
26
+
27
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
28
+
29
+ ## Patent License
30
+
31
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
32
+
33
+ ## Noncommercial Purposes
34
+
35
+ Any noncommercial purpose is a permitted purpose.
36
+
37
+ ## Personal Uses
38
+
39
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
40
+
41
+ ## Noncommercial Organizations
42
+
43
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
44
+
45
+ ## Fair Use
46
+
47
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
48
+
49
+ ## No Other Rights
50
+
51
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
52
+
53
+ ## Patent Defense
54
+
55
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
56
+
57
+ ## Violations
58
+
59
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
60
+
61
+ ## No Liability
62
+
63
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
64
+
65
+ ## Definitions
66
+
67
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
68
+
69
+ **You** refers to the individual or entity agreeing to these terms.
70
+
71
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
72
+
73
+ **Your licenses** are all the licenses granted to you for the software under these terms.
74
+
75
+ **Use** means anything you do with the software requiring one of your licenses.
@@ -0,0 +1,218 @@
1
+ # 指标创作指南(Indicator Authoring Guide)
2
+
3
+ 当用户在会话列中用自然语言提出编写或添加技术指标的需求时(例如:"帮我写一个 TD9 指标"、"帮我写一个 SuperTrend 指标"、"给 OBV 加一个 34 天均线"),请遵循本指南生成符合 `@dshtrading/indicators` 契约规范的 JavaScript 纯函数代码,并调用 `indicator_author` 工具进行沙箱校验与落库。
4
+
5
+ ---
6
+
7
+ ## 1. 核心契约与计算模型
8
+
9
+ 技术指标是纯数据与纯函数的契约对象:
10
+
11
+ ```typescript
12
+ export interface IndicatorDefinition {
13
+ id: string // 唯一 ID,如 "td9"、"supertrend"、"custom_rsi"(小写字母数字下划线,2-32 字符)
14
+ title: string // 显示名称,如 "TD9"、"SuperTrend"(1-32 字符)
15
+ pane: 'main' | 'sub' // 归属:"main" 主图叠加 或 "sub" 独立副图
16
+ params: IndicatorParamSpec[] // 参数列表配置(0-8 个)
17
+ compute(bars: readonly Kline[], params: Record<string, number>): IndicatorOutput[]
18
+ }
19
+ ```
20
+
21
+ ### 输入 `bars`(K 线数组)
22
+ 每根 K 线包含:
23
+ - `openTime`: number(毫秒时间戳)
24
+ - `open`: number(开盘价)
25
+ - `high`: number(最高价)
26
+ - `low`: number(最低价)
27
+ - `close`: number(收盘价)
28
+ - `volume`: number(成交量)
29
+
30
+ ### 输出 `IndicatorOutput[]`(序列数组)
31
+ 每个输出序列包含:
32
+ - `key`: string(系列名称,如 `'TD_BUY'`、`'SUPERTREND'`、`'OBV_MA'`)
33
+ - `kind`: `'line'` | `'histogram'`
34
+ - `color`: string(如 `'#e64545'`(涨红)、`'#2ba471'`(跌绿)、`'#3b82f6'`(蓝)、`'#e6a23c'`(橙))
35
+ - `values`: `Array<number | undefined>`
36
+ - `histogramBySign`?: boolean(柱状图专用:为 true 时正值着红、负值着绿)
37
+
38
+ ---
39
+
40
+ ## 2. 编写黄金铁律(必须遵守)
41
+
42
+ 1. **长度严格对齐**:`output.values.length` **必须严格等于** `bars.length`!
43
+ 2. **warm-up 必须用 `undefined`**:历史数据不足以计算的前 N 根 K 线,对应位置的值必须填 `undefined`,图表引擎会自动将其作为未准备就绪点跳过渲染。
44
+ 3. **数值必须有限(Finite)**:严禁在 `values` 中出现 `NaN`、`Infinity`、`null` 或字符串。除法操作必须做防除零保护(如 `denominator === 0 ? 0 : numerator / denominator`)。
45
+ 4. **纯函数与零副作用**:`compute` 必须是无状态的纯函数,不得访问 `window`、`document` 或外部全局可变状态。
46
+ 5. **红涨绿跌 Token 约定**:中国市场规范下,多头/上涨/买点使用红色系(如 `#e64545`),空头/下跌/卖点使用绿色系(如 `#2ba471`)。
47
+
48
+ ---
49
+
50
+ ## 3. 三大富途牛牛同款生产级范例
51
+
52
+ ### 范例一:TD9(汤姆·狄马克九转序列,主图叠加)
53
+
54
+ 连续 9 根收盘价低于 4 根前收盘价触发买入九转(看多转折),连续 9 根高于 4 根前触发卖出九转。
55
+
56
+ ```javascript
57
+ (bars) => {
58
+ const len = bars.length;
59
+ const buySetup = new Array(len).fill(undefined);
60
+ const sellSetup = new Array(len).fill(undefined);
61
+ let buyCount = 0;
62
+ let sellCount = 0;
63
+
64
+ for (let i = 0; i < len; i++) {
65
+ if (i < 4) continue;
66
+ const currentClose = bars[i].close;
67
+ const close4Ago = bars[i - 4].close;
68
+
69
+ if (currentClose < close4Ago) {
70
+ buyCount += 1;
71
+ sellCount = 0;
72
+ buySetup[i] = buyCount;
73
+ } else if (currentClose > close4Ago) {
74
+ sellCount += 1;
75
+ buyCount = 0;
76
+ sellSetup[i] = sellCount;
77
+ } else {
78
+ buyCount = 0;
79
+ sellCount = 0;
80
+ }
81
+ }
82
+
83
+ return [
84
+ { key: 'TD_BUY', kind: 'line', color: '#2ba471', values: buySetup },
85
+ { key: 'TD_SELL', kind: 'line', color: '#e64545', values: sellSetup },
86
+ ];
87
+ }
88
+ ```
89
+
90
+ ---
91
+
92
+ ### 范例二:SuperTrend(超级趋势指标,主图叠加)
93
+
94
+ 基于 ATR 与倍数构建的动态趋势跟踪通道与止损线。
95
+
96
+ ```javascript
97
+ (bars, params) => {
98
+ const period = Math.max(1, Math.round(params.period ?? 10));
99
+ const multiplier = Number(params.multiplier ?? 3);
100
+ const len = bars.length;
101
+
102
+ const upperBand = new Array(len).fill(undefined);
103
+ const lowerBand = new Array(len).fill(undefined);
104
+ const supertrend = new Array(len).fill(undefined);
105
+
106
+ // 1. 计算 True Range
107
+ const tr = new Array(len);
108
+ tr[0] = bars[0].high - bars[0].low;
109
+ for (let i = 1; i < len; i++) {
110
+ const hl = bars[i].high - bars[i].low;
111
+ const hc = Math.abs(bars[i].high - bars[i - 1].close);
112
+ const lc = Math.abs(bars[i].low - bars[i - 1].close);
113
+ tr[i] = Math.max(hl, hc, lc);
114
+ }
115
+
116
+ // 2. 计算 ATR 与 SuperTrend 轨迹
117
+ let atrSum = 0;
118
+ let trend = 1;
119
+
120
+ for (let i = 0; i < len; i++) {
121
+ atrSum += tr[i];
122
+ if (i >= period) atrSum -= tr[i - period];
123
+
124
+ if (i < period - 1) continue;
125
+
126
+ const currentAtr = atrSum / period;
127
+ const hl2 = (bars[i].high + bars[i].low) / 2;
128
+ let basicUpper = hl2 + multiplier * currentAtr;
129
+ let basicLower = hl2 - multiplier * currentAtr;
130
+
131
+ if (i > 0 && lowerBand[i - 1] !== undefined) {
132
+ if (basicLower < lowerBand[i - 1] && bars[i - 1].close > lowerBand[i - 1]) {
133
+ basicLower = lowerBand[i - 1];
134
+ }
135
+ }
136
+ if (i > 0 && upperBand[i - 1] !== undefined) {
137
+ if (basicUpper > upperBand[i - 1] && bars[i - 1].close < upperBand[i - 1]) {
138
+ basicUpper = upperBand[i - 1];
139
+ }
140
+ }
141
+
142
+ lowerBand[i] = basicLower;
143
+ upperBand[i] = basicUpper;
144
+
145
+ if (i > 0 && supertrend[i - 1] !== undefined) {
146
+ if (trend === 1 && bars[i].close < lowerBand[i]) {
147
+ trend = -1;
148
+ } else if (trend === -1 && bars[i].close > upperBand[i]) {
149
+ trend = 1;
150
+ }
151
+ }
152
+
153
+ supertrend[i] = trend === 1 ? lowerBand[i] : upperBand[i];
154
+ }
155
+
156
+ return [
157
+ { key: 'SUPERTREND', kind: 'line', color: '#3b82f6', values: supertrend }
158
+ ];
159
+ }
160
+ ```
161
+
162
+ ---
163
+
164
+ ### 范例三:OBV + MA34(能量潮 + 34 天均线,副图指标)
165
+
166
+ 量价配合指标,结合累积成交量与平滑均线研判多空力量。
167
+
168
+ ```javascript
169
+ (bars, params) => {
170
+ const maPeriod = Math.max(1, Math.round(params.period ?? 34));
171
+ const len = bars.length;
172
+ const obv = new Array(len);
173
+ const obvMa = new Array(len).fill(undefined);
174
+
175
+ obv[0] = 0;
176
+ for (let i = 1; i < len; i++) {
177
+ if (bars[i].close > bars[i - 1].close) {
178
+ obv[i] = obv[i - 1] + bars[i].volume;
179
+ } else if (bars[i].close < bars[i - 1].close) {
180
+ obv[i] = obv[i - 1] - bars[i].volume;
181
+ } else {
182
+ obv[i] = obv[i - 1];
183
+ }
184
+ }
185
+
186
+ let sum = 0;
187
+ for (let i = 0; i < len; i++) {
188
+ sum += obv[i];
189
+ if (i >= maPeriod) sum -= obv[i - maPeriod];
190
+ if (i >= maPeriod - 1) {
191
+ obvMa[i] = sum / maPeriod;
192
+ }
193
+ }
194
+
195
+ return [
196
+ { key: 'OBV', kind: 'line', color: '#e6a23c', values: obv },
197
+ { key: 'OBV_MA', kind: 'line', color: '#409eff', values: obvMa },
198
+ ];
199
+ }
200
+ ```
201
+
202
+ ---
203
+
204
+ ## 4. 工具调用范式
205
+
206
+ 生成代码后,直接调用 `indicator_author` 工具:
207
+
208
+ ```json
209
+ {
210
+ "id": "td9",
211
+ "title": "TD9",
212
+ "pane": "main",
213
+ "computeSource": "(bars) => { ... }",
214
+ "description": "汤姆狄马克九转序列指标"
215
+ }
216
+ ```
217
+
218
+ 若工具返回 `Validation failed`,请根据返回的具体报错信息调整代码(如修复长度不对齐、NaN 防护等)后重新尝试,直至落库成功。
@@ -0,0 +1,98 @@
1
+ ---
2
+ name: knowledge-curation
3
+ description: 财经观点沉淀与知识库策展指南:基于 Content Insight 事实核查产物,规范化提取知识卡片字段、受控词表对齐、查重与关联建立,通过 knowledge_ingest 工具入库。
4
+ ---
5
+
6
+ # 财经观点沉淀与知识库策展指南(knowledge-curation)
7
+
8
+ 本技能指导 Agent 将经过事实核查的财经视频(B站)或深度文章(微信公众号)观点,转化为结构化知识卡片并录入本地个人知识库,以力导图谱形式沉淀为可复用的交易研究资产。
9
+
10
+ ---
11
+
12
+ ## 1. 目标与范围
13
+
14
+ ### 什么时候执行入库
15
+ - **显式触发**:用户在对话中明确要求「沉淀/入库/收藏/记录到知识库/保存这张卡片」;
16
+ - **主动建议**:当 Agent 运用 `content-insight` 技能完成了一次高质量的视频或文章深度分析并产出事实核查报告后,在回答末尾主动向用户建议:「是否需要将本篇核心观点与核查结论沉淀到知识库?」。用户确认后即可调用工具入库。
17
+
18
+ ### 什么时候不入库
19
+ - 用户仅询问「这个视频讲了什么」或「帮我快速总结一下」,未表达沉淀意向;
20
+ - 素材属于纯情绪宣泄、无实质逻辑链条或事实核查评级为不可信(无有效干货)。
21
+
22
+ ---
23
+
24
+ ## 2. 前置依赖(严格核查原则)
25
+
26
+ **无核查,不入库**:
27
+ - 严禁未经 `content-insight` 事实核查直接录入原始观点;
28
+ - 卡片的 `credibility`(内容可信度)评级必须严格基于事实核查三桶(✅ 证实 / ⚠️ 有出入 / ❓ 无法核实)的综合结论定级:
29
+ - `high`:核心事实与数据均有权威源证实,推理链条严密;
30
+ - `medium`:核心逻辑有参考价值,但部分数据存在滞后或口误出入;
31
+ - `low`:存在重大关键事实失准或关键数据无法核实。
32
+
33
+ ---
34
+
35
+ ## 3. 标准策展 SOP
36
+
37
+ ### 第一步:提取卡片结构化字段
38
+ 根据 `content-insight` 产出的分析报告,提炼以下标准字段:
39
+ - `title`:卡片主题(精炼概括核心逻辑,如「高股息资产在低利率环境下的防御逻辑」);
40
+ - `summary`:合并 2-4 条核心论点的一句话概述(图谱 hover 提示文案);
41
+ - `source`:`type`(bilibili / wechat / manual)、`url`、`author`、`publishedAt`;
42
+ - `credibility`:`high` / `medium` / `low`;
43
+ - `coreClaims`:核心论点列表(保留原作者的推理链条,避免断章取义);
44
+ - `factCheck`:`{ verified: [...], discrepancies: [...], unverifiable: [...] }`;
45
+ - `takeaways`:提炼出的可复用通用分析框架或方法论;
46
+ - `boundaries`:原作者论点的适用边界、失效情景与潜在陷阱;
47
+ - `tags`:受控主题标签列表(见下文标准词表);
48
+ - `tickers`:可选关联标的代码(市场规范词汇,如 `BTCUSDT`、`600519.SH`、`AAPL`)。
49
+
50
+ ### 第二步:对齐受控主题词表(Controlled Vocabulary)
51
+ 为确保力导图谱能够准确聚合主题簇,标签优先在受控词表中选取(单张卡片 2-4 个标签为宜):
52
+ - **宏观与政策**:`宏观`、`货币政策`、`财政政策`、`通胀`、`利率`、`流动性`
53
+ - **策略与风格**:`高股息`、`红利策略`、`成长股`、`价值投资`、`周期`、`动量`、`均值回归`
54
+ - **行业与赛道**:`半导体`、`消费`、`金融`、`大宗商品`、`新能源`、`加密资产`、`AI算力`
55
+ - **风控与心智**:`仓位管理`、`止损纪律`、`认知偏差`、`周期拐点`、`黑天鹅防范`
56
+
57
+ > *注:如需引入词表外的新标签,需向用户说明该标签的分类理由。*
58
+
59
+ ### 第三步:查重与关联发现
60
+ 1. 调用 `knowledge_search`:
61
+ - 先以 `sourceUrl` 或核心关键词检索,检查是否已有同源或同主题卡片;
62
+ - 查看检索到的已有卡片,寻找是否存在论点呼应、正反对比或同类经验的卡片 ID;
63
+ 2. 构造 `related` 数组:将发现的有价值关联卡片 ID(如 `kc_01j...`)填入 `related` 字段,以在图谱中建立显式关联连线。
64
+
65
+ ### 第四步:调用 `knowledge_ingest` 工具入库
66
+ 将准备好的 JSON 参数传入 `knowledge_ingest` 工具执行入库。
67
+
68
+ ---
69
+
70
+ ## 4. 证伪下架与删除(Retraction SOP)
71
+
72
+ 知识卡片既是研究资产也是负债:被证伪的观点留在库里,召回时会持续污染分析。当用户指出某张卡片的核心论点被事实证伪、来源撤稿或存在重大错误时,按下架流程处理:
73
+
74
+ 1. **定位确认**:调 `knowledge_search`(按主题/标的/作者)或 `knowledge_get`(已有 id 时)取出候选卡片,向用户复述卡片标题与核心论点并确认下架对象——不凭模糊记忆直接删;
75
+ 2. **执行删除**:调 `knowledge_delete`(带 `reason`,如「核心论点被 XX 数据证伪」「来源撤稿」);工具自动清理其他卡片指向本卡片的 `related` 引用,并在输出中回显被删卡片的论点留痕;
76
+ 3. **沉淀元知识**:证伪结论本身是有价值的元知识——记入交易日志(agent 轨);若用户同意,可另立一张 `manual` 卡片记录「该观点为何被证伪」(credibility 按核查结论定级),防止同类观点再次误导;
77
+ 4. **作者降权提示**:同一来源反复出现被证伪内容时,在回复中明确提示后续引用该作者的卡片需整体降权。
78
+
79
+ ---
80
+
81
+ ## 5. 输出契约
82
+
83
+ 入库成功后,向用户输出清晰的入库汇报:
84
+ 1. **入库状态**:新建成功 / 更新已有卡片;
85
+ 2. **卡片信息**:卡片标题 + 卡片 ID(`kc_...`) + 主题标签 + 可信度评级;
86
+ 3. **图谱关联**:明确列出与知识库中哪些既有卡片建立了关联(例如「已与《煤炭行业资本开支周期研判》建立关联」);
87
+ 4. **浏览提示**:提示用户可在中栏「知识库」Tab 中查看力导图谱可视化。
88
+
89
+ 下架成功后,向用户输出:已删除的卡片标题 + id + 删除原因 + 受影响(清理引用)的卡片清单,以及证伪结论的留痕去向(交易日志/新卡片)。
90
+
91
+ ---
92
+
93
+ ## 6. 风控与立场红线
94
+
95
+ 1. **转述不等于背书**:入库内容是「原作者观点的结构化提炼与核查记录」,绝不代表平台或 Agent 对该投资观点的认同;
96
+ 2. **免责提示**:知识库全部卡片均为研究辅助资料,**明示不构成任何投资建议**;
97
+ 3. **杜绝自动爬取**:严禁未经用户交互授权后台自动批量抓取外部订阅源;
98
+ 4. **铁律遵循**:严格遵守 dsh-trading 铁律(知识沉淀不包含私钥/凭据,不直接触发任何实盘交易)。
@@ -0,0 +1,91 @@
1
+ ---
2
+ name: trading-notes-setup
3
+ description: 交易日志(trading journal)建立与记录规范:检查/创建工作区 `.trading-journal/` 双轨目录(agent 轨 + human 轨),分别记录 agent 与人类各自的操作(做了什么)。会话启动检查发现工作区没有交易日志目录时调用本技能建立骨架;用户要求建立或查看交易日志时调用;记录条目格式以本技能为权威来源。
4
+ ---
5
+
6
+ # 交易日志建立与记录规范(trading-notes-setup)
7
+
8
+ ## 1. 目标与适用范围(Goal & Scope)
9
+
10
+ - **适用**:任何交易工作区的操作留痕——agent 做了什么、人做了什么,各自一轨、append-only、按月滚动,事后可追溯谁在什么时候动了什么。
11
+ - **非适用**:行情快照、持仓明细等易过期数据(那是工具输出,不进日志);决策的 why 与放弃了什么(归工作区已有的决策记录体系,如 Agent Note——日志只记"做了什么",不与决策记录重复)。
12
+
13
+ ## 2. 首次建立:目录骨架(Setup SOP)
14
+
15
+ 会话启动检查或用户要求时,先确认当前工作目录下 `.trading-journal/` 是否存在:
16
+
17
+ - **不存在**:先向用户说明本工作区尚未建立交易日志、拟创建的结构,征得同意后创建以下骨架(目录已存在对应文件时跳过,绝不覆盖已有内容):
18
+
19
+ ```
20
+ .trading-journal/
21
+ ├── AGENTS.md # agent 守则:知识召回先行 + 日志纪律指针(内容模板见下)
22
+ ├── README.md # 本工作区日志规则速览(谁写哪轨、格式、归档,人可读)
23
+ ├── agent/
24
+ │ └── YYYY-MM.md # agent 操作轨(当月流水,agent 写)
25
+ ├── human/
26
+ │ └── YYYY-MM.md # 人类操作轨(当月流水,agent 代记或用户手写)
27
+ └── archive/ # 归档区(旧月文件移入,封存不改)
28
+ ```
29
+
30
+ 建成后向用户报告路径与轨语义,并把本次会话的首条记录写入(见 §4)。
31
+
32
+ **`AGENTS.md` 内容模板**(原样写入;已有该文件时跳过,绝不覆盖):
33
+
34
+ ```markdown
35
+ # 交易工作区 Agent 守则
36
+
37
+ 本文件随交易日志骨架创建,对在本工作区工作的 agent 生效。
38
+
39
+ ## 知识召回先行(分析工作流必经)
40
+
41
+ - 对任何标的、行业或宏观主题做正式分析前,先调 `knowledge_search` 检索本地知识库
42
+ (按标的代码、行业与主题标签),命中的知识卡片作为线索证据纳入分析,并标注卡片
43
+ id 便于溯源;没命中也如实说明"知识库无相关沉淀";
44
+ - 卡片是"别人观点的结构化转述":转述≠背书,只作线索证据,不得替代原始披露与权威
45
+ 数据;对外明示不构成投资建议;
46
+ - 注意卡片 `updatedAt` 与素材发布时间:宏观/政策类观点过期即降权,不得当作当前
47
+ 事实引用;
48
+ - 分析中形成新的可复用结论时,按 knowledge-curation skill 建议用户沉淀入库
49
+ (先 `knowledge_search` 查重,再 `knowledge_ingest`)。
50
+
51
+ ## 日志纪律
52
+
53
+ - 双轨语义、条目格式与归档规则以 trading-notes-setup skill 为权威来源;
54
+ - 本目录内一切写入遵守 append-only:只追加当月流水,不改历史条目,归档后封存。
55
+ ```
56
+ - **已存在**:不重建;向用户简报现状(已有月份文件数、最近一条记录日期),转 §4 日常纪律。
57
+
58
+ ## 3. 双轨语义与取舍(What to Record)
59
+
60
+ | 轨 | 写什么 | 谁来写 |
61
+ |---|---|---|
62
+ | `agent/` | agent 主动执行的操作:下单/撤单/改单(**含 dry-run,一律标注**)、风控清单拦截、设置或连接器变更、重要分析产出(交易计划/报告,引用标题+结论一句话,不贴全文) | agent |
63
+ | `human/` | 人的决定与手工操作:审批面放行/拒绝、liveTrading 开关变更、行情源/交易所切换、GUI 手动下单、用户明确交代的交易决策 | agent 得知时**代记**(条目尾注 `(代记)` 并注明来源:用户口述/审批面/GUI 观察);用户也可自己写 |
64
+
65
+ **不写**:每条 ticker/K 线查询(噪音)、密钥/账户号/API key 等敏感信息、整段对话粘贴。拿不准是否值得记时:改变状态的操作记,纯查询不记。
66
+
67
+ ## 4. 条目格式契约(Output Format Contract)
68
+
69
+ 月度文件 `YYYY-MM.md` 顶部一行说明轨语义,正文按日分节、时间升序追加:
70
+
71
+ ```markdown
72
+ # agent 轨 · 2026-09(append-only;格式见 trading-notes-setup)
73
+
74
+ ## 2026-09-02
75
+
76
+ - 14:32 crypto_place_order BTCUSDT limit 0.01 @ 60000(dry-run)→ 模拟成交
77
+ - 15:02 【实盘确认】OKX BTC-USDT-SWAP 开多 1 张 @ 市价
78
+ - 触发:用户在审批面明确放行(crypto-risk-checklist 已过)
79
+ - 结果:订单 OKX-xxx,成交均价 60,050(代记,来源:审批面)
80
+ ```
81
+
82
+ - 普通操作:一行 bullet,`- HH:MM 做了什么(关键参数与结果)`。
83
+ - 重要操作(实盘单、闸门拦截、设置变更、用户重大决定):bullet 之下缩进 `- 触发:` / `- 结果:` 两行;结果必须落到具体数值或订单号,禁止模糊代词。
84
+ - 时间用本地时间 `HH:MM`;跨市场会话在条目里带市场词(如 `crypto`/`us`)。
85
+
86
+ ## 5. 日常纪律与归档(Risk & Maintenance)
87
+
88
+ - 会话内出现值得记录的操作,**当场追加**到当月对应轨文件(不留到"最后一起写",会丢);月度文件不存在时按 `YYYY-MM.md` 新建。
89
+ - 月末跨月自然开新文件;跨年或用户要求时,把旧月文件原样移入 `archive/`,封存后不再修改。
90
+ - 工作区若是 git 仓库,建议把日志随常规变更提交(操作史有审计价值);是否提交由用户决定。
91
+ - 与审批闸门的关系:日志是**事后留痕**,不替代、不延迟任何 dry-run/审批闸门流程;先闸门后记账。
@@ -0,0 +1,65 @@
1
+ ---
2
+ name: trading-strategy-paradigms
3
+ description: 经典交易策略参考范式指南:提供短线(唐奇安突破/RSI极值回归)、波段(EMA双均线/布林带下轨回归)、长线(200日均线基线/12月动量)6大策略原理、参数调优、8项回测指标研读与风险防范 SOP。
4
+ ---
5
+
6
+ # 交易策略参考范式与回测研读指南(Trading Strategy Paradigms & Backtest SOP)
7
+
8
+ 当用户在会话中咨询交易策略构思、参数调优、历史表现验证或回测指标解读时,请遵循本 SOP 为用户提供客观、专业、带依据与风险边界的策略参考。
9
+
10
+ ---
11
+
12
+ ## 1. 策略三分类与 6 大参考范式
13
+
14
+ 系统内置三类共 6 个经典参考策略(纯函数计算、零外部随机依赖):
15
+
16
+ | 周期分类 | 策略 ID | 核心逻辑 | 适用行情 | 潜在风险与失效边界 |
17
+ | :--- | :--- | :--- | :--- | :--- |
18
+ | **短线** | `donchian-breakout` | 突破前 N1 根高点买入,跌破前 N2 根低点离场 | 单边爆发趋势市 | 震荡市频繁假突破追高止损 |
19
+ | **短线** | `rsi-reversion` | RSI(2) < 10 极端超卖抄底,> 60 反弹止盈 | 宽幅箱体震荡市 | 单边暴跌行情中越跌越买左侧接飞刀 |
20
+ | **波段** | `ema-crossover` | 快线 EMA20 金叉慢线 EMA60 做多,死叉平仓 | 中级波段趋势行情 | 窄幅盘整期间均线反复缠绕产生摩擦成本 |
21
+ | **波段** | `bollinger-reversion` | 跌破布林下轨做多,反弹至中轨(基准均线)止盈 | 均值回归与通道震荡 | 趋势加速破位时下轨失守 |
22
+ | **长线** | `sma-baseline` | 收盘站上 SMA200 牛市均线做多,跌破空仓避险 | 长期宏观周期牛熊切换 | 长期牛熊分界线附近频繁震荡穿越 |
23
+ | **长线** | `momentum-12m` | 过去 12 个月动量为正且站上年线做多,转负平仓 | 大周期强动量资产 | 拐点滞后,无法在最高点逃顶 |
24
+
25
+ ---
26
+
27
+ ## 2. 8 项核心回测指标研读标准
28
+
29
+ 在为用户分析策略回测报告时,必须结合以下 8 项标准指标进行立体研读,严禁单一吹捧累计收益率:
30
+
31
+ 1. **累计收益率 (Total Return)**:回测全周期内账户总净值增长比例。
32
+ 2. **复合年化收益率 (CAGR)**:几何平均年化回报,用于消除不同回测时长的时间偏差。
33
+ 3. **最大回撤 (Max Drawdown)**:从历史最高净值点到最低点的最大下跌幅度。**核心风控指标**:评估策略在最坏情景下的心理承受极限。
34
+ 4. **夏普比率 (Sharpe Ratio)**:超额收益与波动率的比值(年化),大于 1.0 为优良,大于 2.0 为极其优秀。
35
+ 5. **胜率 (Win Rate)**:盈利交易笔数 / 总交易笔数。趋势跟踪策略胜率通常仅 35%~45%(靠大盈小亏),均值回归策略胜率通常 60%~75%(靠高频小赢)。
36
+ 6. **盈亏比 (Profit Factor)**:总盈利金额 / 总亏损金额。健康策略应 $\ge 1.5$。
37
+ 7. **交易总笔数 (Trade Count)**:样本量。若交易笔数 $< 10$ 笔,回测指标统计显著性不足,警惕幸存者偏差。
38
+ 8. **市场暴露度 (Exposure)**:持仓时间占回测总周期的百分比。低暴露度(如 20%~40%)意味着大部分时间空仓观望,资金利用效率与避险能力强。
39
+
40
+ ---
41
+
42
+ ## 3. 回测与实盘差异分析(反方情景)
43
+
44
+ 引导用户理解回测与实盘交易之间的天然摩擦:
45
+ 1. **滑点与流动性冲击**:回测默认使用次根 Bar 开盘价成交,实盘中大单可能造成显著冲击成本;
46
+ 2. **幸存者偏差与过拟合**:针对特定历史 K 线反复调整参数得到的“完美曲线”在未来样本外往往迅速失效;
47
+ 3. **持仓心理成本**:长达数月的回撤期在回测中仅是曲线的一段波谷,但在实盘中极易引发人为干预导致策略变形。
48
+
49
+ ---
50
+
51
+ ## 4. 建议沟通范式(五段论)
52
+
53
+ 在与用户对话讨论策略时,采用五段论结构:
54
+ 1. **策略定位与适用假设**:说明策略是属于趋势跟踪还是均值回归,适合哪种市场状态;
55
+ 2. **参数设定与敏感度**:解释各参数的物理意义,避免极限参数过度拟合;
56
+ 3. **历史表现与回测解读**:列出收益、回撤、胜率与盈亏比等关键数字;
57
+ 4. **反方情景与极端风险**:指出若市场风格切换(如从单边转为剧烈震荡),该策略将如何亏损;
58
+ 5. **风险提示与安全闸门**:明确提示实盘仍需人工审核与风险把控。
59
+
60
+ ---
61
+
62
+ ## 5. 铁律红线与免责声明
63
+
64
+ 1. **实盘安全铁律**:策略层输出仅为数学信号与历史模拟分析,**严禁任何实盘自动化托管与私自下单循环**;任何交易必须通过 Base 统一审批闸门与显式人工确认。
65
+ 2. **免责提示**:历史回测收益不代表未来实际收益,策略分析内容仅供参考,不构成任何实质性投资建议。
@@ -0,0 +1 @@
1
+ ../../../packages/kit-us/assets/skills/us-risk-checklist.md