All personal projects

Personal project2026Private repository

wsopt

A portfolio optimizer that buys whole shares, pays real fees and measures risk in drawdowns.

Value
Drawdown from the last peak
The worst 5 %: what the optimizer limits
An illustrative path, not a real portfolio.

The job

When
I invest a fixed budget in single stocks,
I want
an order list I can actually place, with whole shares and every fee counted,
So
the plan on paper is the plan the broker executes.

What it does

Given a budget in euros, it builds a portfolio of ten to twenty stocks from the United States and Europe and prints an order list: ticker, number of shares, expected fee. It also draws the trade-off between expected return and drawdown, and runs a walk-forward test of the method itself.

Textbook optimizers hand you weights like 6.37 %. A real account buys whole shares, pays a fixed fee per order, a percentage, a stock exchange tax, and sometimes a French, Italian or Spanish transaction tax on top. On a modest budget those details decide the answer, so they are part of the problem rather than a correction afterwards.

How it is made

  • The unknown is the number of shares. It is a mixed-integer linear program, solved with HiGHS. The budget constraint includes every fee, with a linearisation that never underestimates them.
  • Risk is drawdown, not volatility. The limit is on Conditional Drawdown at Risk, the average of the worst five per cent of drawdowns, so a stock is not punished for going up quickly.
  • Returns are what lands in the account. Net of foreign and Belgian withholding tax, dividends reinvested, converted to euros.
  • The method is tested, not the portfolio. Every five years in the past, it optimises with only what was known then, buys, holds for ten years and records what happened, against a plain equal-weight benchmark.
  • Dirty data is handled in the open. Prices in pence, botched split adjustments, funds listed as stocks, companies that vanished: each has a documented rule.

Worth noticing

The README has a section called “Limitations (read before trusting the numbers)”, and it is longer than the feature list. The main finding is a modest one: the return estimates are too noisy to be worth chasing, so the tool picks the portfolio with the smallest drawdowns and stops there.

This is a personal tool, not investment advice.