TrueHOOHA/shanxi-securities-tushare-skill / sxsc-tushare-analysis
sxsc-tushare-analysis
Verified对用户提到的标的(沪深股票、指数、公募基金、期货)进行综合分析,输出带 ECharts 图表的 HTML 分析报告。 触发条件:用户说"分析""研究""评估""看看XX怎么样""XX基本面""XX技术面""XX估值""XX财务""深度研究""对比"等分析类请求,且标的属于 A 股/指数/公募基金/期货。 本 skill 自动调用 sxsc_tushare 取数并输出完整报告,接管数据获取与分析全流程。当本 skill 被触发时,数据获取类 skill 不应同时激活——分析已包含数据。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 43.8 KB |
| scripts/adjustment.py | script | 8.7 KB |
| scripts/analysis_runner.py | script | 120.8 KB |
| scripts/attribution.py | script | 10.1 KB |
| scripts/basic_metrics.py | script | 4.3 KB |
| scripts/check_env.py | script | 8.8 KB |
| scripts/data_api.py | script | 41.2 KB |
| scripts/factor_signals.py | script | 10.3 KB |
| scripts/fund_analysis_runner.py | script | 61.7 KB |
| scripts/fut_analysis_runner.py | script | 41.4 KB |
| scripts/index_analysis_runner.py | script | 54.6 KB |
| scripts/report_html.py | script | 38.0 KB |
| scripts/result_model.py | script | 4.4 KB |
| scripts/risk_modeling.py | script | 6.3 KB |
| scripts/stock_analyzer.py | script | 1.1 KB |
| scripts/technical_indicators.py | script | 5.9 KB |
| scripts/token_util.py | script | 4.0 KB |
scripts/technical_indicators.py
View on GitHub#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
技术指标模块:MACD、RSI、KDJ、布林带、OBV、量比。
用于行情趋势维度的技术分析,补充均线之外的趋势/动量/波动区间信号。
"""
import numpy as np
import pandas as pd
def calc_macd(df_close, fast=12, slow=26, signal=9):
"""MACD 指标。返回 (DIF, DEA, MACD柱) 最新值。
signal 判定真实金叉/死叉:比较前一日与当日 DIF/DEA 的相对位置变化。
"""
ema_fast = df_close.ewm(span=fast, adjust=False).mean()
ema_slow = df_close.ewm(span=slow, adjust=False).mean()
dif = ema_fast - ema_slow
dea = dif.ewm(span=signal, adjust=False).mean()
macd_bar = (dif - dea) * 2
if len(dif) == 0:
return {"DIF": "N/A", "DEA": "N/A", "MACD": "N/A", "signal": "数据不足"}
if len(dif) < 2:
cross = "数据不足"
elif dif.iloc[-1] > dea.iloc[-1] and dif.iloc[-2] <= dea.iloc[-2]:
cross = "金叉"
elif dif.iloc[-1] < dea.iloc[-1] and dif.iloc[-2] >= dea.iloc[-2]:
cross = "死叉"
else:
cross = "多头排列" if dif.iloc[-1] > dea.iloc[-1] else "空头排列"
return {
"DIF": round(float(dif.iloc[-1]), 2),
"DEA": round(float(dea.iloc[-1]), 2),
"MACD": round(float(macd_bar.iloc[-1]), 2),
"signal": cross,
}
def calc_rsi(df_close, period=14):
"""RSI 相对强弱指标。返回最新 RSI 值与超买/超卖判断。"""
if len(df_close) < period + 1:
return {"RSI": "N/A", "signal": "数据不足"}
delta = df_close.diff()
gain = delta.clip(lower=0).rolling(period).mean()
loss = (-delta.clip(upper=0)).rolling(period).mean()
rs = gain / loss
rsi = 100 - 100 / (1 + rs)
val = rsi.iloc[-1]
if np.isnan(val):
return {"RSI": "N/A", "signal": "数据不足"}
val = round(float(val), 1)
flag = "超买" if val > 70 else ("超卖" if val < 30 else "中性")
return {"RSI": val, "signal": flag}
def calc_kdj(df_high, df_low, df_close, period=9):
"""KDJ 随机指标。返回 K/D/J 最新值。
按国内惯例 K、D 以 50 起算:K_t = (2*K_{t-1} + RSV_t)/3,D_t = (2*D_{t-1} + K_t)/3;
旧实现用 ewm(adjust=False) 从首个 RSV 起算,等价于初值=首值而非 50,
与通达信/同花顺的 KDJ 数值不一致(短序列差异明显)。
RSV 为 NaN(除零等)时沿用前值,不产生 NaN 传播。
"""
if len(df_close) < period:
return {"K": "N/A", "D": "N/A", "J": "N/A", "signal": "数据不足"}
low_min = df_low.rolling(period).min()
high_max = df_high.rolling(period).max()
denom = high_max - low_min
rsv = ((df_close - low_min) / denom * 100).replace([np.inf, -np.inf], np.nan)
k = pd.Series(np.nan, index=rsv.index, dtype=float)
d = pd.Series(np.nan, index=rsv.index, dtype=float)
_kv, _dv = 50.0, 50.0 # 国内惯例:K/D 初值 50
for i, rv in enumerate(rsv.tolist()):
if pd.notna(rv):
_kv = (2 * _kv + rv) / 3
_dv = (2 * _dv + _kv) / 3
k.iloc[i] = _kv
d.iloc[i] = _dv
j = 3 * k - 2 * d
if pd.isna(k.iloc[-1]) or pd.isna(d.iloc[-1]):
return {"K": "N/A", "D": "N/A", "J": "N/A", "signal": "数据不足"}
return {
"K": round(float(k.iloc[-1]), 2),
"D": round(float(d.iloc[-1]), 2),
"J": round(float(j.iloc[-1]), 2),
"signal": "金叉" if k.iloc[-1] > d.iloc[-1] and k.iloc[-2] <= d.iloc[-2] else
("死叉" if k.iloc[-1] < d.iloc[-1] and k.iloc[-2] >= d.iloc[-2] else "未形成交叉"),
}
def calc_boll(df_close, window=20, num_std=2):
"""布林带。返回上轨/中轨/下轨及当前位置判断。"""
if len(df_close) < window:
return {"上轨": "N/A", "中轨": "N/A", "下轨": "N/A", "position": "数据不足"}
mid = df_close.rolling(window).mean()
std = df_close.rolling(window).std()
upper = mid + num_std * std
lower = mid - num_std * std
price = df_close.iloc[-1]
up = upper.iloc[-1]
lo = lower.iloc[-1]
md = mid.iloc[-1]
if np.isnan(up) or np.isnan(lo):
return {"上轨": "N/A", "中轨": "N/A", "下轨": "N/A", "position": "数据不足"}
up = round(float(up), 2); lo = round(float(lo), 2); md = round(float(md), 2)
std_last = std.iloc[-1]
if not np.isnan(std_last) and std_last == 0:
return {"上轨": up, "中轨": md, "下轨": lo, "position": "无波动(区间恒定)"}
pos = "触及上轨(超买)" if price >= up * 0.98 else (
"触及下轨(超卖)" if price <= lo * 1.02 else "中轨附近")
return {"上轨": up, "中轨": md, "下轨": lo, "position": pos}
def calc_obv(df_close, df_vol):
"""OBV(能量潮)。返回 OBV 趋势方向。需至少 5 个数据点判断趋势。"""
if len(df_close) < 5:
return {"OBV": "N/A", "trend": "数据不足(<5日)"}
direction = np.where(df_close.diff() > 0, 1, np.where(df_close.diff() < 0, -1, 0))
obv = (direction * df_vol).cumsum()
trend = "上升" if obv.iloc[-1] > obv.iloc[-5] else ("下降" if obv.iloc[-1] < obv.iloc[-5] else "持平")
return {"OBV": round(float(obv.iloc[-1]), 0), "trend": trend}
def calc_volume_ratio(df_vol, window=5):
"""量比 = 当日成交量 / 近 N 日平均成交量(分母不含当日)。
数据不足 window+1 日(无法排除当日)时返回 None,不返回错误的近似值——
旧实现 tail(window+1).head(window) 在 len == window 时会把当日算进分母,
新股/新基金常见,量比被系统性低估。
"""
if len(df_vol) == 0:
return None
if len(df_vol) < window + 1:
return None
ma_vol = df_vol.iloc[-1 - window:-1].mean()
if ma_vol == 0 or (isinstance(ma_vol, float) and np.isnan(ma_vol)):
return None
ratio = df_vol.iloc[-1] / ma_vol
flag = "放量" if ratio > 2 else ("缩量" if ratio < 0.5 else "正常")
return {"量比": round(float(ratio), 2), "signal": flag}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |