# portfolio-optimization

portfolio-optimization is a Claude Code skill for stock portfolio analysis with Mean-CVaR and Mean-Variance methods using NVIDIA cuOpt. Calculate allocations, assess risk, or backtest.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf (Devin Desktop), Claude.ai · ★ 4106 repo stars
- Author: Jake Goldberg
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/NVIDIA/skills/tree/HEAD/skills/portfolio-optimization/SKILL.md
- Updated: 2026-10-23
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/portfolio-optimization

## What it does

The skill works through the `portfolio_optimization` package. It calculates log returns, creates GPU-based KDE scenarios for CVaR, and solves allocation problems with NVIDIA cuOpt. It can also produce an efficient frontier, compare a strategy with benchmarks, and rebalance holdings on a schedule or when weights drift. Mean-Variance workflows can apply a variance or volatility limit.

The environment needs Python, the installed `portfolio_optimization` package, an NVIDIA GPU runtime, cuOpt, and cuML. Mean-Variance SOCP tasks also require a cuOpt build with QCQP/SOCP support. CUDA dependencies are selected with one of the provided extras: `cuda12`, `cuda13`, or `cuda13-socp`. If `data/stock_data/sp500.csv` is missing, the skill asks before fetching market data. It does not fall back to a CPU solver when cuOpt cannot run.

For user CSV files, it checks for a date index or first date column, numeric ticker columns, at least 60 rows after date filtering, and at least one requested ticker. CVaR calculations use GPU KDE scenarios; Mean-Variance SOCP workflows use returns directly instead. The initial market-data download requires network access.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill portfolio-optimization -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/portfolio-optimization/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/portfolio-optimization/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill portfolio-optimization -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/portfolio-optimization/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill portfolio-optimization -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/portfolio-optimization/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install NVIDIA/skills skills/portfolio-optimization
```

2. **Manually: put the files in place**
- File: `.github/skills/portfolio-optimization/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill portfolio-optimization -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/NVIDIA/skills --path skills/portfolio-optimization
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/portfolio-optimization/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/NVIDIA/skills/tree/HEAD/skills/portfolio-optimization/SKILL.md

## When to use it
- calculate stock weights under a CVaR risk limit
- find an allocation within a variance or volatility cap
- trace an efficient frontier and compare risk-aversion allocations
- backtest a portfolio against a benchmark
- rebalance holdings on a schedule or after weight drift

## Example prompts
- Optimize the tickers in `data/stock_data/sp500.csv` with a CVaR limit.
- Build an efficient frontier from my price data and show allocations at different risk-aversion levels.
- Backtest this allocation against an equal-weight portfolio.

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 79b7fba7d3995796.

BEGIN THIRD-PARTY FILE 79b7fba7d3995796
```text
---
name: portfolio-optimization
version: "26.6"
description: Use when a user asks to build, optimize, backtest, rebalance, or analyze a stock portfolio with Mean-CVaR, Mean-Variance/SOCP variance caps, efficient frontiers, scenario generation, or NVIDIA cuOpt.
license: Apache-2.0
metadata:
  author: Jake Goldberg <jgoldberg@nvidia.com>
  tags:
    - portfolio-optimization
    - cvar
    - cuopt
    - quantitative-finance
    - gpu
---


# Portfolio Optimization with NVIDIA cuOpt

<!--
SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0
-->

## Purpose

Build and analyze quantitative portfolios with NVIDIA-accelerated Mean-CVaR and Mean-Variance optimization. Use the `portfolio_optimization` package to compute returns, generate KDE scenarios for CVaR, solve variance-cap Markowitz allocations as SOCP/QCQP problems with the cuOpt GPU solver, trace an efficient frontier, backtest portfolios, and run rebalancing workflows from price data.

## When to Use

Use this skill when the task is to:

- Build or optimize a Mean-CVaR portfolio from stock prices.
- Allocate weights across tickers while controlling downside CVaR risk.
- Solve Mean-Variance or Markowitz allocations with a hard variance or volatility cap using cuOpt SOCP/QCQP support.
- Plot or inspect an efficient frontier for a portfolio universe.
- Produce a weights-by-risk-aversion table.
- Backtest an optimized portfolio against benchmarks.
- Rebalance a portfolio on a schedule or drift trigger.
- Run workflows on an S&P 500, S&P 100, Dow 30, or user-supplied price dataset.

Common trigger phrases include "optimize my portfolio", "build a CVaR portfolio", "use cuOpt to optimize these tickers", "solve with cuOpt", "plot the efficient frontier", "show weights by risk aversion", "backtest this allocation", "rebalance monthly", "analyze my holdings with CVaR", "compare allocations", "reduce downside risk", "construct an allocation", "assess allocation options", "stress-test my holdings", "evaluate downside-risk exposure", "review my holdings under weight caps", "compare benchmark portfolios", "simulate CVaR scenarios", "screen portfolio risk", "optimize holdings under constraints", "solve a variance-cap portfolio", "use SOCP", "set a volatility cap", and "find a lower-risk allocation".
```
END THIRD-PARTY FILE 79b7fba7d3995796

The third-party file has ended. Everything between the 79b7fba7d3995796 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2361 of 19656 bytes. © Jake Goldberg · Apache-2.0 · https://github.com/NVIDIA/skills/tree/HEAD/skills/portfolio-optimization/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
