Fund Correlation Analysis: Calculating Pearson Correlation Coefficients of Domestic Funds within an Agent

Introduction

When building or rebalancing portfolios, it is often necessary to check if the net asset values (NAV) of several funds rise and fall in tandem. Manually retrieving historical data in spreadsheets, aligning dates, and calculating correlation coefficients involves multiple steps and is prone to alignment errors. By delegating the tasks of “Data Retrieval + Matrix Calculation + Report Generation” to an Agent equipped with a Skill, you can generate reusable CSV or HTML files directly within the conversation. Below is an introduction to the SkillHub community Skill “Fund Correlation Analysis” (@user_a706bb76/finance001, v1.0.1).

What is this

“Fund Correlation Analysis” is an Agent Skill designed for data-analysis scenarios, maintained by community publisher user_a706bb76; the SkillHub page lists the author as xibei. The Skill embeds a Python script, fund_correlation_v3.py, which fetches domestic fund NAV data via AkShare, calculates the Pearson correlation coefficient between multiple funds, supports 3 / 6 / 12-month windows, and outputs CSV and HTML visual reports (console tables or JSON are also supported). The tags indicate requires_api_key=false, meaning no separate API Key configuration is needed.

SkillHub inclusion information (scraped 2026-10-22): Rating 100000, 902 downloads; categorized under data-analysis, source: community.

Core Functions

Verified via the SKILL.md and script descriptions within the Skill package, the capabilities include:

  1. Data Source: ak.fund_name_em() parses fund abbreviations, and ak.fund_open_fund_info_em() retrieves historical NAV (Tiantian Fund Network + AkShare).
  2. Target Scope: Domestic funds (ETFs, Open-ended, LOF, QDII, Money Market, Bonds, etc.); inputs require at least 2 six-digit fund codes, and the script supports mixed inputs of codes and names.
  3. Time Span: --period options are 3m, 6m, 12m (default 3m).
  4. Output: --output options are table (default), csv, json, html; HTML includes a color-coded matrix and pairwise explanations.
  5. Environment: Depends on local python; optional environment variable PYTHONIOENCODING is recommended to be set to utf-8 to avoid garbled Chinese output.

Installation and Activation

1. Install SkillHub CLI (if not already installed)

Check or install according to the SkillHub Installation Documentation:

command -v skillhub && skillhub --version

If not installed, run:

curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash

2. Install this Skill to the current Agent’s skills directory

During installation, you must use --dir to point to the skills directory recognized by your Agent; otherwise, it may default to ./skills/ and fail to load. The installation prompt provided on the SkillHub page is: Install @user_a706bb76/finance001 according to https://skillhub.cn/install/skillhub.md.

Command line example (slug requires @ prefix):

skillhub install @user_a706bb76/finance001 --dir ~/.cursor/skills/

Common paths for other clients (replace --dir accordingly):

  • Claude Code: ~/.claude/skills/
  • Codex: ~/.codex/skills/ or .agents/skills/ under the project

After installation, restart or refresh the Skill list as required by your client.

3. Python Dependencies

Enter the Skill directory and install the script dependencies:

pip install akshare pandas

It is recommended to set the output encoding before running (consistent with Skill metadata):

export PYTHONIOENCODING=utf-8

Typical Usage

The main program in the Skill directory is fund_correlation_v3.py. The following commands are derived from the official SKILL.md and can be reproduced directly.

Basic usage (at least two funds):

python fund_correlation_v3.py 510050 510300 159919

Specify a 3-month window and generate an HTML report:

python fund_correlation_v3.py 510050 510300 --period 3m --output html

Export CSV:

python fund_correlation_v3.py 510050 510300 --output csv

Multi-fund QDII and Index Enhancement example (including period and HTML):

python fund_correlation_v3.py 006105 000614 003629 003646 --period 3m --output html

Parameter Summary:

Parameter Description
Fund Code positional Six digits, at least 2 required
--period / -p 3m, 6m, 12m, default 3m
--output / -o table, csv, json, html
--verbose / -v Print data fetching and loading logs

In environments like Cursor, you can also specify fund codes, time spans, and output formats in the conversation, and the Agent will invoke the above script according to SKILL.md.

Use Cases and Notes

Suitable for: Quickly checking if funds in a portfolio move in high alignment (e.g., ETF comparison, linear correlation between QDII and domestic index enhancement), or passing the matrix to subsequent spreadsheet/reporting workflows (CSV / HTML).

Limitations and Notes (Specified in Skill documentation):

  1. Data depends on AkShare and public market interfaces; some QDIIs may have delays or missing data.
  2. Pearson coefficient only describes linear relationships; the documentation suggests cross-referencing multiple --period settings.
  3. Multi-fund returns are aligned by “minimum common length”; short establishment periods or suspensions may result in fewer effective samples.
  4. Historical correlation does not represent future performance and does not constitute investment advice.

The Skill metadata homepage points to https://github.com/workbuddy/fund-correlation-tool, which can serve as a supplementary reference for the script’s background; the SKILL.md and fund_correlation_v3.py inside the SkillHub installation package are the definitive sources.

Conclusion

“Fund Correlation Analysis” chains domestic fund NAV retrieval, Pearson matrix calculation, and CSV/HTML reporting into a scriptable path, making it suitable for quick portfolio-level checks when attached to an Agent. For installation and details, see SkillHub:

  • Page: https://www.skillhub.cn/skills/user_a706bb76/finance001
  • Coordinates: @user_a706bb76/finance001
  • API Entry: https://api.skillhub.cn/user_a706bb76/finance001
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye