← 返回 Skills 市场
wzratgit

投资组合分析技能

作者 wzratgit · GitHub ↗ · v1.0.2
cross-platform ✓ 安全检测通过
415
总下载
0
收藏
0
当前安装
3
版本数
在 OpenClaw 中安装
/install financial-analysis-skill
功能描述
提供基于免费数据的多资产投资组合风险平价分析、滚动调仓回测及图文报告生成功能。
使用说明 (SKILL.md)

金融分析技能 (Financial Analysis Skill)

概述

这是一个用于投资组合分析的技能,支持使用本地CSV数据进行风险平价组合分析,并提供文字报告和图表可视化。优化版本整合了滚动窗口调仓逻辑和回测功能。

重要说明:此技能仅使用本地CSV文件进行分析,不进行任何网络请求,不需要任何API密钥。

功能特性

  • ✅ 投资组合分析(资产配置、风险评估、收益分析)
  • ✅ 支持多种资产类型:股票、债券、商品等
  • ✅ 本地CSV数据处理
  • ✅ 文字报告生成
  • ✅ 图表可视化(收益曲线、资产分布、风险指标等)
  • 滚动窗口风险平价分析(使用历史一年数据,每月调仓)
  • 避免未来数据(使用expanding窗口计算波动率)
  • 回测功能(完整的回测流程)
  • 无需API密钥(仅使用本地CSV数据)

数据源

  • 本地CSV文件(中国市场数据)
  • 不需要任何外部API密钥

安装依赖

pip install yfinance pandas numpy matplotlib seaborn plotly

使用方法

1. 基本使用

分析投资组合

python financial_analysis.py --portfolio example_portfolio.json --output ./output

获取单个资产数据

python financial_analysis.py --symbol AAPL --period 1y

2. 滚动窗口风险平价分析

运行回测

python optimized_risk_parity_skill.py --csv "C:\path	o\marketdata.csv" --output ./backtest_output

数据格式要求

  • CSV文件应包含日期列和收益率列
  • 收益率数据应为百分比格式(如:1.5表示1.5%)
  • 脚本会自动将百分比转换为实际收益率(除以100)
  • 支持处理文本行和缺失值

3. 投资组合配置文件格式

创建一个JSON文件(如 my_portfolio.json):

{
  "AAPL": 0.25,    # 苹果股票,权重25%
  "GOOGL": 0.20,   # 谷歌股票,权重20%
  "MSFT": 0.20,    # 微软股票,权重20%
  "AMZN": 0.15,    # 亚马逊股票,权重15%
  "TSLA": 0.20     # 特斯拉股票,权重20%
}

滚动窗口风险平价分析

核心特点

  1. 避免未来数据:使用历史一年数据计算波动率
  2. 动态调仓:每月根据最新波动率重新计算权重
  3. 风险平价:各资产对组合风险贡献相等
  4. 回测验证:完整的回测流程,验证策略效果

分析流程

  1. 数据加载:加载CSV数据,处理百分比单位
  2. 滚动波动率:使用expanding窗口计算历史波动率
  3. 权重计算:基于波动率倒数计算风险平价权重
  4. 投资组合收益率:使用滚动权重计算每日收益率
  5. 绩效评估:计算总收益率、年化收益率、夏普比率等
  6. 可视化:生成收益曲线、资产配置、相关性等图表

输出文件

  • 分析报告rolling_risk_parity_report.txt
  • 详细数据rolling_risk_parity_data.json
  • 可视化图表
    • rolling_risk_parity_returns.png - 收益曲线图
    • rolling_risk_parity_allocation.png - 资产配置饼图
    • rolling_risk_parity_correlation.png - 相关性热力图
    • rolling_asset_returns_comparison.png - 资产收益对比图
    • rolling_weight_changes.png - 滚动权重变化图

报告内容

  • 投资组合概览
  • 收益分析(总收益、年化收益)
  • 风险指标(波动率、最大回撤、夏普比率)
  • 资产配置分析
  • 相关性分析
  • 滚动权重变化
  • 可视化图表
  • 投资建议

配置

此技能不需要任何API密钥配置。只需要提供本地CSV文件路径即可。

示例输出

中国市场滚动风险平价组合分析报告
============================================================
生成时间: 2026-02-26 10:20:04
数据来源: C:\Users\wu_zhuoran\.openclaw\workspace\data\marketdata.csv
数据时间范围: 2015-03-23 至 2026-02-25
数据点数: 2656
滚动窗口: 252个交易日(约1年)
调仓频率: 每月

平均投资组合配置:
  五年期国债 (TF.CFE): 46.04% (波动率: 2.46%)
  十年期国债 (T.CFE): 32.55% (波动率: 3.61%)
  沪铜 (CU.SHF): 9.33% (波动率: 17.87%)
  沪金 (AU.SHF): 12.09% (波动率: 14.88%)

收益指标:
  总收益率: 44.78%
  年化收益率: 3.57%

风险指标:
  年化波动率: 3.76%
  最大回撤: -9.48%
  夏普比率: 0.42

技术实现

滚动窗口计算

  • 使用expanding()窗口而非rolling()窗口
  • 确保不使用未来数据
  • 最小窗口大小为252个交易日(约1年)

