Back to Community
How do I use a factor on my universe of stocks

I came across some factors that seemed interesting on Quantopian. https://www.quantopian.com/help/fundamentals

Wanted to test this on a universe of stocks as provided on Quantopian - Q3000US. But for some reason it doesnt run.
Maybe someone can help me with the code

def make_pipeline():
base_universe = Q3000US()
dy = valuation_ratios.dividend_yield.latest.percentile_between(95,100)
dy_universe = dy(inputs=[USEquityPricing.close],mask=base_universe) <-------------ERROR
longs = dy_universe
securities_to_trade = (longs)

Error says: 'PercentileFilter' object is not callable. Any ideas on where I can get help to test these factors?(https://www.quantopian.com/help/fundamentals)

4 responses

Hello Mark, welcome to Quantopian.

Unfortunately, the information you gave isn't enough for me to understand what you're trying to do or what went wrong.

Have you gone through the pipeline tutorial? It will get you going most of the way. I've attached a modified notebook from Lesson 11 where all I did was find/replace the Q1500US with Q3000US.

Loading notebook preview...
Notebook previews are currently unavailable.
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.

Hi Dan,

Thanks for your reply. I managed to solve some problems after going through various links on quantopian. However, I have another problem now.

How do I find the returns of the Q1500US universe in different quantiles based on their market caps? I tried to find materials but couldnt find any useful. Would appreciate your help on this.

Thanks in advance!

Clone Algorithm
5
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59f84bc5be352a42b1464da8
There was a runtime error.

Hi Mark,

Even though I replied to you privately, I wanted to share the example here in case other community members run into the same question.

The attached example uses the pipeline API to output the 5-day returns and quantile classification based on market cap for every security in the Q1500 universe. Then, it queries the result in before_trading_start and uses pandas.DataFrame.groupby to group the pipeline's output by market cap quantile and sum the returns.

Clone Algorithm
0
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5a0a089f94ca8d414a22ffe0
There was a runtime error.
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.

Hi Ernesto, Yes did really did help me alot in this journey of using factors along with some experimental universes. Thank you so much! :)