People frequently talk about having a diversified portfolio, however what they often think that means is simply having a lot of different stocks. Having a large number of different stocks will insulate your portfolio from some sorts of narrowly focused risks. Larger systemic risk reduction requires careful analysis including correlation analysis of investment sectors.
If you have a portfolio that consists of only oil and gas stocks, then any shifts in the oil and gas market will affect your portfolio as a whole even though you may have many different individual holdings. Correlation analysis lets you track the historical returns of market sectors against each other to see if they frequently move in lockstep, or have no connection. In some cases you may even discover negative correlation, meaning when one sector rises the other falls.
A sophisticated portfolio will usually have ten or more sectors, including different investment vehicles such as stocks, bonds, or more exotic holdings like currency swaps. Through careful work one can find the “efficient frontier” which allows for maximizing return while simultaneously minimizing risk. For more information, read about Modern Portfolio Theory.