portfolio-optimizer

Optimize stock portfolio weights and report risk metrics across US, China A-shares, and Hong Kong markets.

Updated Sep 3, 2025
One-click install
npx skills add https://github.com/henrywen98/portfolio-optimizer-skill --skill portfolio-optimizer-henrywen98
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: portfolio-optimizer
Source: https://github.com/henrywen98/portfolio-optimizer-skill/tree/main
Command: npx skills add https://github.com/henrywen98/portfolio-optimizer-skill --skill portfolio-optimizer-henrywen98

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pandas, numpy, scipy, PyPortfolioOpt, requests, yfinance, akshare, pytest, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill removes the friction of portfolio construction by turning a list of stock tickers into an optimized allocation, complete with risk metrics and data retrieval across US stocks, China A-shares, and Hong Kong stocks.

Core Features & Use Cases

  • Multi-market portfolio optimization: Build allocations for US, A-share, and Hong Kong universes with automatic market detection.
  • Strategy comparison: Compare max Sharpe, minimum variance, risk parity, maximum diversification, and equal-weight allocations side by side.
  • Risk reporting and backtesting: Review Sharpe, Sortino, Calmar, VaR, CVaR, drawdown, concentration, and rolling-rebalance backtests with trading costs.
  • Free data access: Use a no-API-key fallback chain with online sources or offline CSV input when network access is unavailable.
  • Use Case: A user can provide tickers like AAPL, MSFT, and NVDA, ask for the best risk-adjusted split, and receive weights plus a clear risk summary.

Quick Start

Ask the skill to optimize your portfolio of tickers for the best allocation and risk report, such as “optimize AAPL, MSFT, and NVDA for max Sharpe with no single stock above 30%.”

Frequently Asked Questions about portfolio-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize stock portfolio weights without an API key?

Stock portfolio optimization without an API key is possible using a no-API-key fallback chain with online sources like yfinance and akshare, or offline CSV input when network access is unavailable. The tool fetches historical prices and applies allocation constraints to produce optimal weights.

Can I backtest asset allocation strategies for China A-shares and Hong Kong stocks?

Yes, backtesting asset allocation strategies supports China A-shares and Hong Kong stocks alongside US stocks. The system automatically detects multi-market tickers, fetches historical prices, and runs rolling-rebalance backtests with trading costs to evaluate strategy performance.

What is the best way to compare max Sharpe and minimum variance portfolio allocations?

The best way to compare max Sharpe and minimum variance allocations is to generate multiple strategies side by side. The optimizer evaluates max Sharpe, minimum variance, risk parity, maximum diversification, and equal-weight allocations to identify the optimal risk-adjusted split.

What risk metrics are included in portfolio optimization reports?

Portfolio optimization reports include comprehensive risk metrics such as Sharpe ratio, Sortino ratio, Calmar ratio, Value at Risk (VaR), Conditional VaR (CVaR), maximum drawdown, and concentration metrics to provide full risk insight for the allocated portfolio.

How do I set allocation constraints like no single stock above 30% for portfolio optimization?

To set allocation constraints for portfolio optimization, you provide instructions alongside your ticker list, such as specifying no single stock above 30%. The optimizer applies these allocation constraints to the historical price data to calculate optimal weights within your limits.

Does portfolio optimization work with offline CSV price data?

Yes, portfolio optimization works with offline CSV price data as a fallback when network access is unavailable. The system uses a no-API-key fallback chain with online sources first, then seamlessly switches to offline CSV input to ensure continuous data retrieval for backtesting.