If you've been an investor in Walgreens Boots Alliance (NASDAQ:WBA) for the past five years, you haven't been thrilled with its performance. The stock has declined each of the past four years. It fell 13.7% in 2019, and that negative momentum continued into 2020 as the price is down 12% year-to-date.

CVS Health (NYSE:CVS) -- the largest pharmacy chain in the U.S., ahead of No. 2 Walgreens -- hasn't been much better over that same period. But the stock did have a positive year in 2019, returning 13.4%, and is down only 3.1% year-to-date in 2020.

Both stocks are facing headwinds from shifts in both the retail and healthcare markets. Not only are they seeing increased competition from Walmart and Amazon, but they're dealing with lower prices for generic drugs and a decline in reimbursement rates, among other factors. That's why both of these companies are in transition periods. The better buy for investors will be the company that can more effectively pivot to move forward.

Walgreens Boots Alliance makes cuts

Walgreens is in the midst of a number of major changes. One of biggest initiatives is its "Transformational Cost Management Plan," which calls for a $1.8 billion reduction in expenses by 2022. This includes the closure of about 200 Walgreens stores.

This cost management initiative – announced last year – has begun to improve cash flow. Operating cash flow was $1.1 billion in the quarter, up $601 million compared to the first quarter of the previous year. Free cash flow, which was negative a year ago, was $674 million at the end of the first quarter.

A pharmacist smiles as she greets a customer.

Image source: Getty Images.

The excess cash will be used to fund several new initiatives to drive future growth, including a German joint venture with McKesson (NYSE:MCK) to expand its presence in Europe.

Walgreens and supermarket chain Kroger (NYSE:KR) formed a group purchasing partnership to save costs. In addition, to boost retail traffic and provide customers with experiences they can't get online, the company is installing Jenny Craig weight loss centers and VillageMD primary care clinics in some stores. Walgreens is also the first retailer in the country to test a drone delivery service as a potential way to speed up delivery times. 

Walgreens missed earnings estimates in the first quarter, as its earnings per share (EPS) dropped 19.8% to $0.95 compared to the previous year's quarter, and net operating income dropped 27.6% to $1 billion. The company projects flat earnings growth for 2020 but is focused on long-term growth.

CVS first to pivot

CVS seems to be ahead of Walgreens in embracing the pivot. The company made a big splash in late 2018 by acquiring health insurance company Aetna. The merger is designed to lower costs for customers while enhancing care and providing a better customer experience and localized healthcare.

After a full year of integration, the merger is beginning to pay off. Revenue increased 22.9% in the fourth quarter to $66.9 billion, a 22.9% increase over the previous year, while full-year revenue was up 32% at $256.8 billion. The EPS was $7.08 for the year – which was the same as the previous year. 

The company streamlined operations by closing 46 underperforming stores last year, with plans to close 22 more in the first quarter of 2020. At the same time, it plans to increase the number of HealthHubs in its stores. HealthHubs are basically walk-in clinics – an expanded version of its Minute Clinics. At HealthHubs, customers can receive about 80% of the care that a patient can get from a primary care doctor. CVS officials expect these hubs to increase retail traffic to its stores. 

The company improved its cash flow in 2019, with cash from operations of $12.8 billion driven by improvements in working capital. The total was higher than expected. Approximately $4.7 billion was used to pay off debt in 2019 and $2.6 billion was returned to shareholders through cash dividends. 

Which is the better buy?

Walgreens appears to be on the right track with its cost-reduction plan and planned initiatives, but the company doesn't expect earnings growth in 2020 --and it remains to be seen how the company will execute on its plan going forward.

CVS has already gone through the process of integrating the Aetna acquisition and expects to see growth in 2020. The company projects EPS to grow between 3% and 5% in 2020 -- which is higher than expected. Plus, CVS pays a better quarterly dividend.

In an industry that's changing, CVS has better positioned itself for growth through its strategy to expand localized healthcare at lower costs. While neither CVS nor Walgreens look to be huge growers, CVS -- which is further along in its execution and is starting to see results -- is the better buy.