Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Universal pipeline, experimentation, learning

This backtest makes it easy to play around with various fundamentals. By default it uses Optimize API (can be switched over to manual short and long) for comparison but you'll never go back from Optimize I'll bet . In before_trading_start, values from pipeline are normalized, then added, then normalized again. It has a setting for a nullzone currently 20% of values around 50% to be excluded. I gathered up some factors as classes and you can add others. The morningstar fundamentals from https://www.quantopian.com/help/fundamentals are extracted out, listed alphabetically and can be used. I understand window_length in a class is a default and can be overridden when calling it.

One route is to isolate to one factor at a time, run through all of them keeping track of results and sort high to low, just as always do battle with the ever-present enemy overfitting. Hope this will do some good.

3 responses

"experimentation, learning"

Curious what the 900+ Morningstar fundamentals would do and whether any might stand out to then be vetted further later for any potential sustainable viability, I ran them all one at a time with the code above in a brief backtest like this:

def make_pipeline(c):  
    return Pipeline(  
        m = VolumeMin(window_length=42).top(400) & Sector().notnull() & Q1500US()  # mask  
        screen  = m,  
        columns = {  
            'sector': Sector(mask=m),  
            'a': Fundamentals.  ebitda   .latest,  
        })  

The code goes long higher values and short lower values.
The numbers shown are returns per dollar invested (neutralizing because invested is unavoidably not always the same).
For those that were initially very negative returns, they were run again like -Fundamentals.other_operating_expenses.latest with the minus sign, flipping long & short in Optimize, and those are indicated with minus signs here.
The code automatically only processes stocks with pipeline values and at some point I began excluding fundamentals where only a handful of stocks were receiving investments. Before that, some of them snuck through and they can tend to be those showing higher returns.
Around 500 returned numerical values (factors, not filters or classifiers) in pipeline and/or invested in enough stocks that I didn't screen them out (besides the ones that eeked through earlier).

