Matlab Optimize Portfolio logo

Matlab Optimize Portfolio

OrganizationPopular
matlab
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. 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.

Overview

Publishermatlab
Repositorymatlab-agentic-toolkit
Skill namematlab-optimize-portfolio
Stars
1.2K
Forks
138
Bundled files
5
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by matlab on GitHub. Read the source before you install it.

Installation

Install the Matlab Optimize Portfolio AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/computational-finance/matlab-optimize-portfolio
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit.git /tmp/matlab-agentic-toolkit
mkdir -p .claude/skills
cp -r /tmp/matlab-agentic-toolkit/skills-catalog/computational-finance/matlab-optimize-portfolio .claude/skills/matlab-optimize-portfolio
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Matlab Optimize Portfolio in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Matlab Optimize Portfolio on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Matlab Optimize Portfolio is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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 PortfolioCVaR or PortfolioMAD classes (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...FormulationReference
Minimize portfolio risk (no return target)Mean-variance (min-variance)formulation-mean-variance.md
Minimize risk for a given target returnMean-variance (target-return)formulation-mean-variance.md
Trace the efficient frontierMean-variance (frontier)formulation-mean-variance.md
Maximize risk-adjusted return (Sharpe ratio)Max Sharpe / tangencyformulation-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:

matlab
p = Portfolio('AssetMean', mu, 'AssetCovar', Sigma);

From historical returns:

matlab
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):

matlab
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:

matlab
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:

matlab
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:

matlab
wFrontier = estimateFrontier(p, 20);
plotFrontier(p, wFrontier);
hold on
[risk, ret] = estimatePortMoments(p, wSpecial);
plot(risk, ret, 'r*', 'MarkerSize', 12);
hold off

Common Pitfalls

  1. Manual solver usage — quadprog/fmincon for portfolio problems is error-prone; Portfolio handles it.
  2. Missing constraints — A Portfolio without constraints is underdetermined.
  3. Redundant solves — Pass weights to plotFrontier, not a number of portfolios, if you already solved.
  4. Manual risk/return formulas — Use estimatePortRisk, estimatePortReturn, estimatePortMoments.
  5. 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


Copyright 2026 The MathWorks, Inc.


Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Matlab Optimize Portfolio AI skill do?

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.

Why use Matlab Optimize Portfolio on TypingMind?

Because you install it once and use it with any model. Matlab Optimize Portfolio is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Matlab Optimize Portfolio in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/computational-finance/matlab-optimize-portfolio. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Matlab Optimize Portfolio?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Matlab Optimize Portfolio?

As many as you like. As long as a model supports skills, you can use Matlab Optimize Portfolio with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Matlab Optimize Portfolio AI skill free?

It is published on GitHub by matlab. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