matlab-optimize-portfolio
Help users formulate and solve portfolio optimization problems using Financial Toolbox's Portfolio object. Covers mean-variance (Markowitz), maximum Sharpe ratio (tangency), and efficient frontier workflows
Install / Use
npx skills add matlab/matlab-agentic-toolkit --skill matlab-optimize-portfolioInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
AutomationSupported Platforms
Tags
Our assessment of matlab-optimize-portfolio
matlab-optimize-portfolio scores 91/100 on our quality scale, 1059th of 2,848 Automation skills we index (top 38%).
Its SKILL.md is 6.9 KB long, well organised into 13 sections with 6 code examples: a thorough specification that gives an agent plenty to work with.
With 1,098 GitHub stars, it is one of the more widely adopted skills in the catalogue.
Maintenance, license and trust
- The repository was last updated 18 days ago, so matlab-optimize-portfolio is actively maintained.
- No license is declared. By default that means all rights are reserved: you can read it, but reusing or redistributing it is not clearly permitted. Ask the author before building on it commercially.
- Its trust signals score 88/100, with 1 caution from licensing, adoption, age or documentation. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
matlab-optimize-portfolio compared with similar skills
All 4 of these similar skills score higher than matlab-optimize-portfolio; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| matlab-optimize-portfolio (this skill)by matlab | 91 | 1.1k | 18d ago | SKILL.md |
| Agent-Reachby Panniantong | 100 | 89.8k | 18d ago | CLAUDE.md |
| Scraplingby D4Vinci | 100 | 85.4k | today | MCP Server |
| rufloby ruvnet | 100 | 73.8k | today | MCP Server |
| algorithmic-artby anthropics | 100 | 177.9k | 11d ago | SKILL.md |
Frequently asked questions
- How do I install matlab-optimize-portfolio?
- Run
npx skills add matlab/matlab-agentic-toolkit --skill matlab-optimize-portfolio. The install tabs above show the steps for each supported agent. - Which AI agents does matlab-optimize-portfolio work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is matlab-optimize-portfolio safe to use?
- It declares no license and scores 88/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is matlab-optimize-portfolio still maintained?
- The repository was last updated 18 days ago, so matlab-optimize-portfolio is actively maintained.
Skill content
View source on GitHubname: matlab-optimize-portfolio description: Help users formulate and solve portfolio optimization problems using Financial Toolbox's Portfolio object. Covers mean-variance (Markowitz), maximum Sharpe ratio (tangency), and efficient frontier workflows. Use when users ask about portfolio optimization, Markowitz, efficient frontier, Sharpe ratio, or attempt to use generic solvers (quadprog, fmincon, ga, problem-based optimize) for portfolio problems. license: https://www.mathworks.com/content/dam/mathworks/license/pmrl/license.md metadata: author: MathWorks version: "1.0"
Portfolio Optimization with Financial Toolbox
You are helping a user formulate and solve a portfolio optimization problem using MATLAB's Financial Toolbox Portfolio object.
When to Use
- User wants to optimize a portfolio (minimize variance, maximize Sharpe ratio, trace efficient frontier)
- User asks about Markowitz, mean-variance, minimum-variance, or tangency portfolios
- User asks about the efficient frontier or target-return portfolios
- User is trying to use fmincon, quadprog, ga, or problem-based optimize for portfolio optimization (redirect to Portfolio object)
- User asks how to set up constraints for portfolio optimization (bounds, groups, turnover, one-way turnover, cardinality, semicontinuous)
- User asks about mean-variance with cardinality or semi-continuous constraints
- User gets errors from Portfolio, estimateMaxSharpeRatio, estimateFrontier, or related methods
When NOT to Use
- User has a general optimization problem (QP, NLP, MILP) that is NOT financial asset allocation (e.g., filter design, resource allocation, mixture proportions) — use
matlab-solve-optimization - User needs to retrieve market data from Bloomberg, FRED, or Haver Analytics — use
matlab-access-datafeed - User wants to predict returns or portfolio weights using neural networks or ML — use
matlab-train-network - User only wants to clean, explore, or summarize a returns table without optimization — use
matlab-analyze-data - User wants Experiment Manager parameter sweeps (not portfolio frontier) — use
matlab-use-experiment-manager - User wants CVaR, MAD, or other non-mean-variance risk measures — use
PortfolioCVaRorPortfolioMADclasses (not covered by this skill)
Key Principle
Always use the Portfolio class — never let users manually code the optimization with fmincon or quadprog. The toolbox handles solver configuration, constraint management, and frontier computation automatically.
If the user is already attempting a manual solver approach, acknowledge their work, then show how the Portfolio object achieves the same result with less code and fewer pitfalls.
Step 1: Identify the Formulation
Determine which problem the user is trying to solve:
| User wants to... | Formulation | Reference | |------------------|-------------|-----------| | Minimize portfolio risk (no return target) | Mean-variance (min-variance) | formulation-mean-variance.md | | Minimize risk for a given target return | Mean-variance (target-return) | formulation-mean-variance.md | | Trace the efficient frontier | Mean-variance (frontier) | formulation-mean-variance.md | | Maximize risk-adjusted return (Sharpe ratio) | Max Sharpe / tangency | formulation-max-sharpe.md |
Consult the relevant formulation file for problem-specific guidance and methods.
Step 2: Determine What Data the User Has
Ask (if not clear) whether they have:
- A matrix of historical asset returns (or prices that need converting)
- Pre-computed mean returns (mu) and covariance matrix (Sigma)
- A risk-free rate (relevant for Sharpe ratio; defaults to 0 if unspecified)
Step 3: Create the Portfolio Object
See reference-core.md for all creation patterns. The most common:
From return statistics:
p = Portfolio('AssetMean', mu, 'AssetCovar', Sigma);
From historical returns:
p = Portfolio;
p = setAssetMoments(p, mean(returns)', cov(returns));
Step 4: Set Constraints
Always set constraints. At minimum, use default constraints (fully invested, long-only):
p = setDefaultConstraints(p);
For other constraint types (bounds, groups, turnover, one-way turnover, cardinality), see reference-core.md.
Step 5: Solve
Use the method appropriate to the formulation (see the formulation file). Common patterns:
wMinVar = estimateFrontierLimits(p, 'Min'); % minimum-variance
wTarget = estimateFrontierByReturn(p, targetRet); % target-return
wSharpe = estimateMaxSharpeRatio(p); % max Sharpe ratio
wFrontier = estimateFrontier(p, 20); % efficient frontier
Step 6: Analyze and Visualize
Use built-in methods for portfolio statistics — never compute them manually:
portRisk = estimatePortRisk(p, w);
portRet = estimatePortReturn(p, w);
[risk, ret] = estimatePortMoments(p, w);
Always use plotFrontier as the primary frontier visualization — add custom annotations (special portfolios, CAL line) with hold on/hold off afterward:
wFrontier = estimateFrontier(p, 20);
plotFrontier(p, wFrontier);
hold on
[risk, ret] = estimatePortMoments(p, wSpecial);
plot(risk, ret, 'r*', 'MarkerSize', 12);
hold off
Common Pitfalls
- Manual solver usage — quadprog/fmincon for portfolio problems is error-prone; Portfolio handles it.
- Missing constraints — A Portfolio without constraints is underdetermined.
- Redundant solves — Pass weights to
plotFrontier, not a number of portfolios, if you already solved. - Manual risk/return formulas — Use
estimatePortRisk,estimatePortReturn,estimatePortMoments. - Cardinality/semicontinuous constraints — When calling
estimateMaxSharpeRatio, specify'Method','iterative'(MATLAB auto-selects with a warning if omitted, but explicit is cleaner). Frontier methods (estimateFrontier,estimateFrontierLimits,estimateFrontierByReturn) auto-detect these constraints and select the mixed-integer solver internally — do NOT pass'Method','iterative'to them.
Tone
Be direct and practical. Show working MATLAB code. If the user provides data, use their actual data. If not, use a small illustrative example so they can see the pattern and adapt.
Reference Materials
- reference-core.md — Portfolio setup, constraints API, visualization (shared across formulations)
- formulation-mean-variance.md — Min-variance, target-return, efficient frontier
- formulation-max-sharpe.md — Max Sharpe ratio / tangency portfolio
- examples.md — Complete runnable examples for all formulations
Copyright 2026 The MathWorks, Inc.
Related Skills
Agent-Reach
89.8kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
Scrapling
85.4k🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev
ruflo
73.8k🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
