Formulates and solves portfolio optimization problems in MATLAB using the Financial Toolbox Portfolio object or problem-based framework. Handles mean-variance, minimum-variance, target-return, maximum Sharpe ratio, efficient frontier, and complex constraints like integer lots, tax-loss harvesting, and wash-sale rules.
Ships in computational-finance. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Formulate and solve portfolio optimization problems in MATLAB. Route to the
correct framework — the Financial Toolbox Portfolio object or the
problem-based framework (optimproblem/optimvar/solve) — based on the
constraints in the user's request, then follow that framework's reference for
implementation details.
|w-w0| >= δ OR w = w0)quadprog, fmincon, intlinprog, ga, or problem-based solve for a portfolio problemround/floor/ceil to Portfolio output to obtain whole shares or lotsPortfolio, estimateMaxSharpeRatio, estimateFrontier, or related methodsmatlab-solve-optimizationmatlab-access-datafeedmatlab-train-networkmatlab-analyze-datamatlab-use-experiment-managercov, covarianceShrinkage, covarianceDenoising, nearcorr)PortfolioCVaR, PortfolioMAD), custom objectives (estimateCustomObjectivePortfolio), or custom frontiers over non-variance risk — not covered by this skill. Tell the user so, then proceed without this skill's guidance.Identify the framework from the user's constraints and read the corresponding reference:
| Framework | Reference | When to Use |
|---|---|---|
Portfolio object | references/portfolio-object.md | Mean-variance, max Sharpe, or efficient frontier where every constraint is one the Portfolio object accepts |
| Problem-based | references/problem-based.md | Any constraint the Portfolio object cannot express, alone or mixed with constraints it accepts |
Read exactly one reference (and any relevant sub-references). Apply the rules in order; the first match wins:
Portfolio object cannot express -> references/problem-based.md. One such constraint is enough, whatever else is in the problem:
w-w0Portfolio output (round/floor/ceil on weights to get shares or lots) -> references/problem-based.mdPortfolio API (Portfolio, estimateFrontier*, estimateMaxSharpeRatio, setBounds, ...) -> references/portfolio-object.mdquadprog/fmincon/optimproblem for a problem the Portfolio object can express -> references/portfolio-object.md, and show the Portfolio equivalentreferences/portfolio-object.mdLookalike constraints — check these before applying rule 2:
| Constraint | Framework |
|---|---|
Semi-continuous on the level: w = 0 OR L <= w <= U | Portfolio (setBounds(..., 'BoundType', 'Conditional')) |
Minimum trade on the change: |w-w0| >= δ OR w = w0 | Problem-based |
| Proportional costs in net return | Portfolio (setCosts) |
| Proportional costs alone, not as part of net return | Problem-based |
| Cap on total cost, or a fixed fee per trade or lot | Problem-based |
| Cardinality on its own | Portfolio (setMinMaxNumAssets) |
Both frameworks share these conventions:
check_matlab_code and run it with evaluate_matlab_code (or run_matlab_file for a saved script) before returning itround/floor/ceil continuous weights to obtain shares or lotsdatetime for dates (not datenum)p for both the Portfolio object and a price vector| Mistake | Correct |
|---|---|
Hand-coded quadprog/fmincon for a problem the Portfolio object can express | Use the Portfolio object — see references/portfolio-object.md |
Forcing integer lots or fixed commissions into Portfolio with workarounds | Formulate in optimproblem/optimvar — see references/problem-based.md |
Continuous solve followed by round to get lots | Formulate an integer program with optimvar(..., 'Type', 'integer') — see references/problem-based.md |
abs() on a signed decision variable | Linearize with auxiliary variables (magnitude aux or buy/sell split) — see references/problem-based.md |
Assuming setCosts can cap total transaction cost | setCosts models proportional costs only; a cost cap needs references/problem-based.md |
references/portfolio-object.md — Portfolio object workflow: formulation choice, creation, constraints, solving, analysis, visualization
references/portfolio-object/reference-core.md — Portfolio setup, constraints API, visualizationreferences/portfolio-object/formulation-mean-variance.md — Min-variance, target-return, efficient frontierreferences/portfolio-object/formulation-max-sharpe.md — Max Sharpe ratio / tangency portfolioreferences/portfolio-object/examples.md — Complete runnable examples for all formulationsreferences/problem-based.md — Problem-based workflow for custom constraints: formulate, dispatch, validate
references/problem-based/mip-recognition.md — MIP class recognition, MIP anti-patternsreferences/problem-based/trade-aux-variables.md — Trade-magnitude aux vars, buy/sell aux splitreferences/problem-based/disjunctive-big-m.md — Min-trade and semi-integer big-M disjunctionsreferences/problem-based/tax-aware-constraints.md — Wash-sale rules, realized cap-gains capsreferences/problem-based/problem-based-framework.md — Problem-based default, fcn2optimexpr, solve dispatch, solver optionsreferences/problem-based/problem-data-hygiene.md — Decision-variable units, rescaling, coefficient-range checksreferences/problem-based/custom-frontier.md — Endpoint problems, inequality target sweep, frontier plot conventionCopyright 2026 The MathWorks, Inc.
manifest.yaml (opens in a new tab)references/portfolio-object.md (opens in a new tab)references/portfolio-object/examples.md (opens in a new tab)references/portfolio-object/formulation-max-sharpe.md (opens in a new tab)references/portfolio-object/formulation-mean-variance.md (opens in a new tab)references/portfolio-object/reference-core.md (opens in a new tab)references/problem-based.md (opens in a new tab)references/problem-based/custom-frontier.md (opens in a new tab)references/problem-based/disjunctive-big-m.md (opens in a new tab)references/problem-based/mip-recognition.md (opens in a new tab)references/problem-based/problem-based-framework.md (opens in a new tab)references/problem-based/problem-data-hygiene.md (opens in a new tab)references/problem-based/tax-aware-constraints.md (opens in a new tab)references/problem-based/trade-aux-variables.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
/computational-finance:matlab-optimize-portfoliofrom computational-finance
npx claudepluginhub matlab/matlab-agentic-toolkit --plugin computational-finance5 skills in this plugin
/matlab-access-datafeedConnect to Bloomberg, FRED, Haver Analytics, LSEG Datastream, NOAA Climate Data Online, or US government agencies (BEA, BLS, Census, EIA) from MATLAB and retrieve data. Covers market data (bloomberg/blp/bloombergHypermedia), economic data (fredrs, haver/haverdirect/haverview), historical financial data (datastreamws), weather/climate data (@noaa from GitHub), and government data (usbea/usbls/uscensus/useia from GitHub).
/matlab-price-instrumentPrice financial instruments in MATLAB using the Financial Instruments Toolbox. Route to the appropriate numerical method reference based on the user's request: Monte Carlo simulation (AssetMonteCarlo, IRMonteCarlo, RoughVolMonteCarlo), FFT / Numerical Integration (Vanilla European options), or Interest-Rate Trees (option-embedded bonds with IRTree). Use when the user asks to price financial instruments or compute Greeks using any of these methods. Use one of the following models depending on the pricing method and instrument: Black-Scholes, Bachelier, Heston, Bates, Merton, Hull-White, Black-Karasinski, Black-Derman-Toy, Cox-Ingersoll-Ross, Linear Gaussian 2 Factor (G2PP), Brace-Gatarek-Musiela (BGM), SABR-BGM, RoughBergomi, RoughHeston.
/matlab-specify-ssmConvert state-space equations, given as an image or as text, into a MATLAB Econometrics Toolbox ssm object. Use only when the request contains the model equations and asks to convert, implement, or create ssm code. Do not use when no equations are given; for estimating, filtering, smoothing, forecasting, or diagnosing an existing or estimated ssm model; for explaining equations without code; or for Control System ss or System Identification idss models./matlab-use-spreadsheet-linkExchange data between Excel and MATLAB using Spreadsheet Link VBA macros and worksheet functions. Use when writing Excel VBA macros that call MLPutMatrix, MLGetMatrix, MLPutVar, MLGetVar, MLPutRanges, MLEvalString, MLGetFigure, or MatlabRequest.Other plugins' skills for the same job