10.2  buy_back_yield  
9.6   interest_coverage  
9.3   normalized_income  
9.0   pretax_income  
8.9   cfo_per_share  
8.9   net_income_from_continuing_operations  
8.7   net_income_from_continuing_operation_net_minority_interest  
8.5   net_income_continuous_operations  
8.5   net_income_from_continuing_and_discontinued_operation  
8.5   operating_income  
8.5   size_score  
8.4   market_cap  
8.4   sales_per_share  
8.3   net_income_including_noncontrolling_interests  
8.3   net_income_common_stockholders  
8.3   roa  
8.3   tax_provision  
7.8   operating_revenue  
7.7   ebitda  
7.6   ebit  
7.6   tangible_bv_per_share3_yr_avg  
7.5   total_non_current_liabilities  
7.3   share_class_level_shares_outstanding  
7.3   stockholders_equity  
7.3   total_equity  
7.3   total_liabilities_net_minority_interest  
7.3   total_revenue  
7.2   gross_profit  
7.2   total_equity_gross_minority_interest  
7.2   total_non_current_liabilities_net_minority_interest  
7.1   cash_equivalents  
7.1   tangible_bv_per_share5_yr_avg  
7.0   -repurchase_of_capital_stock  
7.0   cost_of_revenue  
7.0   research_and_development  
6.9   -common_stock_dividend_paid  
6.9   enterprise_value  
6.9   current_liabilities  
6.9   common_stock_equity  
6.9   other_gain_loss_from_disposition_of_discontinued_operations  
6.9   sale_of_investment  
6.9   tax_rate_for_calcs  
6.9   total_liabilities  
6.8   -common_stock_payments  
6.8   earning_yield  
6.8   operating_cash_flow  
6.8   preferred_stock_issuance  
6.7   change_in_loss_and_loss_adjustment_expense_reserves  
6.7   beginning_cash_position  
6.7   interest_income_from_loans_and_lease  
6.7   reconciled_cost_of_revenue  
6.5   interest_income_from_leases  
6.5   total_assets  
6.4   total_non_current_assets  
6.4   total_yield  
6.3   interest_expense_non_operating  
6.3   interestand_similar_income  
6.3   total_expenses  
6.2   work_in_process  
6.1   fcf_per_share  
6.1   cash_flow_from_continuing_operating_activities  
6.1   leases  
6.0   gain_loss_on_sale_of_ppe  
6.0   current_assets  
6.0   classesof_cash_receiptsfrom_operating_activities  
6.0   cash_and_cash_equivalents  
6.0   non_interest_income  
6.0   sale_of_intangibles  
5.9   gross_ppe  
5.9   normalized_net_profit_margin  
5.9   restricted_cash_and_cash_equivalents  
5.8   foreign_sales  
5.8   patents  
5.8   payables_and_accrued_expenses  
5.8   tangible_book_value_per_share  
5.7   -total_debt_equity_ratio  
5.6   com_tre_sha_num  
5.6   interest_income_non_operating  
5.6   pretax_margin  
5.6   total_employee_number  
5.5   foreign_exchange_trading_gains  
5.5   ebitda_margin  
5.5   provision_for_loan_lease_and_other_losses  
5.5   reconciled_depreciation  
5.4   ebit_margin  
5.4   interest_income_after_provision_for_loan_loss  
5.4   retained_earnings  
5.4   sustainable_growth_rate  
5.3   -net_income_extraordinary  
5.3   earningsfrom_equity_interest_net_of_tax  
5.3   current_capital_lease_obligation  
5.3   share_issued  
5.3   shares_outstanding  
5.2   invested_capital  
5.2   machinery_furniture_equipment  
5.2   securities_activities  
5.2   selling_general_and_administration  
5.2   total_capitalization  
5.2   accrued_interest_receivable  
5.1   current_accrued_expenses  
5.1   interest_income  
5.0   forward_earning_yield  
5.0   cash_and_due_from_banks  
5.0   book_value_per_share  
5.0   long_term_debt  
5.0   long_term_debt_and_capital_lease_obligation  
5.0   working_capital  
4.9   income_tax_paid_supplemental_data  
4.9   ordinary_shares_number  
4.9   receivable_turnover  
4.9   total_debt  
4.8   free_cash_flow  
4.8   current_notes_payable  
4.8   investments_and_advances  
4.8   other_receivables  
4.8   roe  
4.7   interest_income_from_loans  
4.7   land_and_improvements  
4.7   net_occupancy_expense  
4.7   non_interest_expense  
4.7   other_customer_services  
4.6   net_debt  
4.6   net_ppe  
4.6   other_special_charges  
4.6   proceeds_from_issuance_of_warrants  
4.6   treasury_shares_number  
4.5   capital_lease_obligations  
4.5   operating_expense  
4.5   proceeds_from_stock_option_exercised  
4.4   domestic_sales  
4.4   common_stock_issuance  
4.4   payout_ratio  
4.4   realized_capital_gain  
4.3   construction_in_progress  
4.3   common_stock  
4.3   common_equity_to_assets  
4.3   roic  
4.2   foreclosed_assets  
4.2   end_cash_position  
4.2   non_current_deferred_taxes_liabilities  
4.2   operation_margin  
4.1   receivables  
4.1   unrealized_gain_loss_on_investment_securities  
4.0   non_operating_income  
4.0   otherunder_preferred_stock_dividend  
4.0   preferred_stock_dividend_paid  
3.9   general_and_administrative_expense  
3.9   change_in_interest_payable  
3.9   change_in_accrued_expense  
3.9   cash_cash_equivalents_and_marketable_securities  
3.9   buildings_and_improvements  
3.9   net_preferred_stock_issuance  
3.9   other_interest_expense  
3.9   other_non_current_assets  
3.9   payables  
3.9   property_liability_insurance_claims  
3.9   taxes_receivable  
3.8   minimum_pension_liabilities  
3.8   payment_turnover  
3.7   inventory  
3.7   sale_of_long_term_investments  
3.7   treasury_stock  
3.7   accounts_payable  
3.6   tangible_book_value  
3.6   available_for_sale_securities  
3.5   fcf_yield  
3.5   deferred_tax_assets  
3.5   cash_from_discontinued_financing_activities  
3.5   capital_stock  
3.5   sale_of_short_term_investments  
3.5   amortization_of_securities  
3.4   current_debt_and_capital_lease_obligation  
3.4   current_debt  
3.4   net_margin  
3.4   special_charge  
3.4   accounts_receivable  
3.3   change_in_payables_and_accrued_expense  
3.3   cash_cash_equivalents_and_federal_funds_sold  
3.3   marketing_expense  
3.3   minority_interests  
3.3   net_tangible_assets  
3.3   preferred_shares_number  
3.2   finished_goods  
3.2   long_term_capital_lease_obligation  
3.2   non_current_deferred_liabilities  
3.2   other_operating_revenue  
3.2   other_intangible_assets  
3.2   preferred_stock_of_subsidiary  
3.1   interest_income_from_other_money_market_investments  
3.1   interest_expense  
3.1   other_interest_income  
3.1   trust_feesby_commissions  
3.0   ev_to_ebitda  
3.0   other_short_term_investments  
3.0   sales_per_employee  
2.9   gains_loss_on_disposal_of_discontinued_operations  
2.9   other_impairment_of_capital_assets  
2.9   other_income_expense  
2.9   interest_paid_supplemental_data  
2.8   current_deferred_taxes_liabilities  
2.8   change_in_income_tax_payable  
2.8   change_in_accrued_investment_income  
2.8   notes_receivable  
2.8   promotion_and_advertising  
2.7   fees  
2.7   deferred_acquisition_costs  
2.7   ps_ratio  
2.7   separate_account_business  
2.7   working_capital_per_share5_yr_avg  
2.6   gains_losses_not_affecting_retained_earnings  
2.6   other_properties  
2.5   cash_from_discontinued_operating_activities  
2.5   selling_and_marketing_expense  
2.5   short_term_debt_issuance  
2.4   fees_and_commissions  
2.4   inventory_turnover  
2.4   accrued_preferred_stock_dividends  
2.3   extraordinary_items  
2.3   equipment  
2.3   deferred_tax  
2.3   other_non_interest_expense  
2.2   federal_funds_sold  
2.2   current_deferred_liabilities  
2.1   gross_loan  
2.1   equity_per_share_growth  
2.1   line_of_credit  
2.1   other_non_interest_income  
2.1   other_liabilities  
2.1   sales_of_fixed_maturity_securities  
2.0   net_other_unrealized_gain_loss  
1.9   gain_on_sale_of_business  
1.9   loans_receivable  
1.9   prepaid_assets  
1.9   restricted_cash  
1.9   raw_materials  
1.8   interest_income_from_securities  
1.8   loans_held_for_sale  
1.8   pb_ratio  
1.7   goodwill  
1.7   earnings_from_equity_interest  
1.7   current_deferred_assets  
1.7   interest_expense_for_deposit  
1.7   pension_and_employee_benefit_expense  
1.7   securities_and_investments  
1.6   current_deferred_taxes_assets  
1.6   change_in_account_payable  
1.6   cash_return  
1.6   non_current_deferred_taxes_assets  
1.6   net_unrealized_gain_loss_investments  
1.6   policy_acquisition_expense  
1.5   deferred_assets  
1.5   consumer_loan  
1.5   insurance_and_claims  
1.4   current_deferred_revenue  
1.4   net_income_from_other_gains_losses  
1.4   other_current_liabilities  
1.4   peg_payback  
1.4   trading_liabilities  
1.3   deferred_costs  
1.3   cf_yield  
1.3   interest_income_from_investment_securities  
1.3   misc_other_special_charges  
1.3   other_non_cash_items  
1.3   assets_turnover  
1.2   change_in_other_current_assets  
1.2   loans_held_for_resell  
1.2   net_income_discontinuous_operations  
1.2   other_assets  
1.2   preferred_stock  
1.2   additional_paid_in_capital  
1.1   calls_maturities_of_maturity_securities  
1.1   income_tax_payable  
1.1   insurance_and_premiums  
1.1   net_short_term_debt_issuance  
1.1   redeemable_preferred_stock  
1.0   investment_tax_credits  
1.0   net_operating_interest_income_expense  
0.9   total_tax_payable  
0.9   deferred_income_tax  
0.9   goodwill_and_other_intangible_assets  
0.9   change_in_deferred_charges  
0.9   net_other_investing_changes  
0.9   change_in_tax_payable  
0.8   net_intangibles_purchase_and_sale  
0.8   long_term_debt_issuance  
0.8   non_current_deferred_assets  
0.7   growth_score  
0.7   other_non_current_liabilities  
0.7   decreasein_interest_bearing_depositsin_bank  
0.7   interest_payable  
0.7   non_current_accounts_receivable  
0.7   securities_amortization  
0.7   working_capital_per_share3_yr_avg  
0.6   pcf_ratio  
0.6   investments_in_affiliates_subsidiaries_associates_and_joint_ventures  
0.6   long_term_investments  
0.6   commercial_loan  
0.5   interest_income_from_trading_account_securities  
0.5   net_loan  
0.5   non_current_accrued_expenses  
0.5   pe_ratio  
0.5   proceeds_from_loans  
0.4   impairmentof_capital_assets_income  
0.4   classesof_cash_payments  
0.4   interest_paid_direct  
0.4   net_business_purchase_and_sale  
0.4   other_taxes  
0.4   interest_expense_for_long_term_debt  
0.4   value_score  
0.3   earnings_losses_from_equity_investments  
0.3   changes_in_cash  
0.3   peg_ratio  
0.3   customer_acceptances  
0.3   net_interest_income  
0.3   net_utility_plant  
0.3   credit_card  
0.2   gain_losson_saleof_assets  
0.2   mortgage_loan  
0.2   preferred_stock_equity  
0.1   change_in_payable  
0.0   change_in_prepaid_assets  
0.0   gain_on_sale_of_security  
0.0   cash_flowsfromusedin_operating_activities_direct  
0.0   style_score  
-0.1   interest_expense_for_long_term_debt_and_capital_securities  
-0.1   interest_bearing_deposits_liabilities  
-0.1   working_capital_per_share  
-0.2   unrealized_gain_loss  
-0.2   gain_loss_on_investment_securities  
-0.2   fee_revenue_and_other_income  
-0.2   preferred_securities_outside_stock_equity  
-0.2   principle_investment_gain_loss  
-0.2   commercial_paper  
-0.3   inventories_adjustments_allowances  
-0.3   investment_banking_profit  
-0.3   loss_adjustment_expense  
-0.3   service_charge_on_depositor_accounts  
-0.4   foreign_currency_translation_adjustments  
-0.4   fix_assets_turonver  
-0.5   interest_income_from_federal_funds_sold_and_securities_purchase_under_agreements_to_resell  
-0.6   book_value_yield  
-0.6   fcf_ratio  
-0.6   increasein_interest_bearing_depositsin_bank  
-0.6   purchased_components  
-0.6   unearned_income  
-0.6   trading_gain_loss  
-0.7   commission_expenses  
-0.7   deferred_financing_costs  
-0.7   excess_tax_benefit_from_stock_based_compensation  
-0.7   change_in_working_capital  
-0.7   interest_expense_for_short_term_debt  
-0.7   long_term_debt_payments  
-0.7   other_current_borrowings  
-0.7   allowance_for_loans_and_lease_losses  
-0.7   total_unusual_items  
-0.7   total_unusual_items_excluding_goodwill  
-0.8   gross_margin  
-0.8   increase_decrease_in_deposit  
-0.9   professional_expense_and_contract_services_expense  
-0.9   quick_ratio  
-0.9   change_in_other_current_liabilities  
-0.9   occupancy_and_equipment  
-1.0   acquisition_expense  
-1.0   gainon_extinguishmentof_debt  
-1.0   net_other_financing_charges  
-1.0   sale_of_business  
-1.1    trailing_dividend_yield  
-1.1   investments_in_other_ventures_under_equity_method  
-1.2   net_investment_purchase_and_sale  
-1.2   net_issuance_payments_of_debt  
-1.2   net_non_operating_interest_income_expense  
-1.2   receivables_adjustments_allowances  
-1.2   sale_of_ppe  
-1.3   esop_debt_guarantee  
-1.3   nace  
-1.3   total_deposits  
-1.4   change_in_inventory  
-1.4   net_ppe_purchase_and_sale  
-1.4   principle_transaction_revenue  
-1.4   short_term_debt_payments  
-1.5   cash_conversion_cycle  
-1.5   financial_instruments_sold_under_agreements_to_repurchase  
-1.6   effect_of_exchange_rate_changes  
-1.6   defined_pension_benefit  
-1.6   held_to_maturity_securities  
-1.6   net_income_cont_ops_growth  
-1.6   purchase_of_fixed_maturity_securities  
-1.6   realized_gain_loss_on_sale_of_loans_and_lease  
-1.7   gain_loss_on_sale_of_business  
-1.7   federal_funds_purchased_and_securities_sold_under_agreement_to_repurchase  
-1.7   change_in_federal_funds_and_securities_sold_for_repurchase  
-1.7   payment_for_loans  
-1.7   tax_rate  
-1.8   gainon_saleof_loans  
-1.8   forward_dividend_yield  
-1.8   change_in_other_working_capital  
-1.8   purchase_of_business  
-1.9   dps_growth  
-1.9   cash_flow_from_continuing_financing_activities  
-1.9   net_income_growth  
-1.9   non_current_pension_and_other_postretirement_benefit_plans  
-1.9   purchase_of_intangibles  
-2.0   employee_benefits  
-2.0   diluted_eps_growth  
-2.0   changes_in_account_receivables  
-2.0   non_current_note_receivables  
-2.0   repayment_of_debt  
-2.2   fiscal_year_end  
-2.2   derivative_assets  
-2.2   current_ratio  
-2.2   investing_cash_flow  
-2.2   materials_and_supplies  
-2.2   total_premiums_earned  
-2.2   trading_securities  
-2.3   future_policy_benefits  
-2.3   long_term_provisions  
-2.3   sales_yield  
-2.3   tax_effect_of_unusual_items  
-2.4   other_equity_adjustments  
-2.5   debtto_assets  
-2.5   non_operating_expenses  
-2.6   cash_flow_from_continuing_investing_activities  
-2.6   interest_expense_operating  
-2.6   purchase_of_ppe  
-2.6   separate_account_assets  
-2.7   gas_revenue  
-2.7   days_in_inventory  
-2.7   interest_expense_for_federal_funds_sold_and_securities_purchase_under_agreements_to_resell  
-2.7   preferred_stock_dividends  
-2.7   special_income  
-2.8   fuel_and_natural_gas  
-2.8   change_in_receivables  
-2.8   non_interest_bearing_deposits  
-2.8   trading_assets  
-3.0   interest_income_from_interest_bearing_deposits  
-3.0   net_long_term_debt_issuance  
-3.0   operating_gains_losses  
-3.2   earning_loss_of_equity_investments  
-3.2   long_term_debt_total_capital_ratio  
-3.2   non_current_deferred_revenue  
-3.2   total_money_market_investments  
-3.2   asset_impairment_charge  
-3.3   money_market_investments  
-3.4   financing_cash_flow  
-3.4   purchase_of_short_term_investments  
-3.5   interest_income_from_deposits  
-3.5   operation_income_growth  
-3.6   federal_funds_sold_and_securities_purchase_under_agreements_to_resell  
-3.6   common_utility_plant  
-3.6   operation_revenue_growth3_month_avg  
-3.7   federal_funds_purchased  
-3.7   purchase_of_long_term_investments  
-3.8   diluted_cont_eps_growth  
-3.8   interest_income_operating  
-3.8   non_current_prepaid_assets  
-3.8   net_realized_gain_loss_on_investments  
-3.8   restructuring_and_mergern_acquisition  
-3.8   special_income_charges  
-3.9   net_investment_income  
-4.0   fixed_maturity_investments  
-4.0   deferred_policy_acquisition_costs  
-4.0   long_term_debt_equity_ratio  
-4.0   non_recurring_operation_expense  
-4.1   days_in_payment  
-4.1   mineral_properties  
-4.2   financial_leverage  
-4.3   capital_expenditure  
-4.3   revenue_growth  
-4.8   cash_dividends_paid  
-4.8   flight_fleet_vehicle_and_related_equipments  
-4.9   cap_ex_reported  
-4.9   forward_pe_ratio  
-4.9   maintenance_and_repairs  
-5.0   exploration_development_and_mineral_property_lease_expenses  
-5.0   change_in_loans  
-5.0   purchase_of_investment  
-5.0   total_debt_equity_ratio  
-5.1   days_in_sales  
-5.2   gain_on_sale_of_ppe  
-5.3   derivative_product_liabilities  
-5.3   salaries_and_wages  
-5.6   credit_losses_provision  
-5.6   net_common_stock_issuance  
-5.7   fuel_and_purchase_power  
-5.9   fuel  
-6.0   fixed_maturities_available_for_sale  
-6.0   cash_flow_from_discontinued_operation  
-6.0   total_deferred_credits_and_other_non_current_liabilities  
-6.0   accrued_investment_income  
-6.6   cash_from_discontinued_investing_activities  
-6.6   accumulated_depreciation  
-7.0   common_stock_dividend_paid  
-7.0   net_foreign_currency_exchange_gain_loss  
-7.2   common_stock_payments  
-7.3   repurchase_of_capital_stock  
-8.1   net_income_extraordinary  
-9.3   financial_assets  
-10.8  other_operating_expenses  

