Token导航 LogoToken导航TokenDH.com
前端设计需要联网github未标认证来源可访问clear审计提醒

portfolio-optimization投资组合优化

Agent Skill

portfolio-optimization 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

2,472

周安装

101

GitHub Stars

93

下载量

456
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:portfolio-optimization(投资组合优化)
来源仓库:https://github.com/letta-ai/skills
仓库路径:skills/portfolio-optimization
安装命令:
npx skills add https://github.com/letta-ai/skills --skill portfolio-optimization
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/letta-ai/skills --skill portfolio-optimization

简介

portfolio-optimization 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态、代码变更或协作事项进行整理。
  • 通过 npx skills add 命令从 GitHub 仓库安装并使用。
  • 安装前需确认权限范围、维护状态,以及是否触发联网或文件操作。
  • 建议结合原始 README 和仓库内容核验具体用法和功能边界。

SKILL.md

Portfolio Optimization

Overview

This skill provides guidance for implementing high-performance portfolio optimization algorithms using Python C extensions. It covers the workflow for creating C extensions that interface with NumPy arrays, proper verification strategies, and common pitfalls to avoid when optimizing numerical computations.

When to Apply This Skill

Apply this skill when:

  • Implementing portfolio risk calculations (variance, volatility, Sharpe ratio)
  • Optimizing matrix-vector operations for large asset portfolios
  • Creating C extensions for Python numerical code
  • Performance requirements specify speedup ratios (e.g., >= 1.2x)
  • Working with covariance matrices and portfolio weights

Recommended Workflow

Phase 1: Codebase Understanding

Before writing any code:

  1. Read all relevant source files completely - Understand the baseline implementation, data structures, and expected interfaces
  2. Identify the mathematical operations - Common operations include:

- Matrix-vector multiplication (covariance matrix times weights) - Dot products (weights times returns) - Square root operations (for volatility from variance)

  1. Understand the test suite - Know what correctness tolerances are expected (e.g., 1e-10) and what performance benchmarks must be met
  2. Document the input/output contracts - Array shapes, data types (typically float64), and return value specifications

Phase 2: Implementation Planning

Consider these factors before implementation:

  1. Why C provides speedup:

- Eliminates Python interpreter overhead - Enables direct memory access without bounds checking - Allows compiler optimizations (vectorization, loop unrolling) - Reduces temporary array allocations

  1. Design decisions to make:

- Whether to use NumPy C API for zero-copy array access - Memory layout assumptions (C-contiguous vs Fortran-contiguous) - Error handling strategy for type mismatches and dimension errors

  1. Potential algorithmic optimizations:

- Cache-friendly memory access patterns (row-major iteration for C arrays) - SIMD vectorization opportunities - Minimizing Python-to-C data conversion overhead

Phase 3: C Extension Implementation

When implementing the C extension:

  1. Include proper headers:

- Python.h (must be first) - numpy/arrayobject.h for NumPy array access

  1. Initialize NumPy in the module init function:

- Call import_array() to initialize NumPy C API

  1. Use NumPy C API for array access:

- PyArray_DATA() for getting data pointer - PyArray_DIM() for dimensions - PyArray_STRIDE() for memory strides - Check PyArray_IS_C_CONTIGUOUS() for memory layout

  1. Implement robust error handling:

- Validate array dimensions match expected shapes - Check data types (expect NPY_FLOAT64 for double precision) - Handle non-contiguous arrays (either reject or handle strides) - Set appropriate Python exceptions on error

Phase 4: Python Wrapper Implementation

Create a Python module that:

  1. Imports the C extension module
  2. Provides a clean interface matching the baseline API
  3. Handles any necessary array preparation (ensuring contiguity)
  4. Documents the interface clearly

Phase 5: Verification Strategy

Critical: Verify every change completely

  1. After editing files, re-read them - Confirm edits were applied correctly, especially for multi-line changes
  2. Test incrementally:

- Build the C extension first and verify it compiles - Test individual functions before running full benchmarks - Use small test cases for correctness verification before scaling up

  1. Correctness verification:

- Compare outputs against baseline implementation - Use appropriate numerical tolerances (typically 1e-10 for double precision) - Test with known inputs where expected outputs can be calculated manually

  1. Performance verification:

- Run benchmarks with representative data sizes - Verify speedup meets requirements across different portfolio sizes - Test edge cases: small portfolios (n=1, n=10), large portfolios (n=5000+)

Edge Cases to Handle

Ensure the implementation addresses:

  1. Empty portfolios (n=0) - Return appropriate default or error
  2. Single-asset portfolios (n=1) - Degenerate case for covariance
  3. Dimension mismatches - Weights vector length vs covariance matrix dimensions
  4. Invalid inputs:

- Non-square covariance matrices - NaN or infinity values in inputs - Negative variance (mathematically invalid)

  1. Memory considerations:

- Non-contiguous NumPy arrays - Memory allocation failures in C code - Large portfolios that may stress memory

Common Pitfalls to Avoid

Code Completeness

  • Never truncate code in edit operations - always provide complete implementations
  • Verify file contents after editing to confirm changes applied correctly
  • Document all design choices explicitly

Testing Approach

  • Avoid going directly from implementation to full benchmark testing
  • Test each function individually before integration testing
  • Do not rely solely on "tests pass" for validation - understand why they pass

C Extension Specific

  • Always check NumPy array types before accessing data
  • Handle reference counting properly to avoid memory leaks
  • Initialize NumPy API with import_array() in module init
  • Use PyErr_SetString() to set exceptions on errors

Performance Validation

  • Verify speedup is consistent across different input sizes
  • Profile if further optimizations might be needed
  • Consider the overhead of Python-to-C transitions for small inputs

Build and Test Commands

Typical workflow commands:

# Build the C extension
python setup.py build_ext --inplace

# Run correctness tests
python -c "from portfolio_optimized import *; # test calls"

# Run benchmark
python benchmark.py

# Run full test suite
pytest test_portfolio.py -v

Verification Checklist

Before considering the task complete:

  • All source files read and understood
  • C extension compiles without warnings
  • Individual functions tested for correctness
  • Numerical results match baseline within tolerance
  • Performance meets speedup requirements
  • Edge cases explicitly tested or handled
  • Error handling implemented for invalid inputs
  • File contents verified after all edits
  • No memory leaks in C code (proper reference counting)

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

31.66%
按下载量换算144

OpenCode

21.63%
按下载量换算99

Antigravity

17.13%
按下载量换算78

Codex

13.49%
按下载量换算62

Gemini CLI

8.71%
按下载量换算40

Cursor

3.53%
按下载量换算16

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills