LessonThis is a lesson restated in new words. Any figure in it is an example from the source, not this desk's record.
Principal component analysis rotates correlated stock returns into uncorrelated directions and ranks those directions by how much variance they carry. On daily log returns for 2021-2022, after the lecture dropped the S&P 500 from the feature set and kept Apple, Amazon, General Motors, and Microsoft, the first component explained about 55 percent of variance and loaded with the same sign on all four names. The lecture reads that as market risk. Adding a second component, which separated GM from the three technology names, pushed the total past 80 percent, near 82 in one statement. A third, with mixed signs, pushed it past 90 percent. A 60-day rolling version showed those shares are not stable.
Why it matters
Correlated predictors are hard to interpret. If Apple and Amazon rise together, a regression cannot say which one moved the target. Coefficients and network weights become unstable, the model is larger than the distinct information, and it can fit noise. The lecture's camera analogy is the same complaint. Ten cameras aimed at different doors are useful. Three aimed at the same door are redundant, and one blocked by a refrigerator can be dropped. PCA keeps directions that still explain variance and sets the small ones aside. Collinearity measures from a first statistics course, such as variance-inflation factors, are the symptom. PCA is one way to rebuild the features.
The idea in plain words
The inputs were Yahoo Finance tables for 2021-2022, pasted into a spreadsheet because the lecture says the old API was closed, then merged on date. Log returns of the close were computed for Apple, Amazon, GM, Microsoft, and the S&P 500 index. The correlation matrix has ones on the diagonal. Off the diagonal everything the lecture inspected was positive. Apple lined up more with Amazon, Microsoft, and the index than with GM, which matches a sector story and still leaves a common market piece. Two algebra routes produce the same rotation. A data matrix of n days by p stocks has a singular-value decomposition. The principal-component scores are the data times the matrix of right singular vectors, and the covariance of those scores is diagonal. An eigendecomposition of the covariance does the same job: the eigenvalues are the variances of the components, and they equal the squared singular values divided by n minus 1. The lecture recommends checking that scale in code. In practice it calls a standard PCA routine after scaling. Keeping all four components explains 100 percent and accomplishes nothing. The point is to stop early. Loadings are the weights inside each component.
How to use it
Fit PCA on the returns you mean to explain, plot the cumulative share of variance, and stop when added components are noise for your purpose. Then read the loadings before you name them. A common sign across stocks is a clue of a market factor only if you already know those stocks share a market. The GM-versus-technology split is a clue of industry only because of that membership. Neither name is delivered by the algebra.
Repeat the fit on a rolling window before you trust the names. With about 252 sessions and a 60-day window, the lecture's explained-variance path runs to roughly day 190. The market share started above 60 percent, fell below 50, and later rose above 50 again. The industry share stayed roughly in a 0.20 to 0.30 band. The idiosyncratic share rose while the market share fell, and at times exceeded the industry share. Loadings move too, even though they are harder to plot. The lecture floats a future chart of average loadings with a band, and does not draw it.
What usually goes wrong
Keeping every component, which restores the original collinearity in a new coordinate system. Naming component one "the market" from one sample and trading it as if the loading vector were a constant. The 60-day path is the counterexample. Using 2021-2022 technology-heavy names and expecting the same industry split in a different universe. And treating the orthogonal directions as a promise that a later month will line up. The lecture says there is no assurance the structure survives, and that a live book has to decide when a drift in loadings is a blip and when it is a new regime.
Questions people ask
Which names were in the fit?
Apple, Amazon, General Motors, and Microsoft, as 2021-2022 log returns. The S&P 500 was downloaded and then removed before the four-component PCA. Correlations with the index were discussed first.
How was the variance split?
About 55 percent in the first component, past 80 percent with two, past 90 percent with three. The second component's own share was described as roughly the high 20s. A 60-day window moved the first component from above 60 percent to below 50 and back.
Do the labels "market" and "industry" come from the math?
No. The math supplies uncorrelated directions and their variances. The labels are the lecture's reading of the loadings, using the fact that three of the four firms are technology firms and GM is not.