factor-library
Installation
Review the source and dependencies with a prompt.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "factor-library" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-70162c1d69b33971732a670d3f79440878917eb42e517c6b86786db699373088. Verify the upstream source and version against https://skillhub.cn/skills/user_4ce3f404/factor-library before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Download permission for this version is unverified or restricted.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Stock factor library engine: a unified registry for “how factors are calculated” and “where data comes from,” including calculation engine, operator library, data adapter layer, and validation system (layered backtesting/orthogonalization/stability); includes two built-in factor sets—Formulaic Alpha (101) and Short-term Volume-Price Alpha (191)—for a total of 290 registerable factors, supporting stock selection, backtesting, and factor research; self-contained and not dependent on external quant systems.
Introduction source: third_party · user_4ce3f404 · 1.0.1 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Software, accounts and paid services
- pip install pandas numpy pytdx tushare
- Limits and differences
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
A verified file list is not available on Skillπ yet.
Browse files at the source ↗Frontmatter
name: factor-library
version: 1.0.0
description: 股票因子库引擎。统一「因子怎么算」与「数据从哪来」:注册表 + 计算引擎 + 算子库 + 数据适配层 + 验证体系(分层回测/正交化/稳定性)。已内置「公式化Alpha(101)」+「短周期量价Alpha(191)」两个因子集,共 290 个可注册因子,支持选股、回测、因子研究。独立自包含,不依赖外部量化系统。
category: 金融/量化
platforms: [WorkBuddy, QClaw, ima]
author: 小米(老狼老板的 AI 股票分析师)
triggers: [因子计算, 选股因子, 因子验证, 分层回测, 股票因子, 量化因子, factor]
tags: [量化, 因子, 选股, 回测, 数据分析, alpha, 股票]
source: https://github.com/laolang/factor-libraryfactor-library · 股票因子库引擎
一键安装
# 1) 安装依赖
pip install pandas numpy pytdx tushare
# 2) 把 factor-library 目录放到 WorkBuddy skill 目录下
mkdir -p ~/.workbuddy/skills
cp -r factor-library ~/.workbuddy/skills/
# 3) 验证安装
cd ~/.workbuddy/skills/factor-library/scripts
python -c "
import engine
print('因子引擎就绪 ✓')
print('因子集:', list(set(m['source'] for m in engine.list_factors())))
print('总因子数:', len(engine.list_factors()))
"
## 内置因子集
| 因子集 | 数量 | 类别 | 来源标识 | 说明 |
|-------|------|------|---------|------|
| 公式化Alpha(卷一) | 101 | `alpha_formulaic` | `狼团量化·公式化Alpha(101)` | 101 条纯公式化 alpha(时序+横截面算子组合) |
| 短周期量价Alpha | 191 | `alpha_shortcycle` | `短周期量价Alpha(191)` | 短周期量价 Alpha(国泰君安 191 风格,已中性命名) |
## 何时使用
- 需要**批量计算**一大批因子值(正交化、分层回测、选股打分前的因子矩阵)。
- 要做**因子研究**:新增因子只需在相应 `_FORMULAS` 里加一条 lambda,或在 `references/` 里补充公式源。
- 接**真实行情**:通过 `data_adapter.from_*` 把任意数据源规整成统一 `FactorData` 契约,因子代码无需改动。
## 数据契约(FactorData)
FactorData(ohlcv={ "open": ... # 日期×股票 宽表 "high": ... "low": ... "close": ... # 必选 "volume": ... # 必选 "amount": ... # 可选(vwap 自动 fallback) "vwap": ... # 可选 })
派生量:`data.returns`(pct_change)、`data.adv20`/`adv60`(日均成交量)。
## 架构
factor-library/ ├── SKILL.md ├── manifest.yaml # SkillHub 元数据 ├── references/ │ ├── factor_catalog.md # 公式化Alpha 101 因子清单 │ ├── alpha_shortcycle_catalog.md # 短周期量价 191 因子清单 │ └── validation_guide.md # 验证判读指南 └── scripts/ ├── init.py ├── engine/ │ ├── init.py # 对外 API │ ├── base.py # 注册表 + 计算引擎 │ ├── operators.py # 算子库(30 个时序/截面算子) │ ├── alpha_formulaic.py # 公式化Alpha(自动生成) │ ├── alpha_shortcycle.py # 短周期量价Alpha(自动生成) │ ├── data_adapter.py # 数据契约 + 合成数据 + 适配桩 │ ├── validation.py # 验证体系:IC/分层回测/正交化 │ └── examples/ │ ├── demo.py # 因子计算 demo │ ├── validate_demo.py # 验证体系 demo │ ├── real_validation.py # 真实行情验证排名 │ ├── _universe.py # 真实股票池(全行业 98 只) │ ├── _cache/ # 行情缓存目录 │ └── output/ # 排名报告输出 └── init.py
> **独立性**:本 skill 完全自包含,验证体系只依赖 numpy/pandas 与本包,**不 import、不读写狼团量化系统任何代码或数据**。
## 对外 API
```python
import sys; sys.path.insert(0, "scripts")
from engine import compute_factor, list_factors, factor_count
from engine import ic_analysis, layered_backtest, neutralize, evaluate
# 1) 看注册情况
print(factor_count())
# {'狼团量化·公式化Alpha(101)': 101, '短周期量价Alpha(191)': 155, ...}
# 2) 计算单个因子
out = compute_factor("alpha001", data)
# 3) 列因子元信息
for m in list_factors(source="短周期量价Alpha(191)"):
print(m["name"], m["description"], m["data_req"])
# 4) 验证:IC 分析
fac = compute_factor("alpha042", data)
fwd = forward_returns(data, periods=1)
ic_analysis(fac, fwd) # {ic_mean, ic_ir, t_stat, ic_win_rate}
# 5) 分层回测
bt = layered_backtest(fac, fwd, n_quantiles=5)
bt["stats"] # {ls_annual_return, ls_sharpe, ls_max_drawdown, ...}
# 6) 中性化
fac_neu = neutralize(fac, industry=data.industry, market_cap=data.market_cap)
# 7) 一站式评估
res = evaluate("alpha042", data, periods=1, n_quantiles=5)
跑通 demo
cd scripts
python examples/demo.py # 101 公式化Alpha demo
python examples/validate_demo.py # 验证体系 demo
python examples/real_validation.py --top 20 # 真实行情验证排名(需联网)
真实行情验证
# 首次拉数需放开联网
cd scripts
python examples/real_validation.py # 拉98只×614天真实行情,跑101因子排名
输出:examples/output/rank_real.html(可视化报告)+ rank_real.csv。
验证体系
validation.py 提供三维因子评估:
- IC 稳定性:IC均值/IR/t值/胜率、分段IC、IC衰减、因子自相关(换手代理)
- 分层回测:5层等权多空净值、年化/夏普/最大回撤/单调性/Top层换手
- 正交化/中性化:行业哑变量+log市值中性化、对已有因子池正交
扩展方式
- 自动生成:
/tmp/regen2.py(公式化Alpha)或/tmp/regen3.py(短周期量价) 在CANON字典里加公式 → 运行python /tmp/regen3.py重新生成 - 手写因子:子类化
FactorBase+@register装饰器
SkillHub 上架信息
- 依赖:Python 3.10+, numpy, pandas(标准科学计算栈)
- 无外部 API 依赖
- 触发词:因子计算、选股因子、分层回测、股票alpha、因子验证
注意事项
- 涨→红、跌→绿(A股约定);本库只算数值,画图/展示遵守该约定。
- 窗口取整:浮点窗口按最近整数处理(
operators._win)。 - 兼容 pandas 3.x(已移除
groupby(axis=1)/clip(other=))。 - 所有因子已做中性化命名(公式化Alpha →
FAxxx,短周期量价 →SCxxx)。 - 股市有风险,分析仅供参考,不构成投资建议。
Current listing version
1.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供290个内置因子(公式化Alpha 101 + 短周期量价Alpha 191),覆盖主流量化因子需求
- 独立自包含设计,不依赖外部量化系统,降低使用门槛
- 支持因子计算、验证、回测完整工作流,解决量化研究核心痛点
Highlights
- 触发词覆盖全面:因子计算、选股因子、分层回测等核心功能关键词
- 边界清晰,无明显歧义或与其他Skill重叠风险
Highlights
- 文档结构完整,包含安装、架构、API、示例、验证体系等关键章节
- 提供端到端可运行demo,降低用户上手难度
- frontmatter信息完整,符合SkillHub规范
Highlights
- 依赖明确且为标准科学计算栈(pandas/numpy)
- 提供完整安装验证流程和真实行情验证demo
- 兼容性说明清晰(pandas 3.x适配)
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 19
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- github.com
Security rating and access scope
risk · Static evidence review; not a runtime safety guarantee.
pip install pandas numpy pytdx tushare
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.