权重计算

  • 基于波动率倒数加权:权重 = (1/波动率) / ∑(1/波动率)
  • 每月调仓,动态调整权重
  • 使用前一天的权重计算当日收益率

回测验证

  • 完整的回测流程
  • 避免数据泄露
  • 提供详细的绩效指标

注意事项

  • 确保数据质量,处理缺失值和异常值
  • 滚动窗口大小可根据实际情况调整
  • 调仓频率可根据市场情况调整
  • 考虑交易成本对回测结果的影响
安全使用建议
This skill appears coherent and local-only, but take these precautions before installing or running it: - Run it first in an isolated/sandbox environment and monitor network traffic to confirm no outbound connections occur. - Inspect and, if desired, change the default CSV path in optimized_main.py to avoid accidental reads of developer-specific paths. - Note a minor docs inconsistency: SKILL.md lists 'pip install yfinance ...' while other docs and the code do not import yfinance; remove yfinance from install instructions unless you intend to use it. - Review output directory settings to ensure results are written to an intended location (avoid writing into sensitive system folders). - If you will supply real/secret financial files, ensure they are stored/processed according to your data-handling policies.
功能分析
Package: 投资组合分析回测 (xpi) Version: 1.0.0 Description: 根据提供的标的和策略,进行组合构建和回测分析 The package '投资组合分析回测' (financial-analysis-skill) is a Python-based tool designed for local portfolio analysis and backtesting using the risk parity strategy. The code primarily uses standard data science libraries (pandas, numpy, matplotlib, seaborn) to load data from local CSV files, perform financial calculations (rolling volatility, weights, returns, performance metrics), and generate text reports and charts. Crucially, the `manifest.json` and dedicated `NETWORK_SECURITY.md` file explicitly state that the skill is local-only, does not perform any network requests, does not require any API keys, and does not upload any data. A thorough review of the Python source code (`optimized_main.py` and `optimized_risk_parity_skill.py`) confirms these declarations, as there are no imports of network-related libraries (e.g., `requests`, `urllib`, `socket`, `yfinance`) nor any calls that would initiate external communication. File system access is limited to reading the specified input CSV and writing output reports and charts to a user-defined local directory. The documentation also addresses previous review comments, reinforcing the local-only nature of the skill. There are no indications of malicious activities such as data exfiltration, arbitrary code execution, or unauthorized system access. The package's functionality aligns entirely with its stated purpose of offline financial analysis.
能力评估
Purpose & Capability
Name/description match the actual code and files: the package implements rolling-window risk-parity analysis, backtest and local report/chart generation. It does not request unrelated credentials or binaries.
Instruction Scope
Runtime instructions restrict the skill to local CSV input and local outputs. The only caveats are documentation references to a default, user-specific CSV path (C:\Users\wu_zhuoran\.openclaw\workspace\data\marketdata.csv) which is a leftover dev default and should be changed; otherwise instructions do not instruct access to unrelated system files or network endpoints.
Install Mechanism
No install spec is provided (instruction-only + bundled code). No downloads from external URLs or extraction steps. Dependency lists are standard Python libs (pandas/numpy/matplotlib/seaborn).
Credentials
The skill declares no required environment variables or credentials. The code reads a CSV and writes outputs only; this is proportionate for a local backtest tool.
Persistence & Privilege
Skill does not request always:true and does not modify other skills or system configurations. It only reads a provided CSV path and writes output files to the output directory.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install financial-analysis-skill
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /financial-analysis-skill 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.2
- 本版本移除对外部API的使用,仅支持本地CSV数据进行分析,无需API密钥。 - 明确标注所有数据分析和回测均不会进行网络请求,增强数据安全与隐私。 - 文档内容同步更新,优化数据使用说明和依赖流程。 - 新增 INSTALLATION.md、NETWORK_SECURITY.md、REVIEW_RESPONSE.md 文件,补充安装、安全和审核说明。
v1.0.1
- Improved README.md documentation with more details on usage, output files, and analysis steps. - Clarified CSV data format requirements and added examples for backtesting workflow. - No core algorithmic or functional changes to code; focus is on enhanced instructions and clarity for users.
v1.0.0
金融分析技能 1.0.0 - 初始发布,集成投资组合分析与风险评估功能 - 支持多种数据源:Yahoo Finance、Alpha Vantage、Finnhub、CSV - 实现滚动窗口风险平价分析与完整回测流程,避免使用未来数据 - 提供可配置投资组合、文字报告生成与主要绩效图表可视化 - 文档涵盖数据格式要求、用法说明和输出文件结构
元数据
Slug financial-analysis-skill
版本 1.0.2
许可证
累计安装 0
当前安装数 0
历史版本数 3
常见问题

投资组合分析技能 是什么?

提供基于免费数据的多资产投资组合风险平价分析、滚动调仓回测及图文报告生成功能。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 415 次。

如何安装 投资组合分析技能?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install financial-analysis-skill」即可一键安装,无需额外配置。

投资组合分析技能 是免费的吗?

是的,投资组合分析技能 完全免费(开源免费),可自由下载、安装和使用。

投资组合分析技能 支持哪些平台?

投资组合分析技能 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 投资组合分析技能?

由 wzratgit(@wzratgit)开发并维护,当前版本 v1.0.2。

💬 留言讨论