It’s remarkable that, in spite of the headwinds Mahindra and Mahindra Ltd has run up against, it has still outperformed the BSE Auto index this year. What’s more, it is revving up for a strong ride over the next year, after crossing multiple hurdles in the last few years.

The biggest blow for the company was the Supreme Court ban on diesel vehicles in Delhi a few months ago. With most of its portfolio catering to the diesel segment, the firm has steered a course to include petrol variants in all new launches. Analysts say there would be four petrol engines in the next 12-24 months. Its joint venture with Korean car maker Ssangyong would come in handy in filling this void.

That’s not all. M&M has also plugged the gaps in its utility vehicle (UV) range after it was taken by surprise a couple of years ago, when customer preference shifted to compact utility vehicles—something that M&M’s vast UV portfolio lacked.

Because of the gap, M&M, the market leader among UVs, had ceded share to the competition steadily, in the last two years. From 41% in the June 2015 quarter, M&M’s UV share, according to a report by HDFC Securities Ltd, dropped to 33% in the subsequent quarter. Thereafter, as it coped with competition, the share reversed to 41% in the March quarter.

If this is M&M’s story of mending its misses in the auto segment, it is poised for better times in the farm equipment segment too. Good news on the 2016 monsoons will aid tractor sales in the coming months. A Religare Capital Markets Ltd report says that the management has guided towards a 10% growth in volumes for fiscal 2017 on the back of an above-average rainfall forecast. Note that the farm equipment segment has higher profit margins than the auto segment.

The street has been quick to spot the recovery in both its product segments, after long drawn downsides. M&M’s stock has rallied 20% in the last six months driven by its improving outlook. It has outperformed the broader indices too in the last one year, though with high volatility. The stock’s one-year forward price-to-earnings multiple is 17, which has factored in the recent positive developments.

But the growth prospects are not bereft of risks. Analysts are wary of the huge price increase in its diesel vehicles following more stringent emission norms. This may increase the gap between diesel and petrol vehicles, which may be unfavourable for M&M, especially given the cascading price of petrol. Also, margin erosion is likely as M&M will lose some of its tax incentives from January.

That said, the positives override the negatives for the stock in the near term.