Spaces:
Running
Running
fengwm commited on
Commit ·
4a3dd5b
1
Parent(s): 23022b9
fix: report direction probability as signal confidence
Browse files
README.md
CHANGED
|
@@ -21,7 +21,7 @@ pinned: false
|
|
| 21 |
|
| 22 |
- 请求/响应主字段由 `ts_code` 统一为 `symbol`
|
| 23 |
- 数据源切换回 Tushare Pro(`pro_bar`,前复权 `qfq`)
|
| 24 |
-
- 方向概率 `direction.probability` 定义为“
|
| 25 |
- 推理路径改为分批采样(可通过 `MC_BATCH_SIZE` 调整批大小)
|
| 26 |
- 新增阶段耗时日志(`fetch/calendar/infer/build/cache/total`)
|
| 27 |
|
|
@@ -122,7 +122,7 @@ print(r["result"])
|
|
| 122 |
"cache_expires_at": "2026-03-16 15:00:00 UTC+08:00",
|
| 123 |
"direction": {
|
| 124 |
"signal": "bearish",
|
| 125 |
-
"probability": 0.
|
| 126 |
},
|
| 127 |
"summary": {
|
| 128 |
"mean_close": 36.35,
|
|
@@ -281,8 +281,8 @@ curl "https://yingfeng64-kronos-api.hf.space/api/v1/cache"
|
|
| 281 |
| 字段 | 含义 |
|
| 282 |
|---|---|
|
| 283 |
| `base_date` | 预测所基于的最后一个历史 K 线日期 |
|
| 284 |
-
| `direction.signal` | `"bullish"` / `"bearish"`,由
|
| 285 |
-
| `direction.probability` |
|
| 286 |
| `trading_low` | 该日预测最低价的 q2.5 分位数(95% 交易区间下沿) |
|
| 287 |
| `trading_high` | 该日预测最高价的 q97.5 分位数(95% 交易区间上沿) |
|
| 288 |
| `uncertainty` | `(trading_high − trading_low) / last_close`,无量纲不确定性 |
|
|
|
|
| 21 |
|
| 22 |
- 请求/响应主字段由 `ts_code` 统一为 `symbol`
|
| 23 |
- 数据源切换回 Tushare Pro(`pro_bar`,前复权 `qfq`)
|
| 24 |
+
- 方向概率 `direction.probability` 定义为“当前 `direction.signal` 的概率(0–1)”
|
| 25 |
- 推理路径改为分批采样(可通过 `MC_BATCH_SIZE` 调整批大小)
|
| 26 |
- 新增阶段耗时日志(`fetch/calendar/infer/build/cache/total`)
|
| 27 |
|
|
|
|
| 122 |
"cache_expires_at": "2026-03-16 15:00:00 UTC+08:00",
|
| 123 |
"direction": {
|
| 124 |
"signal": "bearish",
|
| 125 |
+
"probability": 0.5667
|
| 126 |
},
|
| 127 |
"summary": {
|
| 128 |
"mean_close": 36.35,
|
|
|
|
| 281 |
| 字段 | 含义 |
|
| 282 |
|---|---|
|
| 283 |
| `base_date` | 预测所基于的最后一个历史 K 线日期 |
|
| 284 |
+
| `direction.signal` | `"bullish"` / `"bearish"`,由内部看涨概率是否 >= 0.5 决定 |
|
| 285 |
+
| `direction.probability` | 当前 `direction.signal` 的概率(0–1) |
|
| 286 |
| `trading_low` | 该日预测最低价的 q2.5 分位数(95% 交易区间下沿) |
|
| 287 |
| `trading_high` | 该日预测最高价的 q97.5 分位数(95% 交易区间上沿) |
|
| 288 |
| `uncertainty` | `(trading_high − trading_low) / last_close`,无量纲不确定性 |
|
app.py
CHANGED
|
@@ -162,6 +162,10 @@ class PredictRequest(BaseModel):
|
|
| 162 |
def _build_response(req: PredictRequest, base_date: str, pred_mean, ci,
|
| 163 |
trading_low, trading_high, direction_prob, last_close,
|
| 164 |
y_timestamp) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
bands = []
|
| 166 |
for i in range(req.pred_len):
|
| 167 |
band: dict = {
|
|
@@ -191,8 +195,8 @@ def _build_response(req: PredictRequest, base_date: str, pred_mean, ci,
|
|
| 191 |
"confidence": 95,
|
| 192 |
"confidence_warning": req.pred_len > 30,
|
| 193 |
"direction": {
|
| 194 |
-
"signal":
|
| 195 |
-
"probability": round(
|
| 196 |
},
|
| 197 |
"summary": {
|
| 198 |
"mean_close": round(float(pred_mean["close"].iloc[-1]), 4),
|
|
|
|
| 162 |
def _build_response(req: PredictRequest, base_date: str, pred_mean, ci,
|
| 163 |
trading_low, trading_high, direction_prob, last_close,
|
| 164 |
y_timestamp) -> dict:
|
| 165 |
+
bullish_prob = float(direction_prob)
|
| 166 |
+
direction_signal = "bullish" if bullish_prob >= 0.5 else "bearish"
|
| 167 |
+
signal_prob = bullish_prob if direction_signal == "bullish" else (1 - bullish_prob)
|
| 168 |
+
|
| 169 |
bands = []
|
| 170 |
for i in range(req.pred_len):
|
| 171 |
band: dict = {
|
|
|
|
| 195 |
"confidence": 95,
|
| 196 |
"confidence_warning": req.pred_len > 30,
|
| 197 |
"direction": {
|
| 198 |
+
"signal": direction_signal,
|
| 199 |
+
"probability": round(signal_prob, 4),
|
| 200 |
},
|
| 201 |
"summary": {
|
| 202 |
"mean_close": round(float(pred_mean["close"].iloc[-1]), 4),
|