return-calculation

用于区间/年化收益的收益率计算原子 skill,适用于通用行业金融计算场景。

105 stars

Best use case

return-calculation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

用于区间/年化收益的收益率计算原子 skill,适用于通用行业金融计算场景。

Teams using return-calculation should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/return-calculation/SKILL.md --create-dirs "https://raw.githubusercontent.com/aifinlab/FinClaw/main/skills/atomic-zlj/return-calculation/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/return-calculation/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How return-calculation Compares

Feature / Agentreturn-calculationStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

用于区间/年化收益的收益率计算原子 skill,适用于通用行业金融计算场景。

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 收益率计算 Skill

## 数据来源

本 Skill 支持多种金融数据输入格式,核心数据来源包括:

### 1. 价格序列数据
- **股票价格数据**:开盘价、收盘价、最高价、最低价、成交量
- **基金净值数据**:单位净值、累计净值、分红信息
- **债券价格数据**:全价、净价、到期收益率
- **指数数据**:各类市场指数、行业指数、主题指数

### 2. 交易流水数据
- **交易记录**:买入价格、卖出价格、交易数量、交易日期
- **持仓数据**:持仓数量、持仓成本、当前市值
- **分红派息数据**:现金分红、股票分红、除权除息日期

### 3. 数据格式要求
- **CSV格式**:标准时间序列数据,包含日期和价格列
- **Excel格式**:支持多工作表价格数据
- **JSON格式**:结构化价格数据
- **数据库连接**:支持SQL数据库直接查询

> 说明:本 Skill 不包含数据采集功能,需要用户提供清洗后的价格数据。建议数据时间跨度不少于1年,以便进行年化收益率计算。

---

## 功能

本 Skill 提供全面的收益率计算能力,涵盖多种计算口径:

### 1. 区间收益率计算
- **简单收益率** = (期末价格 - 期初价格) / 期初价格 × 100%
- **对数收益率** = ln(期末价格 / 期初价格) × 100%
- **累计收益率** = (期末价格 - 期初价格) / 期初价格 × 100%
- **多期收益率** = (1 + r1) × (1 + r2) × ... × (1 + rn) - 1

### 2. 年化收益率计算
- **年化简单收益率** = (1 + 区间收益率)^(365/天数) - 1
- **年化对数收益率** = 区间对数收益率 × (365/天数)
- **考虑复利的年化收益率**:基于复利公式计算

### 3. 考虑分红的收益率计算
- **总收益率** = (期末价格 + 分红 - 期初价格) / 期初价格 × 100%
- **复权收益率**:考虑分红除权后的收益率
- **分红收益率** = 分红金额 / 期初价格 × 100%

### 4. 滚动收益率计算
- **滚动窗口收益率**:计算指定时间窗口内的滚动收益率
- **移动平均收益率**:基于移动平均价格计算收益率
- **分位数收益率**:计算收益率的分位数分布

### 5. 数据处理能力
- **缺失值处理**:支持前向填充、后向填充、插值等方法
- **异常值检测**:基于统计方法识别和处理异常价格
- **数据标准化**:支持不同数据源的格式统一
- **交易日调整**:自动识别交易日和非交易日

---

## 使用示例

### 1. 安装依赖
```bash
pip install -r requirements.txt
```

### 2. 基础使用
```bash
# 计算简单收益率
python scripts/calc_return.py --input prices.csv --date-col date --price-col close --output returns.csv

# 计算年化收益率
python scripts/calc_return.py --input prices.csv --date-col date --price-col close --output annual_returns.csv --annualize true

# 计算对数收益率
python scripts/calc_return.py --input prices.csv --date-col date --price-col close --output log_returns.csv --method log
```

### 3. 高级配置
```bash
# 考虑分红的收益率计算
python scripts/calc_return.py --input prices.csv --dividend-file dividends.csv --output total_returns.csv --include-dividend true

# 计算滚动收益率
python scripts/calc_return.py --input prices.csv --output rolling_returns.csv --window 30 --min-periods 20

# 指定时间区间
python scripts/calc_return.py --input prices.csv --output period_returns.csv --start-date 2024-01-01 --end-date 2024-12-31
```

