In the long run, luck tends to even itself out. This can be applied to all walks of life and while bad luck may persist for some time, over time, a healthy dose of good luck should balance the scales. That is, unless you’re an investor in BP (LSE: BP). The oil and gas major seems to have had an unending run of bad luck that has caused its share price to come under severe pressure in recent years. In fact, the shares have tumbled by 45% in the last decade and there could be further problems ahead.

For example, BP was hurt by the Deepwater Horizon oil spill of 2010, which caused investor sentiment to be hit extremely hard. And with BP paying out billions in compensation claims, its financial stability took a real hit and this caused its long-term outlook to become increasingly uncertain. Following the oil spill, BP’s shares were also hurt by it having a 20% stake in Russian oil and gas operator Rosneft. That’s because Russia has been the subject of sanctions and BP’s exposure to the country has caused additional uncertainty regarding its long-term profit outlook.

After these two pieces of bad luck, BP then suffered from the commodity crisis. Clearly, this is still ongoing and while the price of oil has recovered from its low of $28 earlier this year to just under $50 per barrel today, there are no guarantees the performance of black gold will improve in the medium-to-long term. As such, and even though BP has endured a lot of bad luck in recent years, things could get worse before they get better for BP if commodity prices come under further pressure.

Time to buy?

Of course, BP isn’t doomed to fail and it isn’t subject exclusively to bad luck. Its recent performance is unlikely to continue in the long run and therefore now could be a good time to buy a slice of the business. That’s especially the case since BP appears to offer a relatively wide margin of safety, which means that even if it’s subject to challenging external factors, its share price may still perform relatively well.

For example, BP trades on a price-to-earnings growth (PEG) ratio of just 0.1, which indicates that its shares offer growth at a very reasonable price. And with BP having a high-quality, well-diversified asset base on offer to investors without any premium to its net asset value, there’s clear capital gain potential on offer.

Certainly, BP has had bad luck and the bad luck may continue in the short-to-medium term. However, for long-term investors BP remains a sound buy since it has the right strategy, a strong asset base and a wide margin of safety to ensure that its shares deliver upbeat capital gains in the coming years.

Of course, BP isn't the only company that could be worth buying at the present time. With that in mind, the analysts at The Motley Fool have written a free and without obligation guide called 5 Shares You Can Retire On.

The 5 companies in question offer stunning dividend yields, have fantastic long-term potential, and trade at very appealing valuations. As such, they could deliver excellent returns and provide your portfolio with a major boost in 2016 and beyond.

Click here to find out all about them - it's completely free and without obligation to do so.

Peter Stephens owns shares of BP. The Motley Fool UK has recommended BP. We Fools don't all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors.