Created
June 27, 2023 18:02
-
-
Save dkatz23238/ed3068b3c4f73b16676188fe1ea1a2ea to your computer and use it in GitHub Desktop.
PCA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# ROD, PB, PE, DivP, netIncomeTTM, ROA | |
px_0 = np.array([40, 40, 40, 40, 40, 40]) | |
px_1 = np.array([-49.54, -37.51, -16.38, 3.82, 27.54, 71.29]) | |
pc_0 = 0.01 | |
pc_1 = -0.02 | |
reconstructred_portfolio = pc_0 * px_0 + pc_1 * px_1 | |
# It won't be an exact match since we are only using two principal components, but it's a good approximation. | |
# Since we know our weights must sum up to one we can normalize using something like e^X/sum(e^X) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment