Skip to main content
Glama
kimagure-dd

@kimagure-dd/xirr-mcp

by kimagure-dd

@kimagure-dd/xirr-mcp

npm version License: MIT

用于 XIRR(扩展内部收益率) 计算的 MCP 服务器,内置对乐天证券 (Rakuten Securities) 交易 CSV 的支持。

将其接入 Claude Desktop 或 Claude Code,提供从券商导出的 CSV,然后询问:

「这个 CSV 和当前评估价值 ¥1,500,000,请计算实际年化收益率」

Claude 将为您计算 XIRR(考虑不规则的投入和提取),并解释结果。

功能

  • 🧮 calculate_xirr — 根据任意现金流序列 + 当前估值计算 XIRR

  • 📄 parse_rakuten_csv — 将乐天证券交易 CSV (取引履歴) 解析为标准化的现金流

  • 🔌 纯 stdio MCP 服务器,无需网络访问

  • 📦 无需运行时配置,单个 npx 命令即可运行

安装与设置

Claude Desktop

编辑 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) 或 %APPDATA%\Claude\claude_desktop_config.json (Windows):

{
  "mcpServers": {
    "xirr": {
      "command": "npx",
      "args": ["-y", "@kimagure-dd/xirr-mcp"]
    }
  }
}

重启 Claude Desktop。calculate_xirrparse_rakuten_csv 工具应该会出现。

Claude Code

claude mcp add xirr -- npx -y @kimagure-dd/xirr-mcp

使用示例

直接计算

询问 Claude:

「请根据以下现金流计算 XIRR。2020-01-01 投资 100 万日元,2022-01-01 追加 50 万日元,当前(2025-01-01)评估价值 200 万日元」

Claude 将使用结构化输入调用 calculate_xirr 并返回:

{
  "annualRate": 12.34,
  "annualRateFormatted": "12.34%",
  "totalInvestment": 1500000,
  "totalGain": 500000,
  "gainRateFormatted": "33.33%",
  "converged": true
}

使用乐天证券 CSV

  1. 登录乐天证券 → 取引履歴 → CSV 下载

  2. (由于下载的是 Shift_JIS 编码,请转换为 UTF-8)

  3. 将文件内容传给 Claude 并要求:“请根据此计算实际年化收益率。当前评估价值为 ¥X”

Claude 将自动通过 parse_rakuten_csvcalculate_xirr 处理 CSV。

工具参考

calculate_xirr

根据一系列带日期的现金流和当前估值计算 XIRR。

输入:

字段

类型

描述

cashFlows

array

{ date, amount } 列表。正数 = 投资,负数 = 提取。

currentValue

number

当前投资组合估值。

valuationDate

string

YYYY-MM-DD。currentValue 的日期。

输出:

字段

类型

描述

annualRate

number

年化收益率(百分比)。

monthlyRate

number

月利率(复利至年化)。

totalInvestment

number

所有现金流的总和。

totalGain

number

currentValue - totalInvestment

gainRate

number

总收益占投资的百分比。

converged

boolean

如果迭代求解器收敛,则为 true。

parse_rakuten_csv

解析乐天证券交易 CSV。

输入:

字段

类型

描述

csvContent

string

原始 CSV 文本(UTF-8 解码)。

必需的 CSV 表头:

约定日, 取引, ファンド名, 受渡金額/(ポイント利用)[円]

行为:

  • 买付 行 → 正数金额(投资)

  • 其他交易类型(例如 売却) → 负数金额(提取)

  • 无效行将被跳过并发出警告

计算方法

  • 牛顿-拉夫逊 (Newton-Raphson) 迭代作为主要求解器

  • 当牛顿法无法收敛时使用二分法作为备选

  • 时间单位:月(使用每月 365.25 / 12 天)

  • 收敛阈值:1e-7

该逻辑与 kimagure-dd.dev 上的基于浏览器的 XIRR 计算器 使用的逻辑相同,因此结果一致。

免责声明

此工具仅用于计算投资绩效,仅供参考。 未考虑税收、交易费用和货币兑换。 输出不构成投资建议。

开发

npm install
npm run build
npm test

在发布前在本地测试服务器:

npm pack
# Then point Claude Desktop to the .tgz path

许可证

MIT © kimagure-dd

相关

A
license - permissive license
-
quality - not tested
C
maintenance

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kimagure-dd/xirr-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server