Everyone is aware that a limited run is not gospel but gathering information should not be frowned upon as it contains some value beyond trying to use psychic powers or random guessing.

Of 239 fundamentals not listed at https://www.quantopian.com/help/fundamentals as of 2017-11-27, 144 of them returned values in a backtest.
Full list is in this fundamentals .xls spreadsheet, see data tab. Here's a sample of what they look like:

8.6    200    normalized_basic_eps_earnings_reports  
8.5    254    diluted_eps_earnings_reports  
7.2    200    normalized_ebitda  
7.2    200    net_income_cash_flow_statement  
5.7    254    basic_average_shares_earnings_reports  
4.9    178    forward_roe  
4.8    200    normalized_roic  
4.8    192    ps_ratio3_yr_avg_change  
4.5    168    ev_to_forward_ebit  
3.7    192    ev_to_total_assets3_yr_avg_change  
3.2    200    e_vto_total_assets  
2.7    182    ev_to_ebit3_yr_avg  
2.4    194    priceto_ebitda  
2.4    186    forward_roa  
2.3    198    pe_ratio1_year_average  
2.1    182    pe_ratio5_year_low  
2.1    138    pe_ratio5_year_growth  
1.7    200    p_cash_ratio3_yr_avg  
1.6    200    pe_ratio3_yr_avg  
1.6    162    ps_ratio10_year_growth  
1.6    153    forward_dividend  

This attached backtest is a different date range and will produce different numbers, a nice reminder to avoid overfitting.
This backtest has two modes:

'new_fundamentals'          Log any in Fundamentals.columns not in hardcoded known_list  
'fundamental_backtest'      Backtest using a single pasted fundamental to see how they do.

Set MODE = 'new_fundamentals' to see what that does. It is quick.
known_list was manually collected from https://www.quantopian.com/help/fundamentals and pasted into the code.
The backtest uses fundamental values returned in pipeline and normalizes them for Optimize long and short ordering.

Simplified version using norm()