Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Timing out at get_clean_factor_and_forward_returns

For some reason, it keeps showing [*] next to the get_clean_factor_and_forward_returns line, and runs long enough that it restarts and loses the other variables. Can someone reproduce this or is there an issue with my code?

2 responses

This is the notebook.

The major issue is with the following line of code

pricing_data = get_pricing(result.index.levels[1], start_date, end_date, fields='open_price')

Specifically note result.index.levels[1]. One should only fetch the unique symbols so add the unique() method. Moreover, just accessing the index doesn't really work. Use the get_level_values method instead. Also, the level 1 should be in parenthesis not brackets. So this is the correct code

pricing_data = get_pricing(result.index.get_level_values(level=1), start_date, end_date, fields='open_price')

What was happening was there were just a lot of prices. Actually a lot of duplicate prices which then took a long time for the get_clean_factor_and_forward_returns method to work on and it timed out (or ran out of memory). The get_pricing method will get duplicate prices if it's given duplicate symbols. For example the following code will get the price of AAPL twice. Also, ensure the desired symbols are being passed to get_pricing. There is a post on why get_level_values is the correct approach here.

# The following will get the prices for AAPL twice  
get_pricing(symbols(['AAPL', 'AAPL']))

That was the biggest issue. However, there was a small error in the pipeline screen which caused it to not work as intended and was not actually screening. The operator and is not supported for combining filters. One must use & instead.

# The following was the original  
screen = marketcap & debt_paydown_filter & debt_paydown.notnull() and  sector.notnull())  
# It should be this  
screen = marketcap & debt_paydown_filter & debt_paydown.notnull() &  sector.notnull())

That will then work. One final note, there were several places in the notebook where the results of a dataframe were being displayed using the following typical code

# This is what was typed  
result.head  
# However, `head` is a method (and not an attribute) and requires parenthesis with the desired number of rows like this  
result.head(5)

What was being displayed was the result method object . The intention is to display the output of result method so the parenthesis are required to do that.

Good luck. Check out the attached notebook.

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.