Agent skill

Diversification

by JoelLewis in JoelLewis/finance_skills

Build diversified portfolios using correlation analysis, efficient frontier construction, and factor-based diversification.

MITAuto-check passedBusiness, Finance & HR

Install Diversification

skills CLI
$ npx skills add JoelLewis/finance_skills --skill diversification -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install JoelLewis/finance_skills diversification --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/JoelLewis/finance_skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/wealth-management/skills/diversification .claude/skills/diversification && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
diversification
GitHub stars
205
Token cost
~2.3k tokens
SKILL.md length
993 words
Files
2 (incl. scripts)
Skills in repo
91
Repo updated
First seen
Licence
MIT

At a glance

Build diversified portfolios using correlation analysis, efficient frontier construction, and factor-based diversification.

  • The user asks about portfolio variance
  • SKILL.md covers Core Concepts, Key Formulas, Worked Examples and Common Pitfalls, plus 2 more sections
  • Runs Python scripts from its folder; calls uv, python3 and python
  • Correlation effects

What it does

Diversification is an agent skill from JoelLewis/finance_skills. Build diversified portfolios using correlation analysis, efficient frontier construction, and factor-based diversification. Use when the user asks about portfolio variance, correlation effects, the efficient frontier, minimum variance portfolios, diversification ratios, or factor diversification. Also trigger when users mention 'don't put all eggs in one basket', 'how many stocks do I need', 'correlation breakdown in a crisis', 'are my holdings really diversified', 'risk contributions', or ask why diversification…

Its SKILL.md is about 2.3k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files, including scripts (for example `scripts/diversification.py`).

It sits in Business, Finance & HR. The repository describes itself as: Claude Code skill plugins for financial services — 81 skills across 7 domain plugins covering investment management, compliance, advisory practice, trading, and operations. The licence is MIT.

When your agent uses it

  • The user asks about portfolio variance
  • Correlation effects
  • The efficient frontier
  • Minimum variance portfolios

Example prompts

  • “t put all eggs in one basket”
  • “how many stocks do I need”
  • “correlation breakdown in a crisis”
  • “/diversification”

Requirements

  • Python 3

What it can do on your machine

Read from SKILL.md and the folder at commit 5c498ea. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (Python), which the agent can run.

    Shell commands in SKILL.md call:

    • uv
    • python3
    • python

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use uv, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Diversification loads about 2.3k tokens when it runs. Until then it costs about 141 tokens; SKILL.md has 993 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~141
When it runs · the whole SKILL.md, loaded when a task matches
~2.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from JoelLewis/finance_skills at commit 5c498ea, republished under its MIT licence (© JoelLewis). 993 words, ~2,266 tokens.

Download SKILL.mdSave it as .claude/skills/diversification/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
diversification
description
Build diversified portfolios using correlation analysis, efficient frontier construction, and factor-based diversification. Use when the user asks about portfolio variance, correlation effects, the efficient frontier, minimum variance portfolios, diversification ratios, or factor diversification. Also trigger when users mention 'don't put all eggs in one basket', 'how many stocks do I need', 'correlation breakdown in a crisis', 'are my holdings really diversified', 'risk contributions', or ask why diversification fails during market crashes.

Diversification

Core Concepts

Portfolio Variance (2 Assets)

For a portfolio of two assets with weights w_1 and w_2, volatilities sigma_1 and sigma_2, and correlation rho_12:

sigma^2_p = w_1^2 * sigma_1^2 + w_2^2 * sigma_2^2 + 2 * w_1 * w_2 * sigma_1 * sigma_2 * rho_12

Diversification benefit arises whenever rho_12 < 1, because the portfolio volatility will be less than the weighted average of individual volatilities.

Portfolio Variance (n Assets)

In matrix notation for n assets with weight vector w and covariance matrix Sigma:

sigma^2_p = w' * Sigma * w

This generalizes to any number of assets and captures all pairwise correlations.

Diversification Benefit

Portfolio volatility is strictly less than the weighted average of individual volatilities whenever any pairwise correlation is below 1:

sigma_p < Sigma(w_i * sigma_i) when rho_ij < 1 for some i,j

The lower the average correlation, the greater the diversification benefit.

Efficient Frontier

The efficient frontier is the set of portfolios that offer the highest expected return for each level of risk (or equivalently, the lowest risk for each level of return). Portfolios below the frontier are suboptimal — they can be improved by reallocating weights.

Minimum Variance Portfolio

The portfolio with the lowest possible volatility, regardless of expected returns:

