Back to Community
Fetch_csv during live trading

Is it possible after all to fetch newly updated data every day from an external source during live trading? If so, where should one place the call to fetch_csv? In the initialize or in the before_trading_start method? The documentation sounds somewhat contradictory about this.

The documentation says:
"When Fetcher is used in Live Trading or Paper Trading, the fetch_csv() command is invoked once per trading day, when the algorithm warms up, before market open."

But also:
"Fetcher lets you load CSV files over http. To use it, invoke fetch_csv(url) in your initialize method."

However:
"initialize(context) Called once at the very beginning of a backtest. "

And:
"before_trading_start(context) Optional. Called daily prior to the open of market."

5 responses

initialize() and handle_data() were the first two methods created on Quantopian. You only needed those two to run an algo. In the last few months we added fundamental data to the platform, unlocking a new slew of algorithms and writing styles. With this change, we added "before_trading_start()".

I can definitely see how you got confused. Fetcher lives in "initialize()" and it gets called once per day in live trading.
In the long term, I think Fetcher will move to "before_trading_start()", but we're not there yet.

If you are updating the file, I would recommend to have the CSV updated by midnight Eastern Time so the data is ready for the algo by market open. You can append the new data to the bottom of the file, keeping a growing document. Here is an example of a Fetcher algo: https://www.quantopian.com/help#sample-csv-1

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.

Sorry, I am confused: Alisa wrote that "initialise()" is called once per day in live trading. However, in backtest, it is only called once when the algo is started. So seems inconsistent and would mean that algos will behave differently in backtest and live trading... Does not seem sensible at all!

In backtesting, fetch_csv is called once in the first bar of the algorithm. It pulls in the data and feeds it to your algo when the backtest hits the dates in the file, avoiding look-ahead bias. There is a clear start and end date in the backtest so the algo knows when to pass in the data.

In live trading, fetch_csv is called every day, in the early hours before the trading day. If your file doesn't change, that's fine, you will keep trading the same set of stocks. Otherwise, if you want to update the universe of stocks in the live algo, this gives you that flexibility.

I am still confused. Is "initialize()" called every day during live trading"?

Hi Will - you should probably start a new thread - you'll get a better answer than updating an old thread like this one. That said:

initialize() is called only once at the very start of your algorithm. However, fetch_csv() is called every day in live trading. This is confusing - it's one of the design decisions that we'd change if we could go back in time. In general, fetch_csv() is being made obsolete as more and more data is made available for importing through the data platform.

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.