executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
matlab-optimize-portfolioHelp 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,…
Independent GitHub snapshot · Automated classification · Original documentation governs
You are helping a user formulate and solve a portfolio optimization problem using MATLAB's Financial Toolbox Portfolio object.
matlab-solve-optimizationmatlab-access-datafeedmatlab-train-networkmatlab-analyze-datamatlab-use-experiment-managerPortfolioCVaR or PortfolioMAD classes (not covered by this skill)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.
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.
Ask (if not clear) whether they have:
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));
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.
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
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
plotFrontier, not a number of portfolios, if you already solved.estimatePortRisk, estimatePortReturn, estimatePortMoments.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.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.
Copyright 2026 The MathWorks, Inc.