w_mv = Sigma^(-1) * 1 / (1' * Sigma^(-1) * 1)

where 1 is a vector of ones. This portfolio depends only on the covariance matrix, not on expected returns, making it more robust to estimation error.

Correlation Regimes

Correlations are not constant. In market crises, correlations between risky assets tend to increase sharply ("correlation breakdown" or "correlation tightening"), reducing the diversification benefit precisely when it is needed most. Key implications:

  • Stress-test portfolios using crisis-period correlation matrices
  • Diversification across asset classes (stocks, bonds, commodities, real assets) is more robust than within-asset-class diversification
Diversification Ratio

A measure of how much diversification a portfolio achieves:

DR = (Sigma(w_i * sigma_i)) / sigma_p

A portfolio of perfectly correlated assets has DR = 1. Higher DR indicates more effective diversification. A fully diversified equal-volatility portfolio with zero correlations has DR = sqrt(n).

Maximum Diversification Portfolio

The portfolio that maximizes the diversification ratio. This is an alternative to mean-variance optimization that does not require expected return inputs — it relies only on volatilities and correlations.

Factor Diversification

True diversification means exposure to multiple independent risk factors, not merely holding many assets. Assets that share the same factor exposures (e.g., multiple tech stocks all driven by growth factor) provide less diversification than their number suggests. Key factors:

  • Market, size, value, momentum, quality, low volatility
  • Interest rate, credit, inflation
  • Geographic, sector, currency
Risk Contribution

The risk contribution of asset i to portfolio volatility:

RC_i = w_i * (Sigma * w)_i / sigma_p

where (Sigma * w)_i is the i-th element of the vector Sigma * w. The sum of all risk contributions equals the portfolio volatility. This decomposition reveals which assets truly drive portfolio risk.

Marginal Risk Contribution

The rate of change of portfolio volatility with respect to the weight of asset i:

MRC_i = (Sigma * w)_i / sigma_p

Risk contribution = weight * marginal risk contribution: RC_i = w_i * MRC_i

Diminishing Marginal Diversification

The diversification benefit of adding assets decreases rapidly. Empirically:

  • 15-20 uncorrelated assets capture most of the diversification benefit
  • Beyond 30 assets, incremental risk reduction is minimal
  • The asymptotic portfolio variance equals the average covariance (systematic risk cannot be diversified away)

Key Formulas

FormulaExpressionUse Case
2-Asset Portfolio Variancesigma^2_p = w_1^2sigma_1^2 + w_2^2sigma_2^2 + 2w_1w_2sigma_1sigma_2*rho_12Two-asset risk calculation
n-Asset Portfolio Variancesigma^2_p = w' * Sigma * wGeneral portfolio risk
Minimum Variance Weightsw_mv = Sigma^(-1)*1 / (1'*Sigma^(-1)*1)Lowest-risk portfolio
Diversification RatioDR = Sigma(w_i*sigma_i) / sigma_pMeasure of diversification
Risk ContributionRC_i = w_i * (Sigma*w)_i / sigma_pAsset-level risk attribution
Marginal Risk ContributionMRC_i = (Sigma*w)_i / sigma_pSensitivity of risk to weight
Asymptotic Variancesigma^2_p → avg(cov_ij) as n → infinityDiversification limit

Worked Examples

Show full SKILL.md (397 more words)Show less
Example 1: Two-Asset Portfolio Volatility

Given:

  • Stock: sigma = 20%, weight = 60%
  • Bond: sigma = 5%, weight = 40%
  • Correlation: rho = 0.2

Calculate: Portfolio volatility

Solution:

sigma^2_p = (0.60)^2 * (0.20)^2 + (0.40)^2 * (0.05)^2 + 2 * (0.60) * (0.40) * (0.20) * (0.05) * (0.20)

sigma^2_p = 0.36 * 0.04 + 0.16 * 0.0025 + 2 * 0.60 * 0.40 * 0.20 * 0.05 * 0.20

sigma^2_p = 0.0144 + 0.0004 + 0.00096

sigma^2_p = 0.01576

sigma_p = sqrt(0.01576) = 0.1255 = 12.55%

Weighted average volatility = 0.60 * 20% + 0.40 * 5% = 14.0%

Diversification benefit = 14.0% - 12.55% = 1.45 percentage points of risk reduction.

Example 2: Diversification Ratio for a 4-Asset Portfolio

Given:

  • Assets: A (sigma=15%, w=25%), B (sigma=20%, w=25%), C (sigma=10%, w=25%), D (sigma=18%, w=25%)
  • Portfolio volatility (computed from full covariance matrix): sigma_p = 10.5%

Calculate: Diversification ratio

Solution:

Weighted average volatility = 0.2515% + 0.2520% + 0.2510% + 0.2518% = 3.75% + 5.0% + 2.5% + 4.5% = 15.75%

Diversification Ratio = 15.75% / 10.5% = 1.50

Interpretation: The portfolio achieves significant diversification — the weighted average volatility is 50% higher than the actual portfolio volatility. A DR of 1.50 indicates meaningful correlation benefits. For comparison, a portfolio of perfectly correlated assets would have DR = 1.0.

Common Pitfalls

  • Diversification is not just about holding more assets — correlation structure is what matters; 50 highly correlated stocks provide less diversification than 10 uncorrelated ones
  • Correlations are unstable and tend to increase during market stress, reducing the diversification benefit precisely when it is most needed
  • Over-diversification (diworsification): holding too many positions dilutes high-conviction ideas and guarantees mediocre returns after costs
  • Home country bias: investors systematically under-allocate to international assets, missing a major source of diversification
  • Confusing asset diversification with factor diversification: a portfolio of 20 growth stocks is not diversified despite holding many names
  • Using historical correlations without testing sensitivity to regime changes

Cross-References

  • historical-risk (wealth-management plugin): volatility, correlation, and systematic vs. idiosyncratic risk foundations
  • asset-allocation (wealth-management plugin): diversification principles feed directly into portfolio construction and optimization
  • rebalancing (wealth-management plugin): maintaining diversification targets over time through rebalancing
  • bet-sizing (wealth-management plugin): position sizing interacts with diversification — concentrated vs. diversified approaches
  • equity-compensation (wealth-management plugin): concentrated employer stock from RSUs, options, and ESPPs is a common source of single-stock concentration requiring staged diversification
  • factor-investing (wealth-management plugin): diversifying across factor premia (value, momentum, quality) as a layer distinct from asset-class diversification

Running the Script

bash
uv run scripts/diversification.py            # run the demo (uses PEP 723 inline deps)
uv run scripts/diversification.py --verify   # check demo outputs against the worked examples (exit 1 on mismatch)
python3 scripts/diversification.py            # alternative (requires: pip install numpy)

The demo prints the calculations covered above; its values match the worked examples in this skill. Run --help for a list of the classes and functions. For programmatic use, import the module rather than running it — the demo only executes under python diversification.py.

© JoelLewis, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file (scripts) in plugins/wealth-management/skills/diversification of JoelLewis/finance_skills.

  • SKILL.md
  • scripts/diversification.py

Open the folder on GitHubat commit 5c498ea

Compare with similar skills

Diversification next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Diversification compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Diversification this skillJoelLewis/finance_skills205—~2.3kAutomated safety check: PassMIT
Technical Analysttradermonty/claude-trading-skills3k5 repos~4.6kAutomated safety check: PassMIT
Creating Financial ModelsChen-zexi/open-ptc-agent7294 repos~1.3kAutomated safety check: PassMIT
Stock APIzhangxiangliang/stock-api2k—~507Automated safety check: PassMIT
Theme Detectortradermonty/claude-trading-skills3k2 repos~4.9kAutomated safety check: PassMIT
Itr Walakaranb192/itr-wala871—~3.6kAutomated safety check: PassMIT

Similar skills

  • Technical Analyst

    tradermonty/claude-trading-skills

    This skill should be used when analyzing weekly price charts for stocks, stock indices, cryptocurrencies, or forex pairs.

    3k GitHub starsUsed in 5 repos~4.6k tokens
    Business, Finance & HRAuto-check passed
  • Creating Financial Models

    Chen-zexi/open-ptc-agent

    This skill provides an advanced financial modeling suite with DCF analysis, sensitivity testing, Monte Carlo simulations, and scenario planning for investment decisions

    729 GitHub starsUsed in 4 repos~1.3k tokens
    Business, Finance & HRAuto-check passed
  • Stock API

    zhangxiangliang/stock-api

    Fetch real-time stock quotes, K-line (candlestick) history, and search symbols for China A-shares, Hong Kong, and US markets.

    2k GitHub stars~507 tokensUpdated today
    Business, Finance & HRAuto-check passed
  • Theme Detector

    tradermonty/claude-trading-skills

    Detect and analyze trending market themes across sectors. An agent skill from tradermonty/claude-trading-skills.

    3k GitHub starsUsed in 2 repos~4.9k tokens
    Business, Finance & HRAuto-check passed
  • Itr Wala

    karanb192/itr-wala

    File Indian income tax returns (ITR) for FY 2025-26 / AY 2026-27.

    871 GitHub stars~3.6k tokensUpdated 4 days ago
    Business, Finance & HRAuto-check passed
  • Tushare Data

    zillionare/zillionare

    面向中文自然语言的 Tushare 数据研究技能。用于把“看看这只股票最近怎么样”“帮我查财报趋势”“最近哪个板块最强”“北向资金在买什么”“给我导出一份行情数据”这类请求,转成可执行的数据获取、清洗、对比、筛选、导出与简要分析流程。适用于 A 股、指数、ETF/基金、财务、估值、资金流、公告新闻、板块概念与宏观数据等研究场景。

    319 GitHub starsUsed in 2 repos~2.3k tokens
    Business, Finance & HRAuto-check passed

More from JoelLewis/finance_skills

All 91 skills in this repo
  • Equities

    JoelLewis/finance_skills

    Analyze equity securities, factor models, and equity portfolio construction.

    205 GitHub starsUsed in 1 repo~2.2k tokens
    Auto-check passed
  • Asset Allocation

    JoelLewis/finance_skills

    Determine how to distribute capital across asset classes using strategic and tactical allocation frameworks.

    205 GitHub stars~2.5k tokensUpdated 2 mo ago
    Auto-check passed
  • Bet Sizing

    JoelLewis/finance_skills

    Determine how much capital to allocate to individual positions within a portfolio.

    205 GitHub stars~2.5k tokensUpdated 2 mo ago
    Auto-check passed
  • Commodities

    JoelLewis/finance_skills

    Analyze commodity markets including futures curve dynamics, roll yield, and supply/demand fundamentals.

    205 GitHub stars~1.9k tokensUpdated 2 mo ago
    Auto-check passed
  • Currencies And Fx

    JoelLewis/finance_skills

    Analyze currency markets, exchange rate mechanics, and FX risk management for international portfolios.

    205 GitHub stars~1.9k tokensUpdated 2 mo ago
    Auto-check passed
  • Debt Management

    JoelLewis/finance_skills

    Provide frameworks for managing and paying off personal debt effectively.

    205 GitHub stars~2.5k tokensUpdated 2 mo ago
    Auto-check passed

Questions about Diversification

What does Diversification do?

Build diversified portfolios using correlation analysis, efficient frontier construction, and factor-based diversification. Diversification is an agent skill from JoelLewis/finance_skills. Build diversified portfolios using correlation analysis, efficient frontier construction, and factor-based diversification.

When should I use Diversification?

Diversification fits situations like: the user asks about portfolio variance; correlation effects; the efficient frontier; minimum variance portfolios.

How do I install Diversification in Claude Code?

Run `npx skills add JoelLewis/finance_skills --skill diversification -a claude-code`. Or copy the skill folder (plugins/wealth-management/skills/diversification in JoelLewis/finance_skills) into .claude/skills/diversification in your project. Claude Code loads it when a task matches its description.

How do I install Diversification in Codex?

Run `npx skills add JoelLewis/finance_skills --skill diversification -a codex`. Or copy the skill folder (plugins/wealth-management/skills/diversification in JoelLewis/finance_skills) into .agents/skills/diversification in your project. Codex loads it when a task matches its description.

Can I use Diversification in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add JoelLewis/finance_skills --skill diversification -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/diversification, .gemini/skills/diversification, .github/skills/diversification and .opencode/skills/diversification in your project.

What does Diversification need to run?

Going by SKILL.md and its folder, Diversification needs Python for the scripts in its folder and the command-line tools its instructions call (uv, python3 and python). Our summary lists: Python 3.

Does Diversification access the network?

SKILL.md contains no URLs. Its commands use uv, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Diversification safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Diversification use?

Diversification is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Diversification use?

About 2.3k tokens (SKILL.md is roughly 9.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Diversification?

Skills that share tags, products or a category with Diversification: Technical Analyst (tradermonty/claude-trading-skills, 3k stars), Creating Financial Models (Chen-zexi/open-ptc-agent, 729 stars), Stock API (zhangxiangliang/stock-api, 2k stars) and Theme Detector (tradermonty/claude-trading-skills, 3k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Diversification?

JoelLewis (a GitHub user) maintains it in JoelLewis/finance_skills, which has 205 GitHub stars. The repository holds 91 skills in this directory. The repository was last updated on July 18, 2026.

Source: JoelLewis/finance_skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.