Return calculation

From aifinlab/FinClaw · View interactive version

Return calculation is an AI agent skill from the GitHub repository aifinlab/FinClaw. 用于区间/年化收益的收益率计算原子 skill,适用于通用行业金融计算场景。

How to use this skill

Skill file

收益率计算 Skill

数据来源

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

1. 价格序列数据

2. 交易流水数据

3. 数据格式要求

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


功能

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

1. 区间收益率计算

2. 年化收益率计算

3. 考虑分红的收益率计算

4. 滚动收益率计算

5. 数据处理能力


使用示例

1. 安装依赖

pip install -r requirements.txt

2. 基础使用

# 计算简单收益率
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. 高级配置

# 考虑分红的收益率计算
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. 输出示例

{
  "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. 使用限制


参考资料

License

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.