## Finding more Alpha Factors - Python Programming for Finance p.22

Hello and welcome to part 10 of the Python for Finance with Quantopian tutorials. In this tutorial, we're going to work on a simplified alpha checking notebook.

One warning I will make here is that you should not be using this notebook to look through all of the possible alpha factors you can think of. Instead, you want to use it after having come up with a theory about what would be a good factor, and then test it in here. It's very easy to snoop for a successful alpha that works in the past, but wont perform in the future / out of sample.

To start, we'll keep the sentiment analysis since it's a fairly unique factor, but we need some more. When I personally try to reference my own businesses, I have found that anything that has a large margin, and is also successful in general, is usually an easier business, and one that can take a few hits and downtimes, compared to a low-margin business. This doesn't mean low-margin businesses can't do well, it's just that a higher margin, so long as sales still occur, is easier. Thus, we'll go with operating margin as a second factor, and then revenue growth as a third. Margin is useless if we have no sales, and the value of our company wont go up unless we're growing. We could poke a lot of holes in these assumptions, but we'll go with this for now.

Heading back to the notebooks section on Quantopian, let's make a new one, starting with:

```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():

testing_factor = operation_ratios.operation_margin.latest
universe = (Q1500US() &
testing_factor.notnull())

testing_factor = testing_factor.rank(mask=universe, method='average')

pipe = Pipeline(columns={'testing_factor':testing_factor},
screen=universe)
return pipe

result = run_pipeline(make_pipeline(), start_date='2015-01-01', end_date='2016-01-01')
result.head()```

This will get us the operation margin data, now we're needing to grab the pricing data for all stocks in this same time period:

```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)```

We also want to see the length of assets, since there may be times when the factor is extremely limiting. This will be especially important when we go to compine alpha factors.

Finally, we can analyze the alpha:

```import alphalens

alphalens.tears.create_factor_tear_sheet(factor = result['testing_factor'],
prices = pricing,
quantiles = 2,
periods = (3, 10, 30))```

In the end, we get the following:

```Ann. alpha	0.050	0.050	0.048
beta	-0.222	-0.222	-0.227
IC Mean	0.027	0.036	0.069```

Alright, now we can test revenue growth, by modifying `testing_factor` to be `testing_factor = operation_ratios.revenue_growth.latest`

```Ann. alpha	0.074	0.065	0.057
beta	-0.046	-0.082	-0.062
IC Mean	0.032	0.042	0.054```

Finally, just for the record since we changed the alphalens periods to 3, 10 and 30, let's run sentiment again:

```Ann. alpha	0.027	0.026	0.020
beta	-0.021	-0.033	-0.071
IC Mean	0.011	0.020	0.030```

You can download the notebook for this tutorial: .

In the next tutorial, we're going to combine these three factors into one single factor and see how it compares to the individual alpha factors.

The next tutorial:

• Intro and Getting Stock Price Data - Python Programming for Finance p.1

• Handling Data and Graphing - Python Programming for Finance p.2

• Basic stock data Manipulation - Python Programming for Finance p.3

• More stock manipulations - Python Programming for Finance p.4

• Automating getting the S&P 500 list - Python Programming for Finance p.5

• Getting all company pricing data in the S&P 500 - Python Programming for Finance p.6

• Combining all S&P 500 company prices into one DataFrame - Python Programming for Finance p.7

• Creating massive S&P 500 company correlation table for Relationships - Python Programming for Finance p.8

• Preprocessing data to prepare for Machine Learning with stock data - Python Programming for Finance p.9

• Creating targets for machine learning labels - Python Programming for Finance p.10 and 11

• Machine learning against S&P 500 company prices - Python Programming for Finance p.12

• Testing trading strategies with Quantopian Introduction - Python Programming for Finance p.13

• Placing a trade order with Quantopian - Python Programming for Finance p.14

• Scheduling a function on Quantopian - Python Programming for Finance p.15

• Quantopian Research Introduction - Python Programming for Finance p.16

• Quantopian Pipeline - Python Programming for Finance p.17

• Alphalens on Quantopian - Python Programming for Finance p.18

• Back testing our Alpha Factor on Quantopian - Python Programming for Finance p.19

• Analyzing Quantopian strategy back test results with Pyfolio - Python Programming for Finance p.20

• Strategizing - Python Programming for Finance p.21

• Finding more Alpha Factors - Python Programming for Finance p.22
• Combining Alpha Factors - Python Programming for Finance p.23

• Portfolio Optimization - Python Programming for Finance p.24

• Zipline Local Installation for backtesting - Python Programming for Finance p.25

• Zipline backtest visualization - Python Programming for Finance p.26

• Custom Data with Zipline Local - Python Programming for Finance p.27

• Custom Markets Trading Calendar with Zipline (Bitcoin/cryptocurrency example) - Python Programming for Finance p.28