Skip to main content

Documentation Index

Fetch the complete documentation index at: https://feasible-1447f9c5.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

This example of portfolio optimization is based on the example from the JuMP docs, a modeling framework in Julia. It showcases the agent’s capabilities to compute the coefficients using internal tools, as well as nonlinear modeling capabilities.

The problem

Say you have an amount of money to invest into some stocks, and want to minimize your risk while expecting a certain return. You have obtained historical stock data for the stocks in question. You are a risk-averse investor (like most of us), meaning that for the same expected return, you would like to minimize the spread between possible outcomes. In this case, we’ll say that you have 1000 USD to invest, and want 50 USD (5%) in expected return. The question is how to structure your portfolio.
This is an example of Modern Portfolio Theory

What you do

Paste the following statement into Feasible and watch it optimize:
Problem statement
I have want to optimize my portfolio. I have 1000 USD to invest in 3 stocks, IBM, WMT, and SEHI. I want to hold them for 1 month and then sell again. I can buy/sell fractions of stocks. There's no dividend during that time.

Historical stock prices for the past months are given in the following table:
| **IBM** | **WMT** | **SEHI** |
|--------:|--------:|---------:|
|  93.043 |  51.826 |    1.063 |
|  84.585 |  52.823 |    0.938 |
| 111.453 |  56.477 |      1.0 |
|  99.525 |  49.805 |    0.938 |
|  95.819 |  50.287 |    1.438 |
| 114.708 |  51.521 |      1.7 |
| 111.515 |  51.531 |     2.54 |
| 113.211 |  48.664 |     2.39 |
| 104.942 |  55.744 |     3.12 |
|  99.827 |  47.916 |     2.98 |
|  91.607 |  49.438 |      1.9 |
| 107.937 |  51.336 |     1.75 |
|  115.59 |  55.081 |      1.8 |

I want to minimize variance while keeping the expected return greater than 50 USD.
Example completed workflow: Open in Feasible

What happens

The basic steps should be familiar by now:
  1. The agent analyzes the problem and translates it to a mathematical optimization model
    • The agent sets up variables (x_i: how much to invest into stock i).
    • The agent sets up constraints for the budget and the minimum expected return.
    • The agent sets up an objective of minimizing the variance, according to portfolio theory.
  2. After review, the agent sends it to the solver
  3. The agent interprets the solver’s return values
One thing that is new is the calculation of the coefficients in the optimization problem. In previous examples, coefficients (like oven-hours per batch in the bakery example) were stated explicitly as part of the task. Here, the agent has to use tools to calculate them. Sometimes, you can observe a pattern where the agent initially states a wrong coefficient, e.g.
Initial LLM output
Mean returns (mu_i) estimated from 12 monthly return observations:
mu_IBM ≈ 0.02506 (per month, as a fraction)
mu_WMT ≈ 0.00720 (per month, as a fraction)
mu_SEHI ≈ 0.09075 (per month, as a fraction)
even though it’s not supposed to do any calculations yet. This is because the LLM knows that coefficients will be needed, and is a bit overeager to please. In this case, in a later step, it will correct them after using tools:
Corrected LLM output
Stock	μ_i
IBM	    0.026002
WMT	    0.008101
SEHI	0.073716
This example shows why it’s important to ground numbers generated by LLMs using tools, such as calculators, or optimization solvers. LLMs by themselves will just create plausible numbers; tools will create correct numbers.
A continuation of this problem can be found in Portfolio optimization - Advanced.