In the context of portfolio optimization, for now I encountered only cases where the sum of relative weights $h_n$ in each stock is equal to 1. However, I've seen that there are cases where the sum is equal to 0. How can that be? I cannot wrap my head around this.
In the traditional academic model, the sum of absolute weights adds up to 1. The investor is assumed to have X (usually 100) to invest, some of which goes into cash versus "the market portfolio", of which some goes into bonds versus stock, of which some goes to this stock and some goes that stock etc.
For any fund manager whose performance is measured and incentivised against a benchmark, what matters are the relative weights, that sum to 0. Suppose the market has eg 3% in Apple and 2% in Tesla; and if I'm 5% Apple and 0% Tesla. My performance relative to benchmark will be a portfolio that is +2% Apple and -2% Tesla.
Whether or not the market rises or falls, the bet I'm making is that Apple outperforms Tesla. Or at least that is the "career risk" I'm running in the portfolio given the benchmarked incentive structure above. This is not the same thing as the portfolio's economic risk - chiefly, will stocks go up or down!
These are just the two most classic models. The weights, absolute and relative, can sum to anything you want.
Risk parity funds might run 200% long bonds, 50% long stock, 0% shorts. Which is a +160% bonds, -10% stocks relative profile versus a classic 60:40 balanced fund. A classic long-short equity hedge fund might run 140 long, 90 short equals 230 gross, +50 net positions. Measured against cash, the "relative" here is the same as the absolute; and so essentially meaningless. And the whole concept of "weights" almost entirely collapses when one allows FX or options into the portfolio.
The bottom line is that neither the absolute nor relative weights have to add up to one or zero respectively. Where they do is just the special case where leverage and shorting is prohibited.
A positive coefficient means you are going long; a negative coefficient means you are going short. Think for example of a portfolio where you borrow 1000\$ (i.e. you go short a 1000\$ bond) and you use it to buy 1000\$ worth of shares XYZ. You haven't invested any money from your pocket, hence the sum of coefficients is 0.
Portfolios with weights summing to zero are known as "arbitrage portfolios" or "zero net investment portfolios". They are relatively common in the literature.
The idea is that the funds necessary to buy the assets with positive weights are supplied by selling short the assets with negative weights.
At first this may seem impossible, since the value of the portfolio could easily go negative, with no one available to bear the losses. For example if on the first day the value of the long assets drops by one dollar, the investor no longer has enough money to buy back his short position. What does he do in that situation? Where is the extra dollar going to come from?
It is still a useful concept as long as we assume that the investor has other assets (or income) not mentioned which can be used to cover losses as they occur. In practice before being allowed to set up such a portfolio the investor would be asked by his broker to set aside some collateral to cover losses, and the size of the long and short positions he is allowed to take would be decided by the broker based on how much collateral is left. If the collateral becomes insufficient the investor would be asked to reduce his positions or close them entirely (as happened for example to the famous hedge fund LTCM in 1988).
In summary then a portfolio with zero sum of weights is a way to model arbitrage operations although it leaves out or abstracts away from the (important) details of collateral maintenance. It is a useful concept as long as you realize the simplifications involved.