Count allocations of identical units to named buckets, distinguish zero from positive holdings, and adjust for caps without confusing counts with probabilities.
Stars and bars
Stars and bars is a method for counting allocations of indistinguishable units among labelled buckets. Equivalently, it counts nonnegative integer solutions to a fixed-sum equation. For a quant researcher, it can measure the size of a discrete portfolio-allocation grid before any returns, risk or optimisation are considered.
For integers n≥0 and k≥1, the number of vectors satisfying
These vectors are called weak compositions of n into k parts. The coordinates retain their identities: (3,0,4) and (0,3,4) are different allocations.
Seven units across three assets
Consider a toy grid with seven identical capital units allocated among named assets A, B and C. A unit is the same amount of capital wherever it is placed; it is not one share of an asset with its own price. All seven units must be allocated, holdings are nonnegative integers, and there are initially no caps.
Represent each unit by a star and separate the three asset holdings with two bars. The vector (3,0,4) becomes ***||****: three stars before the first bar, none between the bars, and four after the second. Adjacent bars encode a zero holding. A bar at either end also permits an empty bucket.
Every allocation produces exactly one such string, and each string recovers exactly one allocation. There are nine symbol positions, of which two must contain bars:
(3−17+3−1)=(29)=36.
Seven identical units allocated to named assets A, B and C. The vector (3, 0, 4) is represented by three stars, two adjacent bars and four stars. Choosing two bar positions among nine gives 36 nonnegative allocations; reserving one unit per asset leaves four units and gives 15 positive allocations.
Original illustrative integer-allocation diagram. Adjacent bars allow an asset to receive zero; requiring one unit in every asset changes the count from 36 to 15.
The asset labels matter even though the capital units are interchangeable. Treating the buckets as indistinguishable would instead identify allocations that differ only by exchanging asset names, answering a different question.
Minimum holdings and caps change the count
If each asset must receive at least one unit, allocate those three units first. Write yi=xi−1. The remaining equation is y1+y2+y3=4, with yi≥0, so there are
(3−14+3−1)=(26)=15
allocations. Generally, strictly positive holdings give (k−1n−1) when n≥k, and zero allocations when n<k. For specified integer minima mi≥0, subtract each minimum first; if their sum exceeds the budget, no allocation is feasible.
Upper bounds need another step. Suppose zero is allowed again, but no asset may receive more than four units. Of the original 36 allocations, those with xA≥5 can be counted by reserving five units for A and distributing the remaining two. There are (24)=6 such allocations for each asset. Two assets cannot both receive at least five from a seven-unit budget, so the violating sets do not overlap:
36−3(24)=18.
With larger budgets, violations can overlap and inclusion–exclusion must restore allocations subtracted more than once. Unequal lot sizes, extra constraints or unrestricted short positions also require a revised counting problem. This grid does not count portfolios with continuously variable weights.
A count does not assign probabilities
Stars and bars counts holding vectors. Assigning seven distinct orders to three assets instead gives 37=2,187 assignments when every order can go to any asset. Many assignments share a holding vector: (7,0,0) has one assignment, whereas (3,0,4) has (37)=35.
Consequently, if seven independent orders each choose an asset with equal probability, those two count vectors are not equally likely. Their probabilities come from a multinomial distribution. Selecting uniformly from the 36 allocation vectors would be a different random experiment. The counting formula alone specifies neither experiment nor a portfolio-selection rule.
For the underlying combinations and distinct-object partitions, the Counting and Combinatorics lesson provides worked derivations. Its public page is a preview; the full lesson requires membership.