After so many years of economic gloom, it’s nice to have some good news. On Thursday, such tidings came in the form of a surge in the valuation of Facebook, which climbed to more than $192bn in the wake of good first-quarter earnings.

This means that, as of Friday morning, the social network is now worth more, at least on paper, than Toyota ($189bn), AT&T ($184bn), Coca-Cola ($180bn), Disney ($150bn) and even Bank of America ($164bn).

How could that have happened?

Valuing a company

The total value of a publicly-listed company is pretty easy to work out: you just take its share price, and multiply it by the number of shares it has issued. That tells you what investors think its worth – it’s the price where buyers and sellers equal out.

What a company “should” be worth is a little tricker. For private companies, say a small family-run grocery store, the convention is, roughly speaking, that a business is worth some multiple of how much profit (or sometimes just cash) it generates.

So for a shop that does steady trade over time, a fair price might be about five years’ worth of profits. If the business can show it’s been growing rapidly each year, and is making more and more money, we might decide seven or eight years’ profit is fairer. There’s no exact science.

The same principle can be applied to corporate giants, and is known as valuing companies based on their fundamentals. This is where things get quite strange for companies like Facebook.

Last year, Facebook generated net profit of just under $1.5bn, meaning its current valuation is equal to about 128 times the profit it generated last year.

There are lots of reasons to think Facebook’s profits in the future will be higher than they were in 2013: it hadn’t really sorted mobile advertising at all last year, and a sharp rise in its mobile revenue suggests it now has. It can still do more to monetize its mobile app. It has huge reach, to 1.3 billion consumers. It’s clearly a company worth a lot of money.

But there are also lots of risks ahead for Facebook: it’s not a given that profits will always go up. Once Facebook’s mobile apps have adverts in place, where does next year’s double-digit growth come from? The site’s user base isn’t growing. A new generation of social networking apps, which allow users to take their contacts lists (sometimes called a social graph) with them to other services, is coming. Regulators might decide that Facebook’s market share has grown too large. The global advertising market may decline.

A valuation like Facebook’s – the market deciding a company is worth more than a century of its profit stream – isn’t just optimistic. It isn’t just wildly optimistic. It’s euphoric. Imagine the best possible business scenario, imagine it’s already happened, and then price it into the company’s stock.

The companies Facebook has beaten out in value terms generate much more cash today than Facebook does, and have done so for quite some time, which means we can be more confident they should be able to keep doing it. But investors like exciting companies, and as a result, the boring solid earners almost get punished simply for doing consistently well.

Whether you think the US stock market is too optimistic or too dismal right now, there’s clearly a huge disconnect between the tech world and other sectors – which is leading some people to mutter, worriedly, that the whole sector is once again in a bubble.

Cashing in

So here’s the tricky part: how do you make money off this?

Even if you personally think a company is overpriced, it’s very hard to profit from that belief. You’ve got three choices: buy the shares in the hope of riding the wave, short the company (place a bet that its stock price will fall), or stay out entirely.

Buy

Let’s imagine we’re someone who regards himself a savvy investor, and that we think Facebook and its ilk are over-valued based on their fundamentals – but we know just how hyped they are, and we can see the stock prices tick upwards day after day.

We might think the people buying the shares are morons – but we’d quite like to ride the moron wave. We can cash out quickly, before the market decides (if it ever does) the stock is overpriced. So we buy Facebook.

Savvier still investors, with even more cash to play with, spot that retail investors like you and me are buying Facebook to play the market. So it’s not a bad idea for them to do the same.

Lots of people are putting lots of cash into the stock for entirely rational reasons: some think the company is good, others think its stock price will rise because of other actors in the market.

The hard part is predicting when, if ever, the edifice will crumble and the stock price fall. Cash out too soon and you miss out on a chunk of profit. Cash out too late and you might lose a fortune.

It’s a fundamental part of market theory that knowing this ahead of time is all but impossible: if there was good information a stock was about to fall, a major investor with millions at stake would’ve already acted. If anyone knows a fall is coming, it’ll happen right now. So until new information comes in, markets move unpredictably – what’s known as a random walk.

Stay out

Tech’s a bubble, you decide. I’ll keep well away. This works perfectly fine if you’re a retail investor – though if the bubble doesn’t pop (or maybe even isn’t a bubble at all) your returns will be lower than your neighbours. But for professional fund managers, a few years of disappointing returns versus your rivals will quickly leave you searching for alternative employment.

When you play the game of funds, you win, or you’re fired.

Short it

There’s always the bold option: be the one visionary who predicted the fall before it happened. Place a bet that the share price will fall (known as a “short”) and rake it in big if that happens. The downside is, even if you’re absolutely right about a bubble, you won’t make money until everyone else agrees with you. That might be tomorrow, or it might be in 10 years time. It might be never.

If it doesn’t happen quickly, you’ll soon rake up huge losses. There’s a famous saying attributed to John Maynard Keynes, one of the giants of economics: “The market can remain irrational longer than you can remain solvent.” It’s not entirely clear that he ever actually said that, but if he did, he wasn’t wrong (he very rarely was).

The wrap

Facebook might be worth more than 100 times its most recent year’s profits. It might well not be – no one, including Facebook itself, knows. The same holds for the rest of the sector, and to an extent the rest of the market. Across most of America, recreational gambling is discouraged or illegal. But when it comes to your savings and your pension fund, it’s all but mandatory. Good luck – you’ll need it.