In economics it is probably better explained through the “invisible hand” of supply and demand.
Milton Friedman’s explanation of how speculators affect markets is reviewed in this short blog by a professor at the University of Michigan. Take-away: money losing speculators destabilize markets … but they can only lose so much. So the speculators who make money help stabilize markets.
“Bottom Line: If speculators are making money, they MUST be stabilizing markets. If speculators are losing money, they MUST be destabilizing markets. But speculators can NOT make money and destabilize markets at the same time.”
And onions are the only commodity without a futures market (i.e., no speculators) and take a look at those price swings as compared to oil (they are more price swings without the influence of speculators.
Moral of the story: speculators are helpful. Some win, some lose, but the effect is to stabilize prices more relative to what price volatility would be without them. This does not mean prices do not go up and down … they need too. It does mean prices go up and down less. This is the fundamental purpose of the futures market.
So just what is it that speculators do? Their realm of operation is in the futures market (note 2 separate links) which is riskier than the stock market in general since the futures contracts expire, which forces a gain or loss on the money; stocks are continuous unless the company goes out of business or reconstructs their capitalization method. There are many shades of “speculation.”