Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Reversing Factor Weights with Alphalens

I'm very new to the platform and this is a pretty basic question but I can't seem to find a straightforward answer anywhere. Is it possible to switch which securities are long and short using alphalens? Lets say I had a factor similar to the size factor where I want to go long low values and short high values. How do I construct that in alphalens. I've started with these lines from the tutorial:
factor_data = al.utils.get_clean_factor_and_forward_returns(factor=size['mcap'],prices=asset_prices,quantiles=5, periods=(10,25,75),)

Display first 5 rows

factor_data.head(5)
mean_return_by_q, std_err_by_q = al.performance.mean_return_by_quantile(factor_data)

# Plot mean returns by quantile and holding period
# over evaluation time range
al.plotting.plot_quantile_returns_bar(
mean_return_by_q.apply(al.utils.rate_of_return, axis=0, args=('1D',) ) );
ls_factor_returns = al.performance.factor_returns(factor_data)
al.plotting.plot_cumulative_returns(ls_factor_returns['75D'], '75D')

2 responses

Hi Jason-Anthony,

I usually just put a “-“ (negative sign) in front of the factor if I want to long a low value and short a high value. I usually ‘normalize’ The factors too by either .zscore() or .rank() or both (if I have more than one factor that I’m combining).

Thanks so much! I knew there was a solution haha