Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
This code is calling a stock on a date that has already passed

If you look at the logs for this algo, it seems to be calling WFM on days that are already passed the date in the CSV file.

Any ideas what's going on?

4 responses

Hi Spencer,

In this case, your universe of securities is whatever is in your CSV file.

So what happens is that 'data' will keep your universe as-is since the last time your algorithm used Fetcher. By that I mean, if you have 12/01/2014 'AAPL' and then 12/31/2014 'IBM', your universe will be AAPL from 12/01/2014 -> 12/31/2014 from which point on it will switch to 'IBM'. Other than that, your code will also remember any stocks that you currently hold positions in and also keep that in your universe.

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.

I understand that, although it keeps WFM in the universe on days it should change the universe. Also, it only keeps WFM for some reason, even though AA and WFM are on the same day in the csv file.

The csv file is:
symbol start date stock_score
AA 2/13/2012 11.7
WFM 2/13/2012 15.8
FDX 2/14/2012 12.1
M 2/16/2012 14.3

The logs carry WFM forward.
2012-02-06PRINTtotal universe size: 2
2012-02-13handle_data:39INFOEntry date for : AA
2012-02-13handle_data:39INFOEntry date for : WFM
2012-02-13handle_data:43INFOordered stock WFM
2012-02-14PRINTtotal universe size: 1
2012-02-14handle_data:39INFOEntry date for : FDX
2012-02-14handle_data:39INFOEntry date for : WFM
2012-02-14handle_data:43INFOordered stock WFM
2012-02-15handle_data:39INFOEntry date for : FDX
2012-02-15handle_data:39INFOEntry date for : WFM
2012-02-15handle_data:43INFOordered stock WFM
2012-02-16PRINTtotal universe size: 1
2012-02-16handle_data:39INFOEntry date for : M
2012-02-16handle_data:43INFOordered stock M
2012-02-16handle_data:39INFOEntry date for : WFM
2012-02-16handle_data:43INFOordered stock WFM
2012-02-17handle_data:39INFOEntry date for : M
2012-02-17handle_data:43INFOordered stock M
2012-02-17handle_data:39INFOEntry date for : WFM
2012-02-17handle_data:43INFOordered stock WFM
End of logs.

Is there a way to remove stocks in your portfolio from total universe. This was it is not repeatedly ordered?

You could sell the stock to remove it from your universe. Something like this should do the trick:

order_target(context.stock, 0)  

Or you can check if you have a position in the stock before sending another order:

current_position = context.portfolio.positions[context.stock].amount  
if current_position == 0:  
  order_target(context.stock, 100)  
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.