Hi Karan,
Lesson 12 of the Pipeline Tutorial covers the jump from research to the backtester. The way to think about the 'performance' of a stock is that it's just another factor that you can build in pipeline. In the Pipeline Tutorial, the main factor used in the final example is a percent_difference
factor. The pipeline then spits out the top 25 and bottom 25 stocks based on the percent_difference
factor. You could do something similar to get the bottom 10 and top 10 of a performance
factor that you define.
I'm picturing something like this:
class PriceNDaysAgo(CustomFactor):
inputs = [USEquityPricing.close]
def compute(self, today, asset_ids, out, values):
out[:] = values[0]
...
# in initialize:
base_universe = Q1500US()
month_ago_price = PriceNDaysAgo(window_length=21)
performance = (USEquityPricing.close.latest - month_ago_price) / month_ago_price)
longs = performance.top(10, mask=Q1500US())
shorts = performance.bottom(10, mask=Q1500US())
I left out some imports and some other context in the algo, but try working that into lesson 12 of the Pipeline Tutorial.
Disclaimer
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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.