Notebook

Fundamental Check Example

In [1]:
# Import things to run pipeline
from quantopian.pipeline import Pipeline
from quantopian.research import run_pipeline

# Import a few built in filters
from quantopian.pipeline.filters import Q500US, StaticAssets

# Import the fundamental data
from quantopian.pipeline.data import Fundamentals
In [6]:
# Create a pipline and add a fundamental factor
testing_factor1 = Fundamentals.revenue_growth.latest
testing_factor2 = Fundamentals.diluted_eps_growth.latest
testing_factor3 = Fundamentals.total_capitalization.latest
testing_factor4 = Fundamentals.quick_ratio.latest
testing_factor5 = Fundamentals.debtto_assets.latest 
testing_factor6 = Fundamentals.roe5_yr_avg.latest 
testing_factor7 = Fundamentals.roa5_yr_avg.latest
testing_factor8 = Fundamentals.pe_ratio.latest
testing_factor9 = Fundamentals.pb_ratio.latest
    
testing_factor1_filter = testing_factor1.top(50)
testing_factor2_filter = testing_factor2 > 0.1
testing_factor3_filter = testing_factor3 > 500000000
testing_factor4_filter = testing_factor4 > 1
testing_factor5_filter = testing_factor5 < 0.5
testing_factor6_filter = testing_factor6 > 0.1
testing_factor7_filter = testing_factor7 > 0.1
testing_factor8_filter = testing_factor8 < 20
testing_factor9_filter = testing_factor9 < 2

pass_universe = (Q500US() 
               #& testing_factor1_filter
               & testing_factor2_filter
               & testing_factor3_filter
               & testing_factor4_filter
               & testing_factor5_filter
               #& testing_factor6_filter
               #& testing_factor7_filter
               & testing_factor8_filter
               & testing_factor9_filter
                    )

pipe = Pipeline(
        columns={
                'testing_factor1' : testing_factor1,
                'testing_factor2' : testing_factor2,
                'testing_factor3' : testing_factor3,
                'testing_factor4' : testing_factor4,
                'testing_factor5' : testing_factor5,
                'testing_factor6' : testing_factor6,
                'testing_factor7' : testing_factor7,
                'testing_factor8' : testing_factor8,
                'testing_factor9' : testing_factor9,
                'testing_factor1_filter' : testing_factor1_filter,
                },
                screen = pass_universe)

start_date = '1-3-2018'
end_date = '1-5-2018'

results = run_pipeline(pipe, start_date, end_date)
# Print out the pipeline results listing the data and the dates
results
<string>:52: QuantopianWarning: Morningstar adjusted the calculation for the field 'debtto_assets' starting on April 1, 2018.

The historical values for this field will surface from the vendor in mid-April 2018.

Until the historical data is updated in mid-April, your algorithm will see old (before April 1) and new (after April 1) definitions of the field in the same backtest.
<string>:52: QuantopianWarning: Morningstar adjusted the calculation for the field 'total_capitalization' starting on April 1, 2018.

The historical values for this field will surface from the vendor in mid-April 2018.

Until the historical data is updated in mid-April, your algorithm will see old (before April 1) and new (after April 1) definitions of the field in the same backtest.
<string>:52: QuantopianWarning: Morningstar adjusted the calculation for the field 'quick_ratio' starting on April 1, 2018.

The historical values for this field will surface from the vendor in mid-April 2018.

Until the historical data is updated in mid-April, your algorithm will see old (before April 1) and new (after April 1) definitions of the field in the same backtest.
<string>:52: QuantopianWarning: Morningstar adjusted the calculation for the field 'revenue_growth' starting on April 1, 2018.

The historical values for this field will surface from the vendor in mid-April 2018.

Until the historical data is updated in mid-April, your algorithm will see old (before April 1) and new (after April 1) definitions of the field in the same backtest.
<string>:52: QuantopianWarning: Morningstar adjusted the calculation for the field 'roa5_yr_avg' starting on April 1, 2018.

The historical values for this field will surface from the vendor in mid-April 2018.

Until the historical data is updated in mid-April, your algorithm will see old (before April 1) and new (after April 1) definitions of the field in the same backtest.
<string>:52: QuantopianWarning: Morningstar adjusted the calculation for the field 'roe5_yr_avg' starting on April 1, 2018.

The historical values for this field will surface from the vendor in mid-April 2018.

Until the historical data is updated in mid-April, your algorithm will see old (before April 1) and new (after April 1) definitions of the field in the same backtest.
Out[6]:
testing_factor1 testing_factor1_filter testing_factor2 testing_factor3 testing_factor4 testing_factor5 testing_factor6 testing_factor7 testing_factor8 testing_factor9
2018-01-03 00:00:00+00:00 Equity(3241 [GLW]) 0.039888 False 0.500000 2.131100e+10 1.831321 0.164626 NaN NaN 14.121212 1.876406
Equity(8132 [WDC]) 0.099067 False 1.372340 2.493200e+10 2.018796 0.430454 NaN NaN 16.779381 1.996112
Equity(32902 [FSLR]) 0.595574 False 0.344828 5.842605e+09 6.091087 0.048714 NaN NaN 6.851020 1.334305
2018-01-04 00:00:00+00:00 Equity(3241 [GLW]) 0.039888 False 0.500000 2.131100e+10 1.831321 0.164626 NaN NaN 14.467532 1.922425
Equity(32902 [FSLR]) 0.595574 False 0.344828 5.842605e+09 6.091087 0.048714 NaN NaN 6.851020 1.322369
2018-01-05 00:00:00+00:00 Equity(3241 [GLW]) 0.039888 False 0.500000 2.131100e+10 1.831321 0.164626 NaN NaN 14.614719 1.941983
Equity(32902 [FSLR]) 0.595574 False 0.344828 5.842605e+09 6.091087 0.048714 NaN NaN 6.851020 1.309865