GitHub profile

Projecting Co-ordinates

Notation

As defined in the Definitions page, the principal component scores are $\mathbf{z} = \widetilde{\mathbf{Y}}_c\mathbf{W}$. Here we restrict $\mathbf{W}$ to its first 3 columns, $\mathbf{W}_3 \in \mathbb{R}^{N \times 3}$ (the top 3 loadings from Step 7, ordered by eigenvalue), giving

$$\mathbf{z}_3 = \widetilde{\mathbf{Y}}_c\mathbf{W}_3 \in \mathbb{R}^{(T-12)\times 3}$$

One row per observation (month), one column per retained component (PC1, PC2, PC3) — the coordinates of each month's yield curve in the reduced 3-dimensional space.

step 1 - project onto the first 3 principal components


import subprocess  
%run ./dataframes/step9_scores.py  
%run ./dataframes/truncate_with_ellipsis.py  
df = scores()  
subprocess.run(['wl-copy'], input=truncate_with_ellipsis(df, 3).to_html(index=False).encode())  
Date PC1 PC2 PC3
2017-03-31 -3.576928 0.559211 0.343651
2017-04-30 -4.359432 0.366995 0.329572
2017-05-31 -3.939156 0.141495 0.333422
... ... ... ...
2024-10-31 -1.317907 0.184691 0.068997
2024-11-29 -1.026599 0.033133 0.062858
2024-12-31 0.631144 -0.41012 0.026706

Python

filename: step9_scores.py

from dataframes.step7_eigendecomposition import *

def scores(n_components=3):
    df = demeaning()
    date_col = df.columns[0]
    value_cols = df.columns[1:]
    Y_c = df[value_cols]
    W = eigenvectors().iloc[:, :n_components]
    Z = Y_c.values @ W.values
    df_scores = pd.DataFrame(Z, columns=W.columns)
    df_scores.insert(0, date_col, df[date_col].values)
    return df_scores
projecting the demeaned yields onto the first 3 principal component loadings