Halloween, as comedian Jerry Seinfeld pointed out, is the best possible holiday a child can imagine. You simply go door-to-door and the neighbors give you handfuls of candy for free.

But according to Kerry McDonald, trick-or-treating and the extensive trading of candy afterwards illustrate several important principles of a free market. The very concepts that make investing for retirement possible.

A Senior Education Fellow at the Foundation for Economic Education, McDonald has four children of her own who she’s seen conduct extensive candy trades among themselves, with friends, and with other kids in the neighborhood.

And, as McDonald has observed, whether you’re trading in ETF shares or Mars Bars, certain economic principles hold true.

Trade is voluntary

Years ago there might have been a real threat behind the phrase “trick or treat.” If you don’t give me something good, you could be the target of a prank you don’t like.

But today (at least in most neighborhoods) participation is voluntary. Leave the porch light on if you’re giving out candy. Otherwise, the little princesses and superheroes will just go to the next house. The post-trick-or-treating candy trading is also voluntary. Among kids, if you don’t want to swap, that’s fair.

Trade is win-win

The only reason kids want to make a trade is if both of them feel like they’re coming out ahead. If little brother likes 3 Musketeers bars and doesn’t really care for Twix bars, he’ll gladly trade multiple Twix to get the 3 Musketeers. And if his big sister feels the opposite way, they have the conditions for an ideal trade.

The wider the market the better

McDonald noted that when her four children trade only among themselves, they have less of a chance of making big, win-win deals. In the same way, free trade to the widest possible market gives companies a better chance of finding customers who will receive the greatest value from their goods and services, and are therefore willing to pay the best price.

Value is subjective

The value of a good or service depends on its perceived utility to a customer at a given time. A fresh apple is delicious and nutritious, and if you bought it at Whole Foods, may have cost more than a candy bar. But you’d have a hard time making that case to a kid looking to trade candy corn for something chocolate.

Value is marginal

The value of any good depends on its supply. McDonald observed that as trading progressed, certain candies gained in value. When her six-year-old had plenty of Twizzlers and no fullsize Hershey bar, he became willing to trade more of the Twizzlers as his desired candy bar appeared to become more scarce.

This is the same reason the price of labor cannot be fixed at an absolute value (as the communists learned), and also why government price-fixing ends up causing the opposite effect.

So if there’s trick-or-treating in your area this year, buy a supply of the “good” treats, turn on your porch light, and invest generously in your local free candy market.

Happy Halloween!