The world is going through a significant shift in the way it creates and uses energy, moving away from carbon-based fuels and toward renewables. The transition will take a very long time (think decades), and spending on clean energy will be important for years to come. It is a big opportunity, but does that translate into an investment opportunity? The answer isn't as easy as you might hope.

Value versus price

Benjamin Graham, the man who helped train Warren Buffet, has noted that price is what you pay, and value is what you get. In other words, stock prices don't always align with the value of a company -- in fact, the two often deviate greatly. Graham uses a story to explain this, in which you (as an investor) are partnered with a person called Mr. Market. Mr. Market has wild emotional swings and some days will offer to sell to you cheaply, and on other days, he is willing to buy at premium prices. Your job is to figure out when Mr. Market is selling too cheaply, which is a time to buy from him, and when he is willing to overpay, which is a time to sell.

A soap bubble with a dollar sign in it about to be popped by a hand holding a pin.

Image source: Getty Images.

That's clearly just a way to say buy low and sell high, which can be a very difficult task. However, the biggest problem here is likely to be your own emotions. It is, indeed, very hard to avoid getting caught up in the stories that have Wall Street (Mr. Market) shifting from one mood to the next. Right now, the big-picture story is that carbon fuels are out, and clean energy is in. Thus, many renewable power stocks are doing very well while those producing oil are suffering, relatively speaking. It's not that clean energy isn't going to be important in the future -- it will be. And there's likely to be years of growth ahead for the sector. The question is, how much are you willing to pay for an investment in the sector?

High-priced examples

Over the past five years, Hannon-Armstrong Sustainable Infrastructure (HASI 0.91%) has risen over 180%. The S&P 500 Index is up a little more than 100% over that same span. Hannon-Armstrong is a real estate investment trust (REIT) that provides loans to clean energy providers backed by the long-term contracts they sign. It then passes the majority of the income it generates from the loans it makes to investors in the form of dividends. The stock's dividend yield, at around 2.5%, is near all-time lows. Given that low dividend yield, it would be hard to suggest that Hannon-Armstrong looks like a bargain today. It appears that a lot of good news is being priced into the stock. It is hardly alone.

Clearway Energy (CWEN 2.30%), a large owner of renewable power assets, follows the same trend. Its stock has risen more than 140% over the past five years, and its dividend yield is near historic lows. Shares of SolarEdge Technologies (SEDG 4.15%), which makes technology used in solar power systems, are up more than 300% over the past five years. Although it doesn't pay a dividend, its price-to-earnings ratio is over 100 times versus a P/E ratio of around 28 times for the broader market (which is on the high side itself). In other words, SolarEdge looks a bit pricey, too. This is a repeating theme throughout the renewable power space, with some examples being more stunning than others. But the end result is that it is hard to suggest that clean energy stocks are a good value right now because Mr. Market is excited by the long-term prospects of renewable power. Caution is in order when you are looking at a pure-play name in this space, even though the long-term prospects for the sector look good.

HASI Chart

HASI data by YCharts

The interesting thing is that you don't have to buy a pure play. For example, NextEra Energy (NEE 1.36%) is also richly priced today, and its yield is near historic lows. However, it's a mixture of a renewable-power business and a boring old utility. Its Florida Power & Light division provides a vital foundation for the spending that's underway in the renewable power space. Should the renewable power growth story fall out of favor for some reason, there's a backstop. If you are considering pure plays, you might want to take a closer look at NextEra, noting that it has increased its dividend annually for more than 25 consecutive years, making it a Dividend Aristocrat. That kind of consistency could be important if investors sour on clean energy.

ENB Chart

ENB data by YCharts

There are also names like integrated oil giant TotalEnergies (TTE 0.52%) and North American midstream player Enbridge (ENB 0.20%). Both companies are out of favor today, with negative trailing five-year returns and historically high yields, at least partly because of their ties to carbon energy. But what's interesting is that each of these companies is using the cash generated from the oil sector to build clean energy businesses. With decades to go before oil is phased out, they should have plenty of time to adjust along with the world. For long-term dividend investors, they could be a good way to play the long-term energy transition that's underway without taking on the risk of Wall Street's clean energy zeitgeist.

Be cautious

Is now a good time to buy renewable energy stocks? The answer is, unfortunately, it depends. The prices of pure plays in the space have been bid up. That suggests you need to be careful and perhaps consider something with a little more diversification, like NextEra, which is also expensive but has more than one business to rely on for growth. If you are willing to think outside the box just a little, you might even find that there are ways to invest in the clean-energy transition that are relatively cheap, historically speaking. Sure, you'll have to look at companies tied to dirty carbon fuels, but Mr. Market's dour view of these stocks could make them relative bargains over the long term.