Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Custom factor problem

Can any one tell me why this custom factor returns empty list?

LF_CFO_to_total_debt

There is something wrong with the LF_CFO/LF_ total_debt

Thank you

8 responses

your column dict in return is empty, that might be a start :-)

Hello,
can you tell me what "column dict" is, please? This is the first time I try custom factor.
Loi

Hello,
Why did you need this line below? What is the purpose of axis 0?
std = np.std(vol, axis=0)
Loi

Sorry, I didn't think that example was helpful, so I deleted the post. But, the np.std is using numpy's std function.

Well,
If I do this:

class LF_CFO_to_total_debt(CustomFactor):
inputs = [morningstar.cash_flow_statement.operating_cash_flow]
window_length=1
def compute(self, today, assets, out, LF_CFO):
out[:] = LF_CFO

or this:

class LF_CFO_to_total_debt(CustomFactor):
inputs = [morningstar.balance_sheet.total_debt]
window_length=1
def compute(self, today, assets, out, LF_total_debt):
out[:] = LF_total_debt

My result would be a list of stock symbols. However, when I do the division between those two argument, the result return [ ][ ]. I'm puzzled.

Hi Loi, following this post here: https://www.quantopian.com/posts/best-practices-for-comparing-annual-data I am getting an output of stocks. The main thing I did was remove the screen and added a column in Pipeline()

Anyway, hope this helps!

from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline import Pipeline, CustomFactor  
from quantopian.pipeline.data import morningstar  
from quantopian.pipeline.filters.morningstar import IsPrimaryShare  
import numpy as np

def initialize(context):  
    attach_pipeline(make_pipeline(), 'my_pipeline')

def make_pipeline():

    primary_share = IsPrimaryShare()  
    common_stock = morningstar.share_class_reference.security_type.latest.eq('ST00000001')  
    not_depositary = ~morningstar.share_class_reference.is_depositary_receipt.latest  
    not_otc = ~morningstar.share_class_reference.exchange_id.latest.startswith('OTC')  
    not_wi = ~morningstar.share_class_reference.symbol.latest.endswith('.WI')  
    not_lp_name = ~morningstar.company_reference.standard_name.latest.matches('.* L[. ]?P.?$')  
    not_lp_balance_sheet = morningstar.balance_sheet.limited_partnership.latest.isnull()  
    have_market_cap = morningstar.valuation.market_cap.latest.notnull()

    tradeable_stocks = (  
        primary_share  
        & common_stock  
        & not_depositary  
        & not_otc  
        & not_wi  
        & not_lp_name  
        & not_lp_balance_sheet  
        & have_market_cap  
    )

    factor = LF_CFO_to_total_debt(mask=tradeable_stocks)  
    factor.percentile_between(30, 100)

    return Pipeline(  
        columns={  
            'factor': factor  
        }  
    )

class LF_CFO_to_total_debt(CustomFactor):  
     inputs = [morningstar.cash_flow_statement.operating_cash_flow, morningstar.balance_sheet.total_debt]  
     window_length=1  
     def compute(self, today, assets, out, LF_CFO, LF_total_debt):  
         out[:] = LF_CFO/LF_total_debt

def before_trading_start(context, data):  
    print pipeline_output('my_pipeline')

def handle_data(context,data):  
    pass  

ah,
Thank you for your help, Zippy. I found out that I forgot to account for LF_total_debt = 0.

Thanks Loi :-)

I would like to mention that code runs extremely slow and is not for production. You need to figure out a quicker way to pull down the data you need. At least run it only one time a month.