🐍 Why your portfolio weights swing so hard


Most beginners think portfolio math has no room for their own opinion about a stock (it does)

You can follow the code in a portfolio tutorial line by line and still not know what the numbers mean, so when the program hands back weights you have no way to judge whether they're sensible.

The first weight-picking program I built put almost all the money into two stocks, and nothing in the code was broken.

I just didn't understand that the rough return guesses I fed it were doing all the work.

Here's the reality.

Fischer Black and Robert Litterman built their model at Goldman Sachs in 1990 specifically because the standard approach turned small forecast errors into extreme positions, and that's the same problem beginners run into today.

Most people respond by hand-editing the weights in a spreadsheet, which throws away the reason for running the program at all.

There's a structured way to learn the finance math behind allocation, so you can build your own tools for tracking a portfolio and its risk instead of trusting output you can't explain.

It starts with stating what you actually believe about each stock as a number, then letting the model blend that belief with what the market already expects.

Here's a Python example you can use now.

Assumes prices is a pandas DataFrame (a table of data in Python) of daily closing prices with one column per ticker, and that you've installed PyPortfolioOpt, a library for portfolio math.

The covariance matrix records how much each pair of stocks moves together, which is what separates a spread-out bet from a concentrated one.

Your forecasts supply the return estimate, because past average returns make poor predictions of future ones.

What comes back is a weight per ticker, and BBY carries the highest forecast at 0.25, but it only outweighs BAC if its own price swings and its co-movement with the others don't cancel out that extra return.

Change the BBY number to 0.10, rerun, and watch how far its weight moves, which tells you how much of the allocation rests on one guess you typed.

I still can't tell you whether the views were any good until the year is up and I compare the result against holding all three in equal amounts.

Your next steps

Start by learning what a covariance matrix (how pairs of stocks move together) and an expected return (your own forecast for the year ahead) actually measure, then rerun the code above with your own forecasts until you can predict which weight will move before you press enter.

From there, build a small dashboard that tracks those weights and their worst loss over the holding period, and you'll have a portfolio you can defend line by line instead of one you abandon after a bad month.


Jason Strimpel, founder of PyQuant News

Say 👋 on X/Twitter, LinkedIn, or book a call with me. You can always reply to these emails. I check them all.

You got this email because you joined the PyQuant Newsletter or bought a product of mine.

You told me your email address is Reader.

Not right? Update your profile.

Want to stop getting these emails? No problem! Unsubscribe from all my emails.

Never investment advice. Use at your own risk. For educational purposes.

113 Cherry St #92768, Seattle, WA 98104

© 2026 PyQuant News, LLC

​

PyQuant Tips

For finance professionals, coders, and complete beginners. Automate your trading, investing, and data analysis with Python. No jargon, no fancy math, code you can use.

Read more from PyQuant Tips
Every strategy makes 1 of 3 bets: Use Python to tell you which one.

Sort any trading idea into 1 of 3 bets with 4 lines of Python Every strategy makes 1 of 3 bets: Use Python to tell you which one. My master's degree taught me MATLAB. Not Python. Since I didn't want to pay the $2,000 license fee, I watched every YouTube video I could find to teach myself. 96% of them were a complete waste of time. The other 4% buried me in strategy ideas. Statistical arbitrage. Trend and momentum. Pairs trading... Maybe that's you. A head full of trading ideas but nothing...

Use the workbook you already have.

Move from Excel to Python in 3 simple steps Use the workbook you already have. Most finance work still runs on Excel. When I was a derivatives trader, most the $7 billion operation was based on Excel. The process was the same: You build the model, drag the formulas down and refresh it every Monday. Eventually, the sheets got too big and wouldn't even open. The analysis was basic and not that interesting. An actuary in one of my courses said most of his analysis lived in Excel, and "it was...

You don't need a $30,000 terminal to build an AI research desk Let Python pick what matters. Let the agent explain it. A Bloomberg Terminal costs about $30,000 a year. So you do what everyone does: You paste news headlines into ChatGPT. Then a 10-K. Then a chart. Then another chat window. By Friday you have 40 chats, 12 browser tabs, and no idea if any of what ChatGPT came up with works. That's experimenting, which is fine, but the sooner you build a system, the sooner you get results. Every...