/xpca

Implementations of extended PCA methods, such as IPCA and EWMPCA

Primary LanguageJupyter NotebookApache License 2.0Apache-2.0

xpca

Implementations of extended PCA methods, such as IPCA and EWMPCA.

Installation

pip install xpca

Paper

See Iterated and exponentially weighted moving principal component analysis on SSRN: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3913940

Usage

import xpca

Iterated PCA (IPCA)

# df is a pandas DataFrame
first_year = 2008; last_year = 2020
Z_periods_ipca = []
model = xpca.IPCA()
for period in [str(x) for x in range(first_year, last_year+1)]:
    df_period = df.loc[period]
    model.fit(df_period)
    Z_period = model.transform(df_period)
    Z_periods_ipca.append(Z_period)
Z_periods_ipca = np.vstack(Z_periods_ipca)

Exponentially weighted moving PCA (EWMPCA)

xs = df.values
ewmpca = xpca.EWMPCA(alpha=.9305)
zs_ewmpca = ewmpca.add_all(xs)