pandaai-cli 0.1.0__py3-none-any.whl
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.
- cli.py +442 -0
- pandaai/__init__.py +12 -0
- pandaai/auth.py +103 -0
- pandaai/billing.py +20 -0
- pandaai/config.py +40 -0
- pandaai/constants.py +15 -0
- pandaai/download.py +41 -0
- pandaai/factor.py +96 -0
- pandaai/factor_core.py +283 -0
- pandaai/factor_list.py +183 -0
- pandaai/formatting.py +79 -0
- pandaai/output.py +99 -0
- pandaai_cli-0.1.0.dist-info/METADATA +451 -0
- pandaai_cli-0.1.0.dist-info/RECORD +19 -0
- pandaai_cli-0.1.0.dist-info/WHEEL +5 -0
- pandaai_cli-0.1.0.dist-info/entry_points.txt +2 -0
- pandaai_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
- pandaai_cli-0.1.0.dist-info/top_level.txt +3 -0
- template.py +578 -0
pandaai/output.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""运行结果查询:节点输出、task_id 提取、完整结果聚合"""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
from .auth import api_url, make_headers
|
|
9
|
+
from .factor import FACTOR_ANALYSIS_ENDPOINTS
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_factor_run_detail(config: dict, token: str, uid: str, run_id: str) -> Optional[dict]:
|
|
13
|
+
"""查询因子分析运行详情(含 output_data_obj 映射)"""
|
|
14
|
+
url = api_url(config, "/quantflow/api/workflow/run")
|
|
15
|
+
try:
|
|
16
|
+
resp = requests.get(url, params={"workflow_run_id": run_id},
|
|
17
|
+
headers=make_headers(token=token, uid=uid), timeout=10)
|
|
18
|
+
data = resp.json()
|
|
19
|
+
if data.get("code") == 0:
|
|
20
|
+
return data.get("data", {})
|
|
21
|
+
except Exception:
|
|
22
|
+
pass
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_node_output(config: dict, token: str, uid: str, output_obj_id: str) -> Optional[dict]:
|
|
27
|
+
"""查询单个节点的输出数据"""
|
|
28
|
+
url = api_url(config, "/quantflow/api/workflow/run/output")
|
|
29
|
+
try:
|
|
30
|
+
resp = requests.get(url, params={"output_obj_id": output_obj_id},
|
|
31
|
+
headers=make_headers(token=token, uid=uid), timeout=30)
|
|
32
|
+
data = resp.json()
|
|
33
|
+
if data.get("code") == 0:
|
|
34
|
+
return data.get("data", {})
|
|
35
|
+
except Exception:
|
|
36
|
+
pass
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def extract_task_id(config: dict, token: str, uid: str, run_id: str) -> Optional[str]:
|
|
41
|
+
"""从运行详情中提取因子分析的 task_id"""
|
|
42
|
+
detail = get_factor_run_detail(config, token, uid, run_id)
|
|
43
|
+
if not detail:
|
|
44
|
+
return None
|
|
45
|
+
output_map = detail.get("output_data_obj", {})
|
|
46
|
+
fa_node_uuid = "300e12f5-4814-44c2-9810-c95a4567283c"
|
|
47
|
+
output_obj_id = output_map.get(fa_node_uuid)
|
|
48
|
+
if not output_obj_id:
|
|
49
|
+
return None
|
|
50
|
+
node_data = get_node_output(config, token, uid, output_obj_id)
|
|
51
|
+
return node_data.get("task_id") if node_data else None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def fetch_factor_analysis(config: dict, token: str, uid: str, task_id: str) -> dict:
|
|
55
|
+
"""调用全部 14 个因子分析接口,返回聚合结果"""
|
|
56
|
+
prefix = api_url(config, "/quantflow/api/factor/")
|
|
57
|
+
results = {"task_id": task_id}
|
|
58
|
+
for ep in FACTOR_ANALYSIS_ENDPOINTS:
|
|
59
|
+
try:
|
|
60
|
+
resp = requests.get(f"{prefix}{ep}", params={"task_id": task_id},
|
|
61
|
+
headers=make_headers(token=token, uid=uid), timeout=30)
|
|
62
|
+
data = resp.json()
|
|
63
|
+
if data.get("code") in ("200", 200):
|
|
64
|
+
ep_data = data.get("data", {})
|
|
65
|
+
for k, v in ep_data.items():
|
|
66
|
+
if k != "task_id":
|
|
67
|
+
results[ep] = v
|
|
68
|
+
break
|
|
69
|
+
except Exception:
|
|
70
|
+
results[ep] = None
|
|
71
|
+
return results
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def get_factor_run_results(config: dict, token: str, uid: str, run_id: str) -> dict:
|
|
75
|
+
"""获取一次因子分析的完整结果:节点输出 + 因子分析全部接口"""
|
|
76
|
+
detail = get_factor_run_detail(config, token, uid, run_id)
|
|
77
|
+
if not detail:
|
|
78
|
+
return {"error": "获取运行详情失败"}
|
|
79
|
+
|
|
80
|
+
output_map = detail.get("output_data_obj", {})
|
|
81
|
+
results = {
|
|
82
|
+
"status": detail.get("status"),
|
|
83
|
+
"duration_seconds": detail.get("duration_seconds"),
|
|
84
|
+
"start_time": detail.get("start_time"),
|
|
85
|
+
"end_time": detail.get("end_time"),
|
|
86
|
+
"nodes": {},
|
|
87
|
+
"factor_analysis": None,
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for node_uuid, output_obj_id in output_map.items():
|
|
91
|
+
data = get_node_output(config, token, uid, output_obj_id)
|
|
92
|
+
if data:
|
|
93
|
+
results["nodes"][node_uuid] = data
|
|
94
|
+
|
|
95
|
+
task_id = extract_task_id(config, token, uid, run_id)
|
|
96
|
+
if task_id:
|
|
97
|
+
results["factor_analysis"] = fetch_factor_analysis(config, token, uid, task_id)
|
|
98
|
+
|
|
99
|
+
return results
|
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pandaai-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: PandaAI 因子分析 CLI 工具 — 传入 Python 因子代码或公式,自动完成登录、创建、执行、结果和余额查询
|
|
5
|
+
Author: PandaAI
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://www.pandaaiquant.com
|
|
8
|
+
Keywords: pandaai,factor,quant,cli,因子分析,量化
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: requests>=2.28
|
|
23
|
+
Requires-Dist: pyyaml>=6.0
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# PandaAI 因子分析 CLI
|
|
27
|
+
|
|
28
|
+
供 AI Skill 调用的命令行工具,传入 Python 因子代码或公式,自动完成登录 → 创建 → 执行 → 轮询 → 结果 + 余额。
|
|
29
|
+
|
|
30
|
+
## 安装
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# 方式一:源码安装
|
|
34
|
+
uv venv --python 3.12
|
|
35
|
+
uv pip install -r requirements.txt
|
|
36
|
+
|
|
37
|
+
# 方式二:whl 安装
|
|
38
|
+
uv pip install dist/pandaai_cli-0.1.0-py3-none-any.whl
|
|
39
|
+
# 安装后直接使用: pandaai-cli factor_list
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 快速开始
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# 0. 激活虚拟环境
|
|
46
|
+
source .venv/bin/activate
|
|
47
|
+
|
|
48
|
+
# 1. 登录(token 自动保存到 config.yaml)
|
|
49
|
+
python cli.py login --phone 13800138000 --password 'your_password'
|
|
50
|
+
|
|
51
|
+
# 2. 创建因子分析
|
|
52
|
+
python cli.py factor_create --formula "close/ref(close,5)-1"
|
|
53
|
+
# → ✅ 因子分析已创建: 6a461b10...
|
|
54
|
+
|
|
55
|
+
# 3. 执行并拿结果
|
|
56
|
+
python cli.py factor_run 6a461b10... --download
|
|
57
|
+
|
|
58
|
+
# 4. 查看列表
|
|
59
|
+
python cli.py factor_list
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 命令一览
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
python cli.py <command> [options]
|
|
66
|
+
|
|
67
|
+
命令:
|
|
68
|
+
login 登录并保存 token
|
|
69
|
+
factor_create 创建因子分析(不执行),返回 factor_id
|
|
70
|
+
factor_info <factor_id> 查看因子详情(代码/公式 + 所有参数)
|
|
71
|
+
factor_update <factor_id> [options] 修改因子参数
|
|
72
|
+
factor_run <factor_id> 执行已有因子分析(启动 + 轮询 + 结果)
|
|
73
|
+
factor_list 列出所有因子分析
|
|
74
|
+
balance 查询算力余额
|
|
75
|
+
factor_result <run_id> 查询运行结果(14 个因子分析接口)
|
|
76
|
+
factor_delete <factor_id> [factor_id...] 删除因子分析
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 详细参数
|
|
80
|
+
|
|
81
|
+
### login — 登录
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
python cli.py login [--phone PHONE] [--password PWD]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
| 参数 | 说明 |
|
|
88
|
+
|------|------|
|
|
89
|
+
| `--phone` | 手机号(不传则交互式输入) |
|
|
90
|
+
| `--password` | 密码(不传则隐藏输入,更安全) |
|
|
91
|
+
|
|
92
|
+
登录成功后 token 自动保存到 `config.yaml`,后续命令无需再登录。token 过期时自动提示重新登录。
|
|
93
|
+
|
|
94
|
+
### factor_create — 创建因子分析
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
python cli.py factor_create (--code | --formula | --file) CONTENT
|
|
98
|
+
[--name NAME] [--start-date YYYYMMDD] [--end-date YYYYMMDD]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
| 参数 | 默认值 | 说明 |
|
|
102
|
+
|------|--------|------|
|
|
103
|
+
| `--code CODE` | - | Python 因子代码(需继承 `Factor` 基类) |
|
|
104
|
+
| `--formula FORMULA` | - | 因子公式字符串 |
|
|
105
|
+
| `--file FILE` | - | 从文件读取代码/公式 |
|
|
106
|
+
| `--name NAME` | 新建因子分析 | 因子分析名称 |
|
|
107
|
+
| `--start-date` | 昨天-60天 | 因子构建开始日期,格式 YYYYMMDD |
|
|
108
|
+
| `--end-date` | 昨天 | 因子构建结束日期,格式 YYYYMMDD |
|
|
109
|
+
| `--adjustment-cycle` | 1 | 调仓周期(1-10) |
|
|
110
|
+
| `--factor-direction` | 1 | 因子方向:0=负向,1=正向 |
|
|
111
|
+
|
|
112
|
+
> 分组数量固定为 10,股票池固定为沪深全A,不可修改。
|
|
113
|
+
|
|
114
|
+
**返回值(JSON):**
|
|
115
|
+
```json
|
|
116
|
+
{"success": true, "factor_id": "6a46..."}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**示例:**
|
|
120
|
+
```bash
|
|
121
|
+
python cli.py factor_create --formula "close/ref(close,5)-1"
|
|
122
|
+
# → ✅ 因子分析已创建: 6a461b10...
|
|
123
|
+
|
|
124
|
+
python cli.py factor_create --code "$(cat factor.py)" --name "动量因子"
|
|
125
|
+
python cli.py factor_create --file ./factor.py --start-date 20240101 --end-date 20240630
|
|
126
|
+
|
|
127
|
+
# 自定义因子分析参数
|
|
128
|
+
python cli.py factor_create --formula "close/ref(close,5)-1" \
|
|
129
|
+
--adjustment-cycle 3 --factor-direction 0
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### factor_info — 查看因子详情
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
python cli.py factor_info <factor_id>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| 参数 | 默认值 | 说明 |
|
|
139
|
+
|------|--------|------|
|
|
140
|
+
| `factor_id` | 必填 | 因子分析 ID |
|
|
141
|
+
|
|
142
|
+
展示内容:名称、ID、类型(Python 代码/因子公式)、创建时间、调仓周期、分组数量、因子方向、股票池、日期范围、代码/公式内容。
|
|
143
|
+
|
|
144
|
+
### factor_update — 修改因子参数
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
python cli.py factor_update <factor_id> [options]
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
| 参数 | 默认值 | 说明 |
|
|
151
|
+
|------|--------|------|
|
|
152
|
+
| `factor_id` | 必填 | 因子分析 ID |
|
|
153
|
+
| `--name` | - | 新名称 |
|
|
154
|
+
| `--code` / `--formula` / `--file` | - | 新代码/公式(三选一) |
|
|
155
|
+
| `--start-date` | - | 开始日期 YYYYMMDD |
|
|
156
|
+
| `--end-date` | - | 结束日期 YYYYMMDD |
|
|
157
|
+
| `--adjustment-cycle` | - | 调仓周期 1-10 |
|
|
158
|
+
| `--factor-direction` | - | 因子方向 0=负向 1=正向 |
|
|
159
|
+
|
|
160
|
+
**约束:**
|
|
161
|
+
- 调仓周期必须在 1-10 之间
|
|
162
|
+
- 分组数量固定为 10,不可修改
|
|
163
|
+
- 股票池固定为沪深全A,不可修改
|
|
164
|
+
|
|
165
|
+
### factor_run — 执行因子分析
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
python cli.py factor_run <factor_id>
|
|
169
|
+
[--download [PATH]] [--poll-interval SEC] [--timeout SEC]
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
| 参数 | 默认值 | 说明 |
|
|
173
|
+
|------|--------|------|
|
|
174
|
+
| `factor_id` | 必填 | 要执行的因子分析 ID |
|
|
175
|
+
| `--download [PATH]` | 不下载 | 下载结果 CSV,默认 ~/Downloads/ |
|
|
176
|
+
| `--poll-interval` | 2 | 状态轮询间隔(秒) |
|
|
177
|
+
| `--timeout` | 600 | 超时时间(秒) |
|
|
178
|
+
|
|
179
|
+
> 算力服务器固定使用 cpu=4, memory=8, gpu=4,无需手动选择。
|
|
180
|
+
|
|
181
|
+
**返回值(JSON):**
|
|
182
|
+
|
|
183
|
+
成功:
|
|
184
|
+
```json
|
|
185
|
+
{
|
|
186
|
+
"success": true,
|
|
187
|
+
"status": "SUCCESS",
|
|
188
|
+
"factor_id": "6a46...",
|
|
189
|
+
"factor_run_id": "6a46...",
|
|
190
|
+
"duration_seconds": 6.5,
|
|
191
|
+
"output": [{"node_title": "因子分析", "node_output": {"task_id": "..."}}],
|
|
192
|
+
"billing": {"balance": 9451.51, "deducted": 2.0, "status": "ok"},
|
|
193
|
+
"results": {
|
|
194
|
+
"nodes": {...},
|
|
195
|
+
"factor_analysis": {
|
|
196
|
+
"query_factor_analysis_data": [...],
|
|
197
|
+
"query_group_return_analysis": [...],
|
|
198
|
+
...
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
失败:
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"success": false,
|
|
208
|
+
"status": "FAILED",
|
|
209
|
+
"error": {"type": "WORKFLOW_FAILED", "message": "...", "node_errors": [...]},
|
|
210
|
+
"billing": {"balance": 9449.51, "deducted": 2.0, "status": "ok"}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**示例:**
|
|
215
|
+
```bash
|
|
216
|
+
python cli.py factor_run 6a461b10... --download
|
|
217
|
+
python cli.py factor_run 6a461b10... --download /tmp/my_data.csv
|
|
218
|
+
python cli.py factor_run 6a461b10... --timeout 120
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### factor_list — 列出因子分析
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
python cli.py factor_list [--limit N] [--offset N] [--no-detail]
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
| 参数 | 默认值 | 说明 |
|
|
228
|
+
|------|--------|------|
|
|
229
|
+
| `--limit` | 100 | 每页条数(最大 100) |
|
|
230
|
+
| `--offset` | 0 | 偏移量 |
|
|
231
|
+
| `--no-detail` | false | 跳过获取分析摘要(更快) |
|
|
232
|
+
|
|
233
|
+
列表列:名称、创建时间、最后一次运行时间、Run ID、分析摘要(14 个指标)
|
|
234
|
+
|
|
235
|
+
分析摘要包含:
|
|
236
|
+
- **核心绩效**:因子收益、夏普比率、年化收益、最大回撤
|
|
237
|
+
- **IC 系列**:IC_mean、Rank_IC、IC_std、IC_IR、IR、P(IC<-0.02)、P(IC>0.02)、t统计量、p-value、单调性
|
|
238
|
+
|
|
239
|
+
**返回值(JSON):**
|
|
240
|
+
```json
|
|
241
|
+
{
|
|
242
|
+
"success": true,
|
|
243
|
+
"total": 180,
|
|
244
|
+
"count": 100,
|
|
245
|
+
"limit": 100,
|
|
246
|
+
"offset": 0,
|
|
247
|
+
"factors": [
|
|
248
|
+
{"_id": "6a46...", "name": "动量因子", "create_at": 1782..., "last_run_id": "6a46...", "_last_run_time": "...", "_analysis_summary": "因子收益 20.90% 夏普比率 8.02 年化收益 175.58% 最大回撤 0.00% IC_mean -0.06 Rank_IC -0.07 IC_std 0.11 IC_IR -0.50 IR -4.01 P(IC<-0.02) 83.33% P(IC>0.02) 16.67% t统计量 -1.22 p-value 0.28 单调性 0.73"}
|
|
249
|
+
]
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
**示例:**
|
|
254
|
+
```bash
|
|
255
|
+
python cli.py factor_list
|
|
256
|
+
python cli.py factor_list --limit 50 --offset 50
|
|
257
|
+
python cli.py factor_list --no-detail
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### balance — 查询算力余额
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
python cli.py balance
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**返回值(文本):**
|
|
267
|
+
```
|
|
268
|
+
算力: 9435.51
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**返回值(JSON):**
|
|
272
|
+
```json
|
|
273
|
+
{"success": true, "balance": {"computingPower": 9435.51, ...}}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### factor_result — 查询运行结果
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
python cli.py factor_result <run_id> [--download [PATH]]
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
| 参数 | 默认值 | 说明 |
|
|
283
|
+
|------|--------|------|
|
|
284
|
+
| `run_id` | 必填 | 运行 ID |
|
|
285
|
+
| `--download [PATH]` | 不下载 | 下载结果 CSV |
|
|
286
|
+
|
|
287
|
+
调用全部 14 个因子分析接口,展示:
|
|
288
|
+
- **核心绩效**:因子收益、夏普比率、年化收益、最大回撤
|
|
289
|
+
- **因子分析指标**:IC_mean, Rank_IC, IC_std, IC_IR, IR, P(IC<-0.02), P(IC>0.02), t统计量, p-value, 单调性
|
|
290
|
+
- **分组收益**:10 分组 + 多空组合的 年化收益/超额收益/夏普比率/最大回撤/月胜率
|
|
291
|
+
- **Top 因子**:最新日期因子值最高的 10 只股票
|
|
292
|
+
- **图表数据**:IC 序列、IC 衰减、IC 密度分布等 10 个图表(完整 JSON,含全量数据点)
|
|
293
|
+
|
|
294
|
+
**示例:**
|
|
295
|
+
```bash
|
|
296
|
+
python cli.py factor_result 6a461b10...
|
|
297
|
+
python cli.py factor_result 6a461b10... --download
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### factor_delete — 删除因子分析
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
python cli.py factor_delete <factor_id> [factor_id...]
|
|
304
|
+
python cli.py factor_delete --pattern "quota-test" [--yes]
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
| 参数 | 默认值 | 说明 |
|
|
308
|
+
|------|--------|------|
|
|
309
|
+
| `factor_id` | 至少一个 | 因子分析 ID(支持多个) |
|
|
310
|
+
| `--pattern` | - | 按名称前缀批量匹配 |
|
|
311
|
+
| `--yes` | false | 跳过删除确认 |
|
|
312
|
+
|
|
313
|
+
**示例:**
|
|
314
|
+
```bash
|
|
315
|
+
python cli.py factor_delete 6a461b10...
|
|
316
|
+
python cli.py factor_delete abc123 def456 ghi789
|
|
317
|
+
python cli.py factor_delete --pattern "quota-test" --yes
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## 通用参数
|
|
321
|
+
|
|
322
|
+
| 参数 | 默认值 | 说明 |
|
|
323
|
+
|------|--------|------|
|
|
324
|
+
| `--config PATH` | ~/.pandaai/config.yaml | 配置文件路径 |
|
|
325
|
+
| `--json` | false | 仅输出 JSON(不输出 INFO 日志) |
|
|
326
|
+
|
|
327
|
+
> 注意:`--config` 和 `--json` 必须放在子命令**前面**:
|
|
328
|
+
> ```bash
|
|
329
|
+
> python cli.py --json factor_create --formula "..."
|
|
330
|
+
> ```
|
|
331
|
+
|
|
332
|
+
## 因子代码规范
|
|
333
|
+
|
|
334
|
+
### 代码模式(`--code` / `--file`)
|
|
335
|
+
|
|
336
|
+
需继承 `Factor` 基类,实现 `calculate(self, factors)` 方法:
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
class CombinedFactor(Factor):
|
|
340
|
+
def calculate(self, factors):
|
|
341
|
+
volume = factors['volume']
|
|
342
|
+
close = factors['close']
|
|
343
|
+
|
|
344
|
+
# 大单比例信号
|
|
345
|
+
large_order_volume = TS_MAX(volume, 20)
|
|
346
|
+
buy_signal = (large_order_volume / volume > 0.01).astype(int)
|
|
347
|
+
|
|
348
|
+
# OBV 突破信号
|
|
349
|
+
obv = (volume * ((close - close.shift(1)) / close.shift(1))).cumsum()
|
|
350
|
+
obv_signal = ((obv == obv.rolling(90).max()) & (obv > obv.rolling(30).mean())).astype(int)
|
|
351
|
+
|
|
352
|
+
return buy_signal + obv_signal
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### 公式模式(`--formula`)
|
|
356
|
+
|
|
357
|
+
直接写因子表达式,可用变量 `open`, `close`, `high`, `low`, `volume`, `amount` 等:
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
# 5日收益率
|
|
361
|
+
--formula "close/ref(close,5)-1"
|
|
362
|
+
|
|
363
|
+
# 对数市值排名
|
|
364
|
+
--formula "RANK(-LOG(MARKET_CAP))"
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## 因子分析链路
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
CodeControl → FactorBuildProControl → FactorAnalysisControl → FactorAnalysisChartControl
|
|
371
|
+
(Python代码) (线性因子构建) (因子分析) (结果展示)
|
|
372
|
+
→ DataDownloadControl (数据下载)
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## 配置
|
|
376
|
+
|
|
377
|
+
配置文件默认位置 `~/.pandaai/config.yaml`,也可通过 `--config` 指定其他路径。
|
|
378
|
+
|
|
379
|
+
首次使用直接 `login` 会自动创建:
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
# 自动创建 ~/.pandaai/config.yaml
|
|
383
|
+
python cli.py login --phone 13800138000 --password 'xxx'
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
`config.yaml` 内容:
|
|
387
|
+
|
|
388
|
+
```yaml
|
|
389
|
+
gateway_url: "https://www.pandaaiquant.com/pandaApi"
|
|
390
|
+
token: "eyJ..."
|
|
391
|
+
uid: "35981"
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## 目录结构
|
|
395
|
+
|
|
396
|
+
```
|
|
397
|
+
pandaai_cli/
|
|
398
|
+
├── cli.py # 入口:argparse + 子命令 dispatch
|
|
399
|
+
├── template.py # 因子分析模板构建
|
|
400
|
+
├── pyproject.toml # Python 打包配置(whl/pypi)
|
|
401
|
+
├── config.yaml # 配置文件(gateway_url + token)
|
|
402
|
+
├── config.example.yaml # 配置示例
|
|
403
|
+
├── requirements.txt # requests, pyyaml
|
|
404
|
+
├── README.md # 本文件
|
|
405
|
+
└── pandaai/ # 功能模块
|
|
406
|
+
├── __init__.py # 统一导出
|
|
407
|
+
├── constants.py # 状态常量
|
|
408
|
+
├── config.py # 配置加载 & token 持久化
|
|
409
|
+
├── auth.py # 登录 & token 验证
|
|
410
|
+
├── billing.py # 算力余额查询
|
|
411
|
+
├── factor_core.py # 因子分析 CRUD + 轮询(含 info/update)
|
|
412
|
+
├── output.py # 运行结果查询
|
|
413
|
+
├── factor.py # 因子分析格式化(14 指标 + 图表)
|
|
414
|
+
├── factor_list.py # 因子列表 & 删除(14 指标摘要)
|
|
415
|
+
├── formatting.py # 成功/失败 JSON 格式化
|
|
416
|
+
└── download.py # CSV 下载
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## 打包
|
|
420
|
+
|
|
421
|
+
```bash
|
|
422
|
+
# 构建 whl
|
|
423
|
+
uv run python -m build --wheel
|
|
424
|
+
# → dist/pandaai_cli-0.1.0-py3-none-any.whl
|
|
425
|
+
|
|
426
|
+
# 安装
|
|
427
|
+
pip install dist/pandaai_cli-0.1.0-py3-none-any.whl
|
|
428
|
+
|
|
429
|
+
# 使用
|
|
430
|
+
pandaai-cli factor_list --limit 3
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
## error.type 全集
|
|
434
|
+
|
|
435
|
+
| type | 说明 |
|
|
436
|
+
|------|------|
|
|
437
|
+
| `LOGIN_FAILED` | 登录失败 |
|
|
438
|
+
| `LOGIN_REQUIRED` | 未登录或 token 过期 |
|
|
439
|
+
| `CREATE_FAILED` | 因子分析创建失败(含限额 402) |
|
|
440
|
+
| `RUN_FAILED` | 因子分析启动失败 |
|
|
441
|
+
| `WORKFLOW_FAILED` | 因子分析代码执行报错 |
|
|
442
|
+
| `LIST_FAILED` | 获取因子列表失败 |
|
|
443
|
+
| `DELETE_FAILED` | 删除因子分析失败 |
|
|
444
|
+
| `INFO_FAILED` | 查看因子详情失败 |
|
|
445
|
+
| `UPDATE_FAILED` | 修改因子失败 |
|
|
446
|
+
| `BALANCE_FAILED` | 查询算力余额失败 |
|
|
447
|
+
| `INSUFFICIENT_BALANCE` | 余额不足被终止 |
|
|
448
|
+
| `TIMEOUT` | 轮询超时 |
|
|
449
|
+
| `INPUT_ERROR` | 输入参数错误 |
|
|
450
|
+
| `CONFIG_ERROR` | 配置文件不存在 |
|
|
451
|
+
| `UNKNOWN` | 未知错误 |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
cli.py,sha256=PLRp05mb_FZ_6l2K8eIHcRloldMWplXR1d5d6y_nwyk,21239
|
|
2
|
+
template.py,sha256=jVPJeWqXLoWeFRhX0EFgxfF7wzP_qUzlJHcWmyzK4Qs,21948
|
|
3
|
+
pandaai/__init__.py,sha256=uEoxC1I5syeuahUrU9LMzoEXAmlKW9BxUYjIm0sz0_o,768
|
|
4
|
+
pandaai/auth.py,sha256=IehI7rJ9qzz55KERLaAz7ehN5S8vL7zAmYZF0ZMN1WA,3172
|
|
5
|
+
pandaai/billing.py,sha256=QenWlTb9kZKGeSVpLN8e_twWhwU9XbScBKJmue5JWAU,505
|
|
6
|
+
pandaai/config.py,sha256=dK-Nm5qqiTgEoDSD-ihfIwwhCZqbrttOMns9gDKZnx8,1401
|
|
7
|
+
pandaai/constants.py,sha256=EjPVBC3TnUQ7BC_jlH-Ee2yZ594eywSaviGp5s824VU,322
|
|
8
|
+
pandaai/download.py,sha256=mpkJrOK3eedUULr6t8arQZfZZvKuJ3fRn1wEe2hTXuU,1350
|
|
9
|
+
pandaai/factor.py,sha256=PtITUV9Kp4myzkQ2uInHtJ1A4WS4-lR9ORIlGjGOJi4,4009
|
|
10
|
+
pandaai/factor_core.py,sha256=epOzs-Id7LoS7p_PxoW9ynB96W-NiBU1f6T7rR1fZzM,11889
|
|
11
|
+
pandaai/factor_list.py,sha256=cZ3qrbwIA4SXzha-YRTVeyU8YS6F_2ntGYLeHDZBxTE,7117
|
|
12
|
+
pandaai/formatting.py,sha256=aYFB1sqJ9ocnWWEVBWyhQb9cUOY0Pu8VQbnn2lz13aE,3141
|
|
13
|
+
pandaai/output.py,sha256=GV3wsmNAgEKOsd9ci9i4LnDCcYe2a3Rys95v4VzzgVQ,3687
|
|
14
|
+
pandaai_cli-0.1.0.dist-info/licenses/LICENSE,sha256=Uwup0oN64NqD0317qdmOVgeH62v-fNNJGx0cTxMkX_Q,1064
|
|
15
|
+
pandaai_cli-0.1.0.dist-info/METADATA,sha256=RG597M95w088V3uSdgaYuGptAkgJdTeiM57DaKlu3KU,13964
|
|
16
|
+
pandaai_cli-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
17
|
+
pandaai_cli-0.1.0.dist-info/entry_points.txt,sha256=WxNLSAxJycB_0eI6ILAvJVcoraGOyunsyBHVQAsZCPs,41
|
|
18
|
+
pandaai_cli-0.1.0.dist-info/top_level.txt,sha256=OdrGfFDQP1jxVMHNJ90WY2zec3SAc8NPWQsDUF3ovuM,21
|
|
19
|
+
pandaai_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PandaAI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|