Would appreciate help with basic stock screening. The pipeline code below was common on Quantopian (Q) before their move to more stock pre-set groupings. The essentials are in the comments, reworded a bit here:

# is primary_share
# not_depositary_receipt
# not_otc (over the counter)
# not ending in .WI
# not_lp in the name, not limited partnership
# is common_stock
# market_cap not empty
# Price greater_than

My code using similar is something I'd like to try to implement on QuantConnect (it can't qualify for Q's contest/fund so I just want to run it live). Only a little bit of progress so far ...

One way to screen for price is in Coarse:

    def CoarseSelection(self, coarse):
        coarse = [ s for s in coarse if s.Price > 5.00 and s.HasFundamentalData ]

I think ST00000001 can be dealt with in Fine:

    def FineSelection(self, fine):
        fine = [ s for s in fine if s.SecurityReference.SecurityType == 'ST00000001']

The others didn't turn up in a google search. An additional problem is that I'm confused on how Coarse & Fine work together. I think this is saying the return from Coarse is what gets fed to Fine. Automagic if so. It says regarding fine "Also you must use coarse fundamental universe to narrow down the universe as a "pre-filter". " So then in my goal, price filtering can't happen in Coarse, it would have to wait until Fine is done with everything else.

https://www.quantconnect.com/docs/algorithm-reference/universes#Universes-Coarse-Universe-Selection

 

Need to understand for sure, to be able to gain some certainty in control over it in making changes down the line. Go read the docs would be ok if these things were addressed there already clearly with examples, I've done my homework, hours trying to find hints. A similar question can be found with a Find on "tradeable" here along with a reply from Jared. Until a preset group is prepared, I don't mind rolling my own if someone can show how.

https://www.quantconnect.com/forum/discussion/2317/migrating-from-quantopian-to-quantconnect/p1

 

Also a page here but no answer:

https://www.quantconnect.com/forum/discussion/2561/migrating-from-quantopian-easy-way-to-replicate-q500us-and-q1500us-universes/p1

A suitable goal would be to return the 3 lowest priced stocks above $5.00 that meet all of those other criteria as well.

Then I'd like to compare with the Q return and ideally those 3 will be the same. And go from there.

 

from quantopian.pipeline import Pipeline
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline.data import Fundamentals
from quantopian.pipeline.data.builtin import USEquityPricing

def initialize(context):
pipe = make_pipeline(context)
attach_pipeline(pipe, 'pipe')

def before_trading_start(context, data):
context.out = pipeline_output('pipe')

def make_pipeline(context):
prices = USEquityPricing.close
f = Fundamentals
m = ( # mask. ~ means not
f.is_primary_share # primary_share
& ~f.is_depositary_receipt.latest # not_depositary
& ~f.exchange_id .latest.startswith('OTC') # not_otc
& ~f.symbol .latest.endswith('.WI') # not_wi
& ~f.standard_name .latest.matches('.* L[. ]?P.?$') # not_lp_name
& f.security_type .latest.eq('ST00000001') # common_stock
& f.market_cap .latest.notnull() # has market_cap
& (prices.latest > 5.00) # Price greater_than
)

return Pipeline(
screen = m,
columns = {
'prc': prices.latest,
},
)

 

Once the stocks are the same, the idea is to see whether this result can be matched or anywhere close. This isn't margin, it's just 4+ years of hard work every day showing a glimmer of hope.

file:///C:/Users/garyha/Documents/Image169.jpg

Thanks for any examples.

Author