
Python for Algorithmic Trading Cookbook
By :

Principal component analysis (PCA) is a dimensionality reduction technique that is widely used in data science. It transforms the original features into a new set of features, called principal components, which reflect the maximum variance in the data. In other words, it transforms a large set of variables into a smaller set of variables, while still containing most of the information from the larger set.
There are various sources of risk in an asset portfolio, including market risk, sector risk, and asset-specific risk. PCA helps identify and quantify these risks by breaking down the returns of the portfolio into components that explain the maximum variance. The first few principal components usually capture most of the variance and they can be analyzed to understand the major sources of risk in the portfolio.
This recipe will use scikit-learn to run PCA on a portfolio of eight stocks made of up mining and...