Bank of America Merrill Lynch crunched the numbers and found that companies with a higher share of women holding executive positions had historically outperformed.

The firm also says those companies experienced less stock price and earnings volatility.

Bank of America Merrill Lynch has a solution for any company looking to boost the bottom line: Appoint more women to executive positions.

Over the past seven years, S&P 500 companies where at least 25% of executives were female generated higher one-year returns on equity than the overall index, on a median basis, according to data compiled by the firm.

"Gender diversity may drive better returns," BAML strategists led by Savita Subramanian wrote in a client report, noting that women make up just 22% of S&P 500 boards right now.

This chart shows this dynamic at work. The blue bars represent companies where women hold more than 25% of executive positions — and as you can see, the group has outperformed in each of the past seven years.

BAML also cites a McKinsey study from 2015 that found a "statistically significant relationship between diversity of leadership teams and financial performance."

According to the study, companies in the top quartile for gender diversity were 15% more likely to see their operating income surpass the industry median.

Further, BAML finds that companies with more female executives have historically experienced less stock price and earnings volatility.

"Companies that invest in women tend to have more favorable fundamental attributes, and with the rise in impact investing, a growing investor base," the firm said.