lean-mean-variance

lean-mean-variance is a skill for Claude Code from Travisun/Opptrix. It costs 98 tokens per session (1,401 once invoked), scanned A, original, Apache-2.0.

A portfolio-allocation workflow based on the mean-variance idea, a method that balances expected return against risk across several investments. It uses explicit assumptions and is adapted for Chinese stocks and exchange-traded funds.

In plain words
What is it for?
Use it to explore target weights or an efficient-frontier chart for a defined basket, subject to stated return, risk, and long-only assumptions.
Why use it?
It shows how different return and risk assumptions affect portfolio weights, without presenting them as proven or automatically optimal. It also highlights estimation errors, short samples, and market constraints such as price limits and no free short selling.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Good fit Use it to explore target weights or an efficient-frontier chart for a defined basket, subject to stated return, risk, and long-only assumptions.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/travisun/opptrix/lean-mean-variance
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Travisun/Opptrix --skill lean-mean-variance
Clone the repo
git clone --depth 1 https://github.com/Travisun/Opptrix

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for lean-mean-variance

README.md
[![agentmods](https://agentmods.dev/badge/skills/travisun/opptrix/lean-mean-variance.svg)](https://agentmods.dev/skills/travisun/opptrix/lean-mean-variance)
Your own site
<a href="https://agentmods.dev/skills/travisun/opptrix/lean-mean-variance"><img src="https://agentmods.dev/badge/skills/travisun/opptrix/lean-mean-variance.svg" alt="Measured on agentmods" height="20"></a>
Per session 98 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,401 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00098 $0.01401
Opus 5 $0.00049 $0.00700
Sonnet 5 $0.00020 $0.00280
Haiku 4.5 $0.00010 $0.00140

Measured 4d ago against content hash 170f8b8cbf83, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

lean-mean-variance scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

packages/agent-skills/builtin/lean-mean-variance/SKILL.md · 87 lines

What it actually says

LEAN 均值方差

方法溯源 QuantConnect LEAN / 经典马科维茨框架在算法交易中的组合优化思路;本技能为 assumption-only 权重框架,禁止假装跑完整 LEAN 引擎

何时使用

用户要在 A股/场内 ETF 篮子上、在显式预期收益与风险假设下得到均值方差型目标权重或有效前沿示意(LEAN 方法溯源,非美股原版照搬)。

边界:等权用 @skill:lean-equal-weight-pcm;风险平价用 @skill:lean-risk-parity;已有目标只算差额用 @skill:rebalance。默认交付网页。

A股适配(默认)

  • 默认市场 CN(A股 / 场内 ETF)。用户点名美股/港股再切换,并声明数据口径与微观结构差异。
  • 默认 CN 持仓/候选池协方差估计;涨跌停截断收益分布。
  • 有效前沿默认 仅多头约束(禁止自由做空权重)。
  • 不可硬适配或数据缺口时:首页横幅写清完整度(partial 或更严)+ 必要时 ask_user

分析架构(投研方法)

  • 问题/假设:在约定收益向量与协方差下,目标权重如何?对假设敏感吗?
  • 证据清单:历史收益样本(事实)、预期收益/约束(假设)、「最优」标签(推断,须降级措辞)
  • 多维交叉验证:权重和、边界约束;扰动收益假设看权重漂移
  • 结论与不确定:估计误差大;样本外易崩
  • 风险与缺口:用户拒给预期、样本过短、奇异协方差
  • 微观/制度风险:涨跌停钝化、T+1、ST/停牌、融券受限(及相关会计口径差异);不得按美股连续可成交或自由做空假设叙事
  • 事实 | 假设 | 推断 分栏强制

数据维度

维度 取数方向 缺失时
成分 ask_user / search_instruments 先确认
价格序列 get_instrument_chart / 批量 无法估协方差则 not-feasible
预期收益 ask_user(必填或明确用历史均值并标假设) 禁止假装「市场共识收益」
约束 ask_user 按无约束并说明
现持仓对照 get_portfolio_holdings 可选
计算 opptrix_run + workspace_write 手工示意并标局限
交付 list_web_vendorcreate_web 可跳过口头要点
A股组合约束 CN 收益协方差;多头约束优化 样本不足则降维/缩小池

步骤

  1. 确认默认 CN:标的/宇宙为 A股或场内 ETF(用户点名其他市场再切换并声明差异)。应用涨跌停/T+1/融券受限等微观约束(见 A股适配)。
  2. 确认成分、约束与收益假设来源(历史均值 vs 用户观点)。
  3. 声明非 LEAN Runtime / assumption-only
  4. 估计或录入协方差与收益向量;不可行则诚实降级。
  5. 求解权重并做至少一组敏感性。
  6. 分栏结论 → 默认 create_web

网页报告建议目录

  1. 范围:默认 A股/场内 ETF + LEAN 溯源
  2. 显式假设表(收益、协方差窗口、约束)
  3. 目标权重结果(模型输出)
  4. 敏感性与估计误差
  5. 事实 / 假设 / 推断
  6. 与等权/风险平价对照(可选)
  7. A股适配与限制(默认 CN;微观结构/代理/完整度)
  8. 免责声明(非投资建议;非下单)

禁止

  • 荐股;把优化权重写成「应买入」
  • 禁止假装跑完整 LEAN 引擎
  • 禁止假装共识预期收益
  • 禁止无交付就结束(默认 web)
  • 无假设表就宣称「最优组合」
  • 禁止把美股成分/ETF 清单不经映射直接当 A股结果
  • 禁止假设可自由融券做空
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 87 lines · 98 tokens per session scan A 170f8b8cbf83

Subscribe to this mod's changes

lean-mean-variance is a skill published in the GitHub repository Travisun/Opptrix (230 stars, last pushed yesterday), licensed Apache-2.0. It adds 98 tokens to every session and 1,401 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

national-team-position

A Chinese-language analysis tool that estimates changes in China’s government-backed ETF holdings by tracking ETF share counts and related index prices. ETFs are funds traded on stock exchanges, and the “national team” refers here to Central Huijin, a state investment company.

Xiaoyuan-Liu/national-team-position · 161 tokens

caijing-ipo-hk

A Chinese-language adviser for Hong Kong stock initial public offerings, or IPOs—the first sale of a company's shares to the public. It covers how to apply, how much to apply for, and risks such as the share price falling below the offering price.

nekopunch11/rodya-caijing-studio · 209 tokens

caijing-fundamental

A finance research skill for writing a detailed, forward-looking analysis of a listed company’s business, financials, valuation, risks, and investment arguments. It covers companies listed in mainland China and Hong Kong.

nekopunch11/rodya-caijing-studio · 188 tokens

rodya-caijing-studio

A toolkit for researching Chinese A-share and Hong Kong-listed companies and producing financial content. It includes separate workflows for company fundamentals, earnings, valuation, risks, industries, and IPO checks.

nekopunch11/rodya-caijing-studio · 171 tokens

caijing-earnings

A finance research skill for reviewing listed companies’ earnings reports, or preparing for an upcoming report. It focuses on Chinese A- and Hong Kong-listed companies.

nekopunch11/rodya-caijing-studio · 215 tokens

caijing-valuation

A Chinese-language adviser that assesses whether a stock's current valuation looks high or low. It adapts the comparison to the industry and examines historical and peer-company valuation ranges.

nekopunch11/rodya-caijing-studio · 161 tokens