### 4. 输出示例
```json
{
  "symbol": "000001.SZ",
  "period": "2024-01-01 to 2024-12-31",
  "returns": {
    "simple_return": 15.8,
    "log_return": 14.7,
    "annualized_return": 15.8,
    "total_return": 18.2,
    "dividend_yield": 2.4
  },
  "statistics": {
    "trading_days": 245,
    "max_return": 8.5,
    "min_return": -5.2,
    "volatility": 12.3
  },
  "rolling_returns": {
    "30_day": 2.1,
    "60_day": 4.5,
    "90_day": 7.8
  }
}
```

---

## 注意事项与限制

### 1. 数据质量要求
- 价格数据需要经过清洗和验证
- 建议使用复权价格进行计算
- 异常价格数据会影响计算结果

### 2. 计算口径说明
- 不同计算方法的收益率结果可能不同
- 年化收益率需要明确交易日天数
- 分红处理方式会影响总收益率

### 3. 时间序列分析
- 收益率计算应结合时间序列分析
- 考虑市场波动对收益率的影响
- 不同时间区间的收益率不可直接比较

### 4. 综合判断原则
- 单一收益率指标不能全面反映投资表现
- 需要结合风险指标进行综合分析
- 应结合市场环境和行业特点进行判断

### 5. 使用限制
- 本 Skill 输出为技术分析结果,不构成投资建议
- 使用者应结合专业判断和具体业务场景
- 对于重大决策,建议咨询专业投资顾问

---

## 参考资料
- 见 references/ 目录中的相关文档,包括:
  - 收益率计算公式手册
  - 年化收益率计算方法
  - 分红处理最佳实践指南
  - 数据处理方法说明文档

## License
- 本 skill 代码部分采用 MIT License,详见 `LICENSE` 文件
- 依赖与运行环境以 `requirements.txt` 为准
- 文档内容采用 CC BY 4.0 许可

Related Skills

return-attribution-explainer

105
from aifinlab/FinClaw

收益来源解释助手,专用于解释客户持仓收益的来源和构成。 以下情况请主动触发此技能: - 用户需要向客户解释收益来源("赚的是什么钱") - 用户问"这个收益是怎么来的""收益归因分析" - 客户问"为什么赚/亏""收益合理吗" - 用户准备业绩归因报告、客户收益分析材料 - 用户需要区分收益来源(市场 beta/产品 alpha/配置贡献/择时贡献) - 客户对收益有疑问,需要专业解释 输出清晰的收益归因分析,帮助客户理解收益来源、评估投资表现。 不要等用户明确说"收益归因"——只要涉及收益来源解释、业绩归因分析,就应主动启动此技能。

risk-return-explanation

105
from aifinlab/FinClaw

面向基金投研分析领域的风险收益解释任务Skill,围绕「风险收益解释助手」场景提供信息抽取、结构化分析与结果输出。

return-source-explanation

105
from aifinlab/FinClaw

面向基金投顾与客户服务领域的收益解释任务Skill,围绕「收益来源解释助手」场景提供信息抽取、结构化分析与结果输出。

excess-return-decomposition

105
from aifinlab/FinClaw

面向基金投研分析领域的收益拆解任务Skill,围绕「超额收益拆解助手」场景提供信息抽取、结构化分析与结果输出。

volatility-calculation

105
from aifinlab/FinClaw

用于风险波动的波动率计算原子 skill,适用于通用行业金融计算场景。

max-drawdown-calculation

105
from aifinlab/FinClaw

用于回撤指标的最大回撤计算原子 skill,适用于通用行业金融计算场景。

financial-ratio-calculation

105
from aifinlab/FinClaw

用于计算企业财务比率的原子技能,包括盈利能力、偿债能力、营运能力和成长性指标。适用于财务报表分析、企业信用评估、投资研究和风险管理等金融场景。

style-factor-calculation

105
from aifinlab/FinClaw

用于因子暴露的风格因子计算原子 skill,适用于通用行业金融计算场景。

risk-return-matching-calculation

105
from aifinlab/FinClaw

用于适当性匹配的风险收益匹配计算原子 skill,适用于通用行业金融计算场景。

position-concentration-calculation

105
from aifinlab/FinClaw

用于仓位/集中度的仓位与集中度计算原子 skill,适用于通用行业金融计算场景。

portfolio-attribution-calculation

105
from aifinlab/FinClaw

用于收益归因的组合归因计算原子 skill,适用于通用行业金融计算场景。

peer-comparison-calculation

105
from aifinlab/FinClaw

用于排名/对比的同类对比计算原子 skill,适用于通用行业金融计算场景。