A typical workflow involves preprocessing the factor with AlphaPurifier, running backtests with FactorAnalyzer, and performing attribution with PureExposures.
from alphapurify import AlphaPurifier, FactorAnalyzer, PureExposures
# 1. Preprocess the factor
df = (
AlphaPurifier(df, factor_col="alpha_003")
.winsorize(method="mad")
.standardize(method="zscore")
.to_result()
)
# 2. Run backtests and generate reports
FA = FactorAnalyzer(
base_df=df,
trade_date_col='datetime',
symbol_col='symbol',
price_col='close',
factor_name='alpha_003'
)
FA.run()
FA.create_long_return_sheet()
FA.create_long_short_return_sheet()
FA.create_short_return_sheet()
FA.create_single_fac_ic_sheet()
# 3. Analyze contributions of other factors
Ex = PureExposures(
base_df=df,
trade_date_col='datetime',
symbol_col='symbol',
price_col='close',
factor_name='alpha_003',
exposure_cols=['momentum_12_1', 'vol_60', 'beta_252'],
)
Ex.run()
Ex.plot_pure_exposures()
Ex.plot_pure_returns()
Ex.plot_pure_exposures_and_returns()
Ex.plot_correlations()
from alphapurify import AlphaPurifier, FactorAnalyzer, PureExposures
# preprocess
df = (
AlphaPurifier(df, factor_col="alpha_003")
.winsorize(method="mad")
.standardize(method="zscore")
.to_result()
)
#backtest
FA = FactorAnalyzer(base_df=df,
trade_date_col='datetime',
symbol_col='symbol',
price_col='close',
factor_name='alpha_003')
FA.run()
FA.create_long_return_sheet()
FA.create_long_short_return_sheet()
FA.create_short_return_sheet()
FA.create_single_fac_ic_sheet()
#contributions of other factors
Ex = PureExposures(
base_df=df,
trade_date_col='datetime',
symbol_col='symbol',
price_col='close',
factor_name='alpha_003',
exposure_cols=['momentum_12_1', 'vol_60', 'beta_252'],
)
Ex.run()
Ex.plot_pure_exposures()
Ex.plot_pure_returns()
Ex.plot_pure_exposures_and_returns()
Ex.plot_correlations()