➡️ Quantitative Finance from Scratch, part 59: Principal Component Analysis.
QuantFinanceToGo
Visit on TikTok43K followers
19,300 views #quantfinance #finance #principalcomponentanalysis
➡️ Quantitative Finance from Scratch, part 59: Principal Component Analysis. Principal component analysis, or PCA, takes many things that move together and finds the few directions behind most of their movement. In finance, these hidden directions are called factors, and PCA is one of the main tools to find them. In the parts about Fama French and APT, the factors were built the classic way: start from an idea like size or value, build a long short portfolio from it, and test whether it explains returns. PCA is an alternative to this. It starts from the data alone and lets the factors show up, without names and without assumptions. How it works, roughly: first it measures how every pair of stocks moves together, which gives the covariance matrix. Then it searches for the one mix of all stocks that swings the most. When one force moves many stocks at once, their moves add up in the mix, while the private noise of single stocks cancels out. So the mix with the biggest swing points at the strongest common force: the first component. The second component is the mix with the most swing that is left, at a right angle to the first. Each component comes with weights (loadings), which say how strongly each stock moves with it, much like a beta, and a share, which says how much of the total movement it explains, much like an R squared for the whole table. In the example, the first component gives all 50 stocks almost the same weight, so it is the market, and it explains about half of all movement. The second puts one sector against the other and explains another 11 %. Every other component explains only about 1 % each, which is the noise of single stocks. Keeping the two big components and dropping the other 48 separates the common forces from the noise. Uses: risk models work with a few components instead of 1,225 pairs of stocks, statistical arbitrage trades what is left after removing the first components, and for bonds three components called level, slope and curvature describe almost every move of the yield curve. Limits: the components are purely statistical, so you have to find out yourself what they mean, they can change over time, and they only capture straight line relationships. The code (pca59_reel.py, 14 lines of Python) builds the example data, computes the covariance matrix C, finds the components with eigh (C v = λ v), sorts them by size and prints the share each one explains. If you want to go deeper, check out the full course I built: quantfinancetogo.com #quantfinance #finance #principalcomponentanalysis #factorinvesting #python Education only, not financial advice.
Comments
Comments from the original post on TikTok
No comments yet
