For most of 2012, Apple, (NASDAQ:AAPL) could do no wrong in the eyes of investors. In the first 3 months of the year, Apple stock rallied more than 50%. After giving up some gains, shares skyrocketed again, peaking with a 70% year-to-date gain in mid-September. Apple stock slumped badly to end the year, but still ended with a gain of nearly 30%, crushing the broader market.

AAPL Chart

Apple 2012 stock performance, data by YCharts

From a fundamental standpoint, Apple may benefit from similar tailwinds in 2015 as it did in 2012: primarily margin expansion. This could catalyze another year of strong outperformance for Apple stock.

Apple's margins soared in 2012
Rapid sales growth for both the iPhone and iPad product lines clearly played a big role in driving Apple's 2012 outperformance. However, margin expansion was an equally important source of profit growth. As the chart below clearly shows, Apple's gross margin and net margin rose through most of the period from 2005-2011 before peaking in 2012.

AAPL Gross Profit Margin (Quarterly) Chart

AAPL Gross Profit Margin, data by YCharts

Apple's strong margin performance in 2012 had a few key sources. The most important factor was a rapid increase in the iPhone's profit contribution. The iPhone 4S carried a very high gross margin because it maintained the same form factor as the iPhone 4. This meant that a lot of components could be reused, and electronics components prices tend to decrease significantly over time.

Apple also benefited from a favorable mix shift, as sales of the iPhone -- its most profitable product -- skyrocketed. In the quarter ending in December 2011 (and reported in January 2012), iPhone unit sales jumped 128%. In the March 2012 quarter, iPhone unit sales jumped 88%.

With sales of highly profitable iPhones (roughly) doubling and gross margin on those devices rising as well, it shouldn't be surprising that Apple's earnings soared. (Even declining iPod sales and slower growth in Mac sales couldn't drag down Apple's overall results.)

2012 redux?
The days of iPhone sales doubling year-over-year are gone. The law of large numbers has caught up with Apple; its sheer size puts practical limits on how fast sales can grow in the future.

Still, Apple is in the midst of a noticeable upswing in iPhone sales growth. Almost all Wall Street analysts agree that iPhone sales surged last quarter compared to the 51 million sold in the December 2013 quarter. A few think that December quarter iPhone sales may have exceeded 70 million, representing roughly 40% unit growth.

iPhone unit sales growth may have risen as high as 40% last quarter. Photo: Apple

By contrast, the rest of Apple is barely growing, as iPod sales continue to decline and iPad sales have been in a rut for the past year as well. In the September quarter, iPhone revenue rose 21% year-over-year but Apple's non-iPhone revenue rose less than 3%. This means that iPhone sales growth is having a significant impact on Apple's product mix.

Gross margin within the iPhone product line is on the rise, too. First, the iPhone 6 Plus costs $100 more (in the U.S.) than Apple previously charged for its top-of-the-line iPhones. Strong demand for the iPhone 6 Plus will benefit gross margin because the incremental production cost is much lower. A shift in demand toward models with more storage is also lifting gross margin.

Apple has projected that gross margin will reach 37.5%-38.5% in the December quarter compared to 37.9% in the year-earlier period. Apple has been regularly beating its gross margin guidance, though. It wouldn't be surprising if gross margin hit 39% or even 40% last quarter.

Moreover, Apple ended the December quarter with tight iPhone supply. In the first few weeks of the March quarter, iPhone sales momentum has remained strong. The relatively late Chinese New Year (Feb. 19, compared to Jan. 31 last year) should also stimulate higher sales in China this quarter. These factors should contribute to a smaller-than-typical seasonal decline in iPhone sales this quarter.

The Apple Watch launch could boost gross margin this quarter. Photo: Apple

Apple's March quarter gross margin could also benefit if the Apple Watch goes on sale in the next 2 months. (Early adopters tend to buy more expensive and higher-margin Apple products.) Lastly, App Store sales -- which have gross margins of nearly 100% -- hit a record high earlier this month.

In short, there are a lot of factors working together to boost Apple's gross margin. Gross margin typically rises sequentially in the March quarter. Last year, it increased by 1.4 percentage points. Apple's big tailwinds this year could drive even bigger gains, lifting gross margin well into the 40%-45% range for the March quarter.

Risk factors
In the March 2012 quarter, Apple's gross margin surged to a record of 47.4%. Apple probably can't duplicate that feat, but it is poised to deliver its best gross margin results since 2012 this year. This could drive rapid earnings growth.

The strong dollar represents the biggest risk to Apple's gross margin performance this year. As the dollar rises against other currencies, Apple brings in less revenue for every iPhone or iPad sold abroad (assuming that it doesn't change its local currency prices).

Longer-term, it is possible that gross margin will start to fall again later this year (as it did later in 2012). For example, if the next-generation iPhones don't offer a significant upgrade compared to the iPhone 6 and iPhone 6 Plus, customers might gravitate to discounted older models with lower gross margins.

The most likely scenario is that Apple's gross margin will settle in lower than the glory days of 2012 but appreciably higher than the "dark" days of 2013. That's good enough to make Apple stock look like a bargain at less than 14 times forward earnings, compared to 17 times earnings for the rest of the market.