Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
fetcher and schedule_function

This is an obvious question, so surely has been asked a million times: if I schedule some action based on (timestamped) external data (obtained by the fetcher), does it consume the data item (if any), so the next time I try the action, that particular datum will be invisible?

That is, if I have

6/18/2015, 1pm, "buy AAPL"
6/18/2015, 2pm, "sell AAPL"

If I schedule my algo to run at 1:30pm and at 2:30pm, I would obviously want the first instance to buy AAPL, and consume the line, so the second time the algo runs, it only sees the second line. Is this, in fact, what happens?

4 responses

Hi Igor,

Fetcher cannot look backwards in the file. So if you deploy the algo at 1:30PM, the next signal it sees is "sell AAPL" at 2PM.

If you want to first buy AAPL and then sell APPL, you can add this code to the algo. Something like "if we have an existing position (or if we entered this position today), then sell"

Cheers,
Alisa

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.

Alisa, I am a little puzzled. If the fetched file contains buy and sell signals, I can only act on the signals after they arrive. So, if I have a buy signal timestamped 1pm, that means that the next time I trade I must buy. Now, the natural thing is for this signal to be thus "consumed" (popped off the top of the stack) once acted on, and then the next time the algorithm runs it seems whatever is at the top of the stack at that point. Are you saying that this is NOT the right model?

Hi Igor,
The backtester is a 'point in time' simulation, so if you have an external fetcher file with timestamps, the data will not be made available to the algo until the time in the backtest is equal to or after the timestamp in the fetcher file.

The values in the fetcher file are forward filled, so if you have a buy signal at 1:00pm, and a sell signal at 2:00pm, the buy signal will be the value in the algos data until it is replaced by the sell signal at 2:00. You will have to keep track of whether or not you have already acted on the 1:00 signal within your code.

David

David, thanks! So, it is as I expected! (always gratifying :))

Igor