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.
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.
Also a page here but no answer:
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.
Thanks for any examples.
Michael Manus
you really worked on this for 4 years? are the returns really kind of realistic
so back to your questions ...hmm...some parts could get maybe answered with the missing mornig star chapter that reveals itself by knowing the secret place were to find it
# not ending in .WI seems to be morning star maybe CompanyReference -> PrimarySymbol
please search for some morning star algos to clone in the community to see how it works in case you did not already have seen it.
Jared Broad
You can do the price filtering you need at the coarse stage; the code you pasted above is 90% there.
def CoarseSelection(self, coarse):
coarse = [ s for s in coarse if s.Price > 5.00 and s.HasFundamentalData ]
This coarse list is just not sorted -- see this example for a sorted result. You need to sort on the Price property and take the bottom 3.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Garyha
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!