Hello and welcome to part 11 of the Python for Finance with Quantopian tutorials. In the previous tutorial, we covered analysis of a couple new factors, which we have deemed to be decent new alpha factors. What we want to do here now is combine all three alpha factors into a new factor, and then analyze that. To do this, we just need to slightly modify our previous alpha factor checker notebook:
from quantopian.pipeline import Pipeline from quantopian.research import run_pipeline from quantopian.pipeline.filters.morningstar import Q1500US from quantopian.pipeline.data.sentdex import sentiment from quantopian.pipeline.data.morningstar import operation_ratios def make_pipeline(): # Yes: operation_ratios.revenue_growth, operation_ratios.operation_margin, sentiment testing_factor1 = operation_ratios.operation_margin.latest testing_factor2 = operation_ratios.revenue_growth.latest testing_factor3 = sentiment.sentiment_signal.latest universe = (Q1500US() & testing_factor1.notnull() & testing_factor2.notnull() & testing_factor3.notnull()) testing_factor1 = testing_factor1.rank(mask=universe, method='average') testing_factor2 = testing_factor2.rank(mask=universe, method='average') testing_factor3 = testing_factor3.rank(mask=universe, method='average') testing_factor = testing_factor1 + testing_factor2 + testing_factor3 testing_quantiles = testing_factor.quantiles(2) pipe = Pipeline(columns={ 'testing_factor':testing_factor, 'shorts':testing_quantiles.eq(0), 'longs':testing_quantiles.eq(1)}, screen=universe) return pipe result = run_pipeline(make_pipeline(), start_date='2015-01-01', end_date='2016-01-01') result.head()
Notice the changes made are adding 2 new testing_factors
, then having the final testing_factor
just as these three factors added together. This is a pretty crude way of doing things, but it should work just fine. From here, everything is actually the same.
assets = result.index.levels[1].unique() pricing = get_pricing(assets, start_date='2014-12-01', end_date='2016-02-01', fields='open_price') len(assets)
import alphalens alphalens.tears.create_factor_tear_sheet(factor = result['testing_factor'], prices = pricing, quantiles = 2, periods = (3, 10, 30))
Combining everything and running it:
Ann. alpha 0.123 0.108 0.098 beta -0.147 -0.186 -0.221 IC Mean 0.045 0.069 0.105
This along with all of the analysis in Alphalens is a major improvement overall. The alpha here is higher than any single alpha factor, same with